1 package projectmanagement.business.timewage; 2 3 import projectmanagement.business.ProjectManagementBusinessException; 4 import projectmanagement.business.employee.*; 5 import projectmanagement.business.project.*; 6 import projectmanagement.data.timewage.*; 7 import com.lutris.appserver.server.sql.DatabaseManagerException; 8 import com.lutris.appserver.server.sql.ObjectId; 9 import com.lutris.appserver.server.sql.ObjectIdException; 10 import com.lutris.dods.builder.generator.query.*; 11 import com.lutris.appserver.server.Enhydra; 12 import com.lutris.logging.*; 13 14 import projectmanagement.spec.employee.*; 15 import projectmanagement.spec.project.*; 16 import projectmanagement.spec.timewage.*; 17 23 public class WorkSheetManagerImpl implements WorkSheetManager{ 24 25 33 public WorkSheet[] getAllWorkSheets() 34 throws ProjectManagementBusinessException { 35 try { 36 WorkSheetQuery query = new WorkSheetQuery(); 37 38 WorkSheetDO[] foundWorkSheets = query.getDOArray(); 39 if(foundWorkSheets.length != 0) { 40 WorkSheetImpl[] cs=new WorkSheetImpl[foundWorkSheets.length]; 41 for (int i=0; i<foundWorkSheets.length; i++) { 42 cs[i]=new WorkSheetImpl(foundWorkSheets[i]); 43 } 44 return cs; 45 } else { 46 return null; 47 } 48 } catch(NonUniqueQueryException ex) { 49 Enhydra.getLogChannel().write(Logger.DEBUG, 50 "Non-unique workshit found in database: "+ex.getMessage()); 51 throw new ProjectManagementBusinessException("Non unique worksheet found"); 52 } catch(DataObjectException ex) { 53 throw new ProjectManagementBusinessException("Database error retrieving worksheets: ", ex); 54 } 57 } 58 59 69 public WorkSheet[] getAllWorkSheetsForEmployee(Employee employee) 70 throws ProjectManagementBusinessException { 71 try { 72 WorkSheetQuery query = new WorkSheetQuery(); 73 QueryBuilder mainQuery=query.getQueryBuilder(); 74 QueryBuilder subQuery=new QueryBuilder(); 75 subQuery.select(PayRateDO.PrimaryKey); 76 subQuery.addWhere(PayRateDO.Employee,((EmployeeImpl)employee).getDO(),QueryBuilder.EQUAL); 77 mainQuery.addWhereIn(WorkSheetDO.PayRate,subQuery); 78 79 WorkSheetDO[] foundWorkSheets = query.getDOArray(); 80 if(foundWorkSheets.length != 0) { 81 WorkSheetImpl[] cs=new WorkSheetImpl[foundWorkSheets.length]; 82 for (int i=0; i<foundWorkSheets.length; i++) { 83 cs[i]=new WorkSheetImpl(foundWorkSheets[i]); 84 } 85 return cs; 86 } else { 87 return null; 88 } 89 } catch(NonUniqueQueryException ex) { 90 Enhydra.getLogChannel().write(Logger.DEBUG, 91 "Non-unique worksheet found in database: "+ex.getMessage()); 92 throw new ProjectManagementBusinessException("Non unique worksheet found"); 93 } catch(DataObjectException ex) { 94 throw new ProjectManagementBusinessException("Database error retrieving worksheets: ", ex); 95 } catch(QueryException ex) { 96 throw new ProjectManagementBusinessException("Query exception retrieving worksheets: ", ex); 97 } 98 } 99 100 113 public WorkSheet findWorkSheetByID(String id) 114 throws ProjectManagementBusinessException { 115 WorkSheetImpl theWorkSheet = null; 116 117 try { 118 WorkSheetQuery query = new WorkSheetQuery(); 119 query.setQueryOId(new ObjectId(id)); 121 query.requireUniqueInstance(); 123 WorkSheetDO theWorkSheetDO = query.getNextDO(); 124 theWorkSheet = new WorkSheetImpl(theWorkSheetDO); 125 return theWorkSheet; 126 } catch(Exception ex) { 127 throw new ProjectManagementBusinessException("Exception in findWorkSheetByID()", ex); 128 } 129 } 130 131 146 public WorkSheet[] getAllWorkSheetsForEmployeeProjectPair(String employeeID,String projectID) 147 throws ProjectManagementBusinessException { 148 try { 149 WorkSheetQuery query = new WorkSheetQuery(); 150 if (employeeID != null || projectID != null) { 151 QueryBuilder mainQuery=query.getQueryBuilder(); 152 QueryBuilder subQuery=new QueryBuilder(); 153 subQuery.select(PayRateDO.PrimaryKey); 154 if (employeeID != null) { 155 EmployeeManagerImpl employeeManager=new EmployeeManagerImpl(); 156 EmployeeImpl employee=(EmployeeImpl)employeeManager.findEmployeeByID(employeeID); 157 158 subQuery.addWhere(PayRateDO.Employee,employee.getDO(),QueryBuilder.EQUAL); 159 } 160 if (projectID != null) { 161 ProjectManagerImpl projectManager = new ProjectManagerImpl(); 162 Project project = projectManager.findProjectByID(projectID); 163 164 subQuery.addWhere(PayRateDO.Project,((ProjectImpl)project).getDO(),QueryBuilder.EQUAL); 165 } 166 mainQuery.addWhereIn(WorkSheetDO.PayRate,subQuery); 167 } 168 WorkSheetDO[] foundWorkSheets = query.getDOArray(); 169 if(foundWorkSheets.length != 0) { 170 WorkSheetImpl[] ws=new WorkSheetImpl[foundWorkSheets.length]; 171 for (int i=0; i<foundWorkSheets.length; i++) { 172 ws[i]=new WorkSheetImpl(foundWorkSheets[i]); 173 } 174 return ws; 175 } else { 176 return null; 177 } 178 179 } catch(NonUniqueQueryException ex) { 180 Enhydra.getLogChannel().write(Logger.DEBUG, 181 "Non-unique worksheet found in database: "+ex.getMessage()); 182 throw new ProjectManagementBusinessException("Non unique worksheet found"); 183 } catch(DataObjectException ex) { 184 throw new ProjectManagementBusinessException("Database error retrieving worksheets: ", ex); 185 } catch(QueryException ex) { 186 throw new ProjectManagementBusinessException("Query exception retrieving worksheets: ", ex); 187 } 188 } 189 190 204 public WorkSheet[] getAllWorkSheetsForEmployeeProjectPair(Employee employee, Project project) 205 throws ProjectManagementBusinessException { 206 try { 207 WorkSheetQuery query = new WorkSheetQuery(); 208 if (employee != null || project != null) { 209 QueryBuilder mainQuery=query.getQueryBuilder(); 210 QueryBuilder subQuery=new QueryBuilder(); 211 subQuery.select(PayRateDO.PrimaryKey); 212 if (employee != null) 213 subQuery.addWhere(PayRateDO.Employee,((EmployeeImpl)employee).getDO(),QueryBuilder.EQUAL); 214 if (project != null) 215 subQuery.addWhere(PayRateDO.Project,((ProjectImpl)project).getDO(),QueryBuilder.EQUAL); 216 mainQuery.addWhereIn(WorkSheetDO.PayRate,subQuery); 217 } 218 WorkSheetDO[] foundWorkSheets = query.getDOArray(); 219 if(foundWorkSheets.length != 0) { 220 WorkSheetImpl[] ws=new WorkSheetImpl[foundWorkSheets.length]; 221 for (int i=0; i<foundWorkSheets.length; i++) { 222 ws[i]=new WorkSheetImpl(foundWorkSheets[i]); 223 } 224 return ws; 225 } else { 226 return null; 227 } 228 229 } catch(NonUniqueQueryException ex) { 230 Enhydra.getLogChannel().write(Logger.DEBUG, 231 "Non-unique worksheet found in database: "+ex.getMessage()); 232 throw new ProjectManagementBusinessException("Non unique worksheet found"); 233 } catch(DataObjectException ex) { 234 throw new ProjectManagementBusinessException("Database error retrieving worksheets: ", ex); 235 } catch(QueryException ex) { 236 throw new ProjectManagementBusinessException("Query exception retrieving worksheets: ", ex); 237 } 238 } 239 240 257 public WorkSheet[] getAllWorkSheetsForEmployeeProjectPairFromDate1ToDate2( 258 String employeeID, String projectID, java.sql.Date date1, java.sql.Date date2) 259 throws ProjectManagementBusinessException { 260 try { 261 WorkSheetQuery query = new WorkSheetQuery(); 262 QueryBuilder mainQuery=query.getQueryBuilder(); 263 if (employeeID != null || projectID != null) { 264 QueryBuilder subQuery=new QueryBuilder(); 265 subQuery.select(PayRateDO.PrimaryKey); 266 if (employeeID != null) { 267 EmployeeManagerImpl employeeManager=new EmployeeManagerImpl(); 268 Employee employee= employeeManager.findEmployeeByID(employeeID); 269 subQuery.addWhere(PayRateDO.Employee,((EmployeeImpl)employee).getDO(),QueryBuilder.EQUAL); 270 } 271 if (projectID != null) { 272 ProjectManagerImpl projectManager = new ProjectManagerImpl(); 273 Project project = projectManager.findProjectByID(projectID); 274 subQuery.addWhere(PayRateDO.Project,((ProjectImpl)project).getDO(),QueryBuilder.EQUAL); 275 } 276 mainQuery.addWhereIn(WorkSheetDO.PayRate,subQuery); 277 } 278 mainQuery.addWhere(WorkSheetDO.WorkingDate,date1,QueryBuilder.GREATER_THAN_OR_EQUAL); 279 mainQuery.addWhere(WorkSheetDO.WorkingDate,date2,QueryBuilder.LESS_THAN_OR_EQUAL); 280 WorkSheetDO[] foundWorkSheets = query.getDOArray(); 281 if(foundWorkSheets.length != 0) { 282 WorkSheetImpl[] ws=new WorkSheetImpl[foundWorkSheets.length]; 283 for (int i=0; i<foundWorkSheets.length; i++) { 284 ws[i]=new WorkSheetImpl(foundWorkSheets[i]); 285 } 286 return ws; 287 } else { 288 return null; 289 } 290 291 } catch(NonUniqueQueryException ex) { 292 Enhydra.getLogChannel().write(Logger.DEBUG, 293 "Non-unique worksheet found in database: "+ex.getMessage()); 294 throw new ProjectManagementBusinessException("Non unique worksheet found"); 295 } catch(DataObjectException ex) { 296 throw new ProjectManagementBusinessException("Database error retrieving worksheets: ", ex); 297 } catch(QueryException ex) { 298 throw new ProjectManagementBusinessException("Query exception retrieving worksheets: ", ex); 299 } 300 } 301 302 319 public WorkSheet[] getAllWorkSheetsForEmployeeProjectPairFromDate1ToDate2( 320 Employee employee, Project project, java.sql.Date date1, java.sql.Date date2) 321 throws ProjectManagementBusinessException { 322 try { 323 WorkSheetQuery query = new WorkSheetQuery(); 324 QueryBuilder mainQuery=query.getQueryBuilder(); 325 if (employee != null || project != null) { 326 QueryBuilder subQuery=new QueryBuilder(); 327 subQuery.select(PayRateDO.PrimaryKey); 328 if (employee != null) 329 subQuery.addWhere(PayRateDO.Employee,((EmployeeImpl)employee).getDO(),QueryBuilder.EQUAL); 330 if (project != null) 331 subQuery.addWhere(PayRateDO.Project,((ProjectImpl)project).getDO(),QueryBuilder.EQUAL); 332 mainQuery.addWhereIn(WorkSheetDO.PayRate,subQuery); 333 } 334 mainQuery.addWhere(WorkSheetDO.WorkingDate,date1,QueryBuilder.GREATER_THAN_OR_EQUAL); 335 mainQuery.addWhere(WorkSheetDO.WorkingDate,date2,QueryBuilder.LESS_THAN_OR_EQUAL); 336 WorkSheetDO[] foundWorkSheets = query.getDOArray(); 337 if(foundWorkSheets.length != 0) { 338 WorkSheetImpl[] ws=new WorkSheetImpl[foundWorkSheets.length]; 339 for (int i=0; i<foundWorkSheets.length; i++) { 340 ws[i]=new WorkSheetImpl(foundWorkSheets[i]); 341 } 342 return ws; 343 } else { 344 return null; 345 } 346 347 } catch(NonUniqueQueryException ex) { 348 Enhydra.getLogChannel().write(Logger.DEBUG, 349 "Non-unique worksheet found in database: "+ex.getMessage()); 350 throw new ProjectManagementBusinessException("Non unique worksheet found"); 351 } catch(DataObjectException ex) { 352 throw new ProjectManagementBusinessException("Database error retrieving worksheets: ", ex); 353 } catch(QueryException ex) { 354 throw new ProjectManagementBusinessException("Query exception retrieving worksheets: ", ex); 355 } 356 } 357 374 public WorkSheet[] getAllWorksheetsForEmployeeArrayAndProjectArrayBetweenDates( 375 java.util.ArrayList employeeIDs, java.util.ArrayList projectIDs, java.sql.Date date1, java.sql.Date date2) 376 throws ProjectManagementBusinessException { 377 378 String employeeID=""; 379 String projectID=""; 380 java.util.Iterator it1=employeeIDs.iterator(); 381 java.util.Iterator it2=projectIDs.iterator(); 382 383 try { 384 WorkSheetQuery query = new WorkSheetQuery(); 385 QueryBuilder mainQuery=query.getQueryBuilder(); 386 387 QueryBuilder subQuery=new QueryBuilder(); 388 subQuery.select(PayRateDO.PrimaryKey); 389 subQuery.addWhereOpenParen(); 390 boolean firstPass = true; 391 while( it1.hasNext() ) { 392 employeeID=it1.next().toString(); 393 if (employeeID !=null && employeeID.length()==0) { 394 employeeID=null; 395 } 396 if (employeeID != null) { 397 EmployeeManagerImpl employeeManager=new EmployeeManagerImpl(); 398 Employee employee= employeeManager.findEmployeeByID(employeeID); 399 if ( !firstPass ) { 400 subQuery.addWhereOr(); 401 } 402 firstPass = false; 403 subQuery.addWhere(PayRateDO.Employee,((EmployeeImpl)employee).getDO(),QueryBuilder.EQUAL); 404 } 405 } 406 subQuery.addWhereCloseParen(); 407 subQuery.addWhereOpenParen(); 408 firstPass = true; 409 while( it2.hasNext() ) { 410 projectID=it2.next().toString(); 411 if (projectID != null && projectID.length()==0) { 412 projectID = null; 413 } 414 if (projectID != null) { 415 ProjectManagerImpl projectManager = new ProjectManagerImpl(); 416 Project project = projectManager.findProjectByID(projectID); 417 if ( !firstPass ) { 418 subQuery.addWhereOr(); 419 } 420 firstPass = false; 421 subQuery.addWhere(PayRateDO.Project,((ProjectImpl)project).getDO(),QueryBuilder.EQUAL); 422 } 423 } 424 subQuery.addWhereCloseParen(); 425 mainQuery.addWhereIn(WorkSheetDO.PayRate,subQuery); 426 mainQuery.addWhere(WorkSheetDO.WorkingDate,date1,QueryBuilder.GREATER_THAN_OR_EQUAL); 427 mainQuery.addWhere(WorkSheetDO.WorkingDate,date2,QueryBuilder.LESS_THAN_OR_EQUAL); 428 WorkSheetDO[] foundWorkSheets = query.getDOArray(); 429 430 if(foundWorkSheets.length != 0) { 431 WorkSheetImpl[] ws=new WorkSheetImpl[foundWorkSheets.length]; 432 try { 433 for (int i=0; i<foundWorkSheets.length; i++) { 434 ws[i]=new WorkSheetImpl(foundWorkSheets[i]); 435 } 436 } catch ( Exception e ) { e.printStackTrace(); } 437 return ws; 438 } else { 439 return null; 440 } 441 442 } catch(NonUniqueQueryException ex) { 443 Enhydra.getLogChannel().write(Logger.DEBUG, 444 "Non-unique worksheet found in database: "+ex.getMessage()); 445 throw new ProjectManagementBusinessException("Non unique worksheet found"); 446 } catch(DataObjectException ex) { 447 throw new ProjectManagementBusinessException("Database error retrieving worksheets: ", ex); 448 } catch(QueryException ex) { 449 throw new ProjectManagementBusinessException("Query exception retrieving worksheets: ", ex); 450 } 451 } 452 public WorkSheet getWorkSheet() 453 throws ProjectManagementBusinessException{ 454 return new WorkSheetImpl(); 455 } 456 457 } 458 | Popular Tags |