1 package projectmanagement.business.timewage; 2 3 import projectmanagement.business.employee.*; 4 import projectmanagement.business.project.*; 5 import projectmanagement.business.ProjectManagementBusinessException; 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 java.sql.Date ; 15 import java.util.HashMap ; 16 import java.util.Iterator ; 17 18 import projectmanagement.spec.timewage.*; 19 import projectmanagement.spec.employee.*; 20 import projectmanagement.spec.project.*; 21 27 public class PayRateManagerImpl implements PayRateManager { 28 29 37 public PayRate[] getAllPayRates() 38 throws ProjectManagementBusinessException { 39 try { 40 PayRateQuery query = new PayRateQuery(); 41 42 PayRateDO[] foundPayRates = query.getDOArray(); 43 if(foundPayRates.length != 0) { 44 PayRateImpl[] cs=new PayRateImpl[foundPayRates.length]; 45 for (int i=0; i<foundPayRates.length; i++) { 46 cs[i]=new PayRateImpl(foundPayRates[i]); 47 } 48 return cs; 49 } else { 50 return null; 51 } 52 } catch(NonUniqueQueryException ex) { 53 Enhydra.getLogChannel().write(Logger.DEBUG, 54 "Non-unique pay rate found in database: "+ex.getMessage()); 55 throw new ProjectManagementBusinessException("Non unique pay rate found"); 56 } catch(DataObjectException ex) { 57 throw new ProjectManagementBusinessException("Database error retrieving pay rates: ", ex); 58 } 61 } 62 63 76 public PayRate[] getAllPayRatesForEmployee(String employeeID, boolean distinctOnEmployProjectPair) 77 throws ProjectManagementBusinessException { 78 try { 79 EmployeeManagerImpl employeeManager=new EmployeeManagerImpl(); 80 EmployeeImpl emp=(EmployeeImpl)employeeManager.findEmployeeByID(employeeID); 81 82 if (emp==null) { 83 throw new ProjectManagementBusinessException("The employee for given ID can't be found"); 84 } 85 PayRateQuery query = new PayRateQuery(); 86 query.setQueryEmployee(emp.getDO()); 87 88 PayRateDO[] foundPayRates = query.getDOArray(); 89 if(foundPayRates.length != 0) { 91 if (distinctOnEmployProjectPair) { 92 HashMap distinctPayRate = new HashMap (); 93 for (int i=0; i<foundPayRates.length; i++) { 94 String key = foundPayRates[i].getEmployee().getOId()+"."+foundPayRates[i].getProject().getOId(); 95 distinctPayRate.put(key,foundPayRates[i]); 96 } 97 PayRateImpl[] prs=new PayRateImpl[distinctPayRate.size()]; 98 Iterator iter = distinctPayRate.values().iterator(); 99 for (int i = 0; iter.hasNext(); i++ ) 100 prs[i]=new PayRateImpl((PayRateDO)iter.next()); 101 return prs; 102 } else { 103 PayRateImpl[] prs=new PayRateImpl[foundPayRates.length]; 104 for (int i=0; i<foundPayRates.length; i++) 105 prs[i]=new PayRateImpl(foundPayRates[i]); 106 return prs; 107 } 108 } else { 109 return null; 110 } 111 } catch(NonUniqueQueryException ex) { 112 Enhydra.getLogChannel().write(Logger.DEBUG, 113 "Non-unique pay rate found in database: "+ex.getMessage()); 114 throw new ProjectManagementBusinessException("Non unique pay rate found"); 115 } catch(DataObjectException ex) { 116 throw new ProjectManagementBusinessException("Database error retrieving pay rates: ", ex); 117 } catch(QueryException ex) { 118 throw new ProjectManagementBusinessException("Query exception retrieving pay rates: ", ex); 119 } 120 } 121 122 133 public PayRate[] getAllPayRatesForEmployeeProjectPair (String employeeID,String projectID) 134 throws ProjectManagementBusinessException { 135 try { 136 PayRateQuery query = new PayRateQuery(); 137 if (employeeID != null || projectID != null) { 138 QueryBuilder mainQuery=query.getQueryBuilder(); 139 if (employeeID != null) { 140 141 EmployeeManagerImpl employeeManager=new EmployeeManagerImpl(); 142 EmployeeImpl employee=(EmployeeImpl) employeeManager.findEmployeeByID(employeeID); 143 144 mainQuery.addWhere(PayRateDO.Employee,employee.getDO(),QueryBuilder.EQUAL); 145 } 146 if (projectID != null) { 147 148 ProjectManagerImpl projectManager = new ProjectManagerImpl(); 149 Project project = projectManager.findProjectByID(projectID); 150 151 mainQuery.addWhere(PayRateDO.Project,((ProjectImpl)project).getDO(),QueryBuilder.EQUAL); 152 } 153 } 154 PayRateDO[] foundPayRates = query.getDOArray(); 155 if(foundPayRates.length != 0) { 156 PayRateImpl[] pr=new PayRateImpl[foundPayRates.length]; 157 for (int i=0; i<foundPayRates.length; i++) { 158 pr[i]=new PayRateImpl(foundPayRates[i]); 159 } 160 return pr; 161 } else { 162 return null; 163 } 164 } catch(NonUniqueQueryException ex) { 165 Enhydra.getLogChannel().write(Logger.DEBUG, 166 "Non-unique pay rate found in database: "+ex.getMessage()); 167 throw new ProjectManagementBusinessException("Non unique pay rate found"); 168 } catch(DataObjectException ex) { 169 throw new ProjectManagementBusinessException("Database error retrieving pay rates: ", ex); 170 } 173 } 174 175 188 public PayRate findPayRateByID(String id) 189 throws ProjectManagementBusinessException { 190 PayRateImpl thePayRate = null; 191 192 try { 193 PayRateQuery query = new PayRateQuery(); 194 query.setQueryOId(new ObjectId(id)); 196 query.requireUniqueInstance(); 198 PayRateDO thePayRateDO = query.getNextDO(); 199 thePayRate = new PayRateImpl(thePayRateDO); 200 return thePayRate; 201 } catch(Exception ex) { 202 throw new ProjectManagementBusinessException("Exception in findPayRateByID()", ex); 203 } 204 } 205 206 223 public PayRate findPayRateByEmployeeProjectAndDate(String employeeID, String projectID, Date workingDate) 224 throws ProjectManagementBusinessException { 225 226 PayRate thePayRate = null; 227 228 try { 229 EmployeeManagerImpl employeeManager=new EmployeeManagerImpl(); 230 Employee emp= employeeManager.findEmployeeByID(employeeID); 231 232 if (emp==null) { 233 throw new ProjectManagementBusinessException("The employee for given ID can't be found"); 234 } 235 ProjectManagerImpl projectManager = new ProjectManagerImpl(); 236 Project proj = projectManager.findProjectByID(projectID); 237 238 if (proj==null) { 239 throw new ProjectManagementBusinessException("The project for given ID can't be found"); 240 } 241 242 PayRateQuery query = new PayRateQuery(); 243 query.setQueryEmployee(((EmployeeImpl)emp).getDO()); 245 query.getQueryBuilder().addWhere(PayRateDO.Project,((ProjectImpl)proj).getDO(),QueryBuilder.EQUAL); 246 query.getQueryBuilder().addOrderByColumn(PayRateDO.ValidFrom,"DESC"); 247 248 PayRateDO[] foundPayRates = query.getDOArray(); 250 if(foundPayRates!=null && foundPayRates.length != 0) { 251 for (int i=0; i<foundPayRates.length; i++) { 253 PayRateDO pr=foundPayRates[i]; 254 if (pr.getValidFrom().compareTo(workingDate)<=0) { 256 thePayRate=new PayRateImpl(pr); 257 break; 258 } 259 } 260 } 261 264 265 return thePayRate; 266 } catch(Exception ex) { 267 throw new ProjectManagementBusinessException("Exception in findPayRateByEmployeeProjectAndDate()", ex); 268 } 269 } 270 public PayRate getPayRate() 271 throws ProjectManagementBusinessException{ 272 return new PayRateImpl(); 273 } 274 } 275 | Popular Tags |