001: package projectmanagement.business.timewage;
002:
003: import projectmanagement.business.ProjectManagementBusinessException;
004: import projectmanagement.business.employee.*;
005: import projectmanagement.business.project.*;
006: import projectmanagement.data.timewage.*;
007: import com.lutris.appserver.server.sql.DatabaseManagerException;
008: import com.lutris.appserver.server.sql.ObjectId;
009: import com.lutris.appserver.server.sql.ObjectIdException;
010: import com.lutris.dods.builder.generator.query.*;
011: import com.lutris.appserver.server.Enhydra;
012: import com.lutris.logging.*;
013:
014: import projectmanagement.spec.employee.*;
015: import projectmanagement.spec.project.*;
016: import projectmanagement.spec.timewage.*;
017:
018: /**
019: * Used to find the instance of WorkSheet.
020: *
021: * @author Sasa Bojanic
022: * @version 1.0
023: */
024: public class WorkSheetManagerImpl implements WorkSheetManager {
025:
026: /**
027: * The getAllWorkSheets method performs a database query to
028: * return all <CODE>WorkSheet</CODE> objects representing the
029: * row in the <CODE>WorkSheets</CODE> table.
030: * @return all the worksheets, or null if there are no any.
031: * @exception ProjectManagementBusinessException
032: * if there is a problem retrieving workshit information.
033: */
034: public WorkSheet[] getAllWorkSheets()
035: throws ProjectManagementBusinessException {
036: try {
037: WorkSheetQuery query = new WorkSheetQuery();
038:
039: WorkSheetDO[] foundWorkSheets = query.getDOArray();
040: if (foundWorkSheets.length != 0) {
041: WorkSheetImpl[] cs = new WorkSheetImpl[foundWorkSheets.length];
042: for (int i = 0; i < foundWorkSheets.length; i++) {
043: cs[i] = new WorkSheetImpl(foundWorkSheets[i]);
044: }
045: return cs;
046: } else {
047: return null;
048: }
049: } catch (NonUniqueQueryException ex) {
050: Enhydra.getLogChannel().write(
051: Logger.DEBUG,
052: "Non-unique workshit found in database: "
053: + ex.getMessage());
054: throw new ProjectManagementBusinessException(
055: "Non unique worksheet found");
056: } catch (DataObjectException ex) {
057: throw new ProjectManagementBusinessException(
058: "Database error retrieving worksheets: ", ex);
059: } /*catch(QueryException ex) {
060: throw new ProjectManagementBusinessException("Query exception retrieving worksheets: ", ex);
061: }*/
062: }
063:
064: /**
065: * The getAllWorkSheetsForEmployee method performs a database query to
066: * return all <CODE>WorkSheet</CODE> objects representing the
067: * row in the <CODE>WorkSheets</CODE> table that belongs to the
068: * given employee.
069: * @param employee the employee
070: * @return all the worksheets for given employee
071: * @exception ProjectManagementBusinessException
072: * if there is a problem retrieving worksheet information.
073: */
074: public WorkSheet[] getAllWorkSheetsForEmployee(Employee employee)
075: throws ProjectManagementBusinessException {
076: try {
077: WorkSheetQuery query = new WorkSheetQuery();
078: QueryBuilder mainQuery = query.getQueryBuilder();
079: QueryBuilder subQuery = new QueryBuilder();
080: subQuery.select(PayRateDO.PrimaryKey);
081: subQuery.addWhere(PayRateDO.Employee,
082: ((EmployeeImpl) employee).getDO(),
083: QueryBuilder.EQUAL);
084: mainQuery.addWhereIn(WorkSheetDO.PayRate, subQuery);
085:
086: WorkSheetDO[] foundWorkSheets = query.getDOArray();
087: if (foundWorkSheets.length != 0) {
088: WorkSheetImpl[] cs = new WorkSheetImpl[foundWorkSheets.length];
089: for (int i = 0; i < foundWorkSheets.length; i++) {
090: cs[i] = new WorkSheetImpl(foundWorkSheets[i]);
091: }
092: return cs;
093: } else {
094: return null;
095: }
096: } catch (NonUniqueQueryException ex) {
097: Enhydra.getLogChannel().write(
098: Logger.DEBUG,
099: "Non-unique worksheet found in database: "
100: + ex.getMessage());
101: throw new ProjectManagementBusinessException(
102: "Non unique worksheet found");
103: } catch (DataObjectException ex) {
104: throw new ProjectManagementBusinessException(
105: "Database error retrieving worksheets: ", ex);
106: } catch (QueryException ex) {
107: throw new ProjectManagementBusinessException(
108: "Query exception retrieving worksheets: ", ex);
109: }
110: }
111:
112: /**
113: * The findWorkSheetByID method performs a database query to
114: * return a <CODE>WorkSheet</CODE> object
115: * representing the row in the <CODE>worksheet</CODE> table
116: * that matches the object id.
117: *
118: * @param id, the object id of the worksheet table.
119: * @return
120: * the worksheet. null if there isn't a worksheet associated
121: * the id
122: * @exception ProjectManagementBusinessException
123: * if there is a problem retrieving worksheet information.
124: */
125: public WorkSheet findWorkSheetByID(String id)
126: throws ProjectManagementBusinessException {
127: WorkSheetImpl theWorkSheet = null;
128:
129: try {
130: WorkSheetQuery query = new WorkSheetQuery();
131: //set query
132: query.setQueryOId(new ObjectId(id));
133: // Throw an exception if more than one user by this name is found
134: query.requireUniqueInstance();
135: WorkSheetDO theWorkSheetDO = query.getNextDO();
136: theWorkSheet = new WorkSheetImpl(theWorkSheetDO);
137: return theWorkSheet;
138: } catch (Exception ex) {
139: throw new ProjectManagementBusinessException(
140: "Exception in findWorkSheetByID()", ex);
141: }
142: }
143:
144: /**
145: * The getAllWorkSheetsForEmployeeProjectPair method performs
146: * a database query to return a <CODE>WorkSheet</CODE> objects
147: * representing the row in the <CODE>worksheet</CODE> table
148: * that matches the employee given by employeeID and project
149: * given by projectID.
150: *
151: * @param employeeID, the object id of Employee for which we need worksheets.
152: * @param projectID, the object id of Project for which we need worksheets.
153: * @return
154: * array of worksheets. null if there isn't a worksheet associated
155: * the employeeID and projectID
156: * @exception ProjectManagementBusinessException
157: * if there is a problem retrieving worksheet information.
158: */
159: public WorkSheet[] getAllWorkSheetsForEmployeeProjectPair(
160: String employeeID, String projectID)
161: throws ProjectManagementBusinessException {
162: try {
163: WorkSheetQuery query = new WorkSheetQuery();
164: if (employeeID != null || projectID != null) {
165: QueryBuilder mainQuery = query.getQueryBuilder();
166: QueryBuilder subQuery = new QueryBuilder();
167: subQuery.select(PayRateDO.PrimaryKey);
168: if (employeeID != null) {
169: EmployeeManagerImpl employeeManager = new EmployeeManagerImpl();
170: EmployeeImpl employee = (EmployeeImpl) employeeManager
171: .findEmployeeByID(employeeID);
172:
173: subQuery.addWhere(PayRateDO.Employee, employee
174: .getDO(), QueryBuilder.EQUAL);
175: }
176: if (projectID != null) {
177: ProjectManagerImpl projectManager = new ProjectManagerImpl();
178: Project project = projectManager
179: .findProjectByID(projectID);
180:
181: subQuery.addWhere(PayRateDO.Project,
182: ((ProjectImpl) project).getDO(),
183: QueryBuilder.EQUAL);
184: }
185: mainQuery.addWhereIn(WorkSheetDO.PayRate, subQuery);
186: }
187: WorkSheetDO[] foundWorkSheets = query.getDOArray();
188: if (foundWorkSheets.length != 0) {
189: WorkSheetImpl[] ws = new WorkSheetImpl[foundWorkSheets.length];
190: for (int i = 0; i < foundWorkSheets.length; i++) {
191: ws[i] = new WorkSheetImpl(foundWorkSheets[i]);
192: }
193: return ws;
194: } else {
195: return null;
196: }
197:
198: } catch (NonUniqueQueryException ex) {
199: Enhydra.getLogChannel().write(
200: Logger.DEBUG,
201: "Non-unique worksheet found in database: "
202: + ex.getMessage());
203: throw new ProjectManagementBusinessException(
204: "Non unique worksheet found");
205: } catch (DataObjectException ex) {
206: throw new ProjectManagementBusinessException(
207: "Database error retrieving worksheets: ", ex);
208: } catch (QueryException ex) {
209: throw new ProjectManagementBusinessException(
210: "Query exception retrieving worksheets: ", ex);
211: }
212: }
213:
214: /**
215: * The getAllWorkSheetsForEmployeeProjectPair method performs
216: * a database query to return a <CODE>WorkSheet</CODE> objects
217: * representing the row in the <CODE>worksheet</CODE> table
218: * that matches the employee and project.
219: *
220: * @param employee employee for which we need worksheets.
221: * @param project project for which we need worksheets.
222: * @return
223: * array of worksheets. null if there isn't a worksheet associated
224: * the employee and project
225: * @exception ProjectManagementBusinessException
226: * if there is a problem retrieving worksheet information.
227: */
228: public WorkSheet[] getAllWorkSheetsForEmployeeProjectPair(
229: Employee employee, Project project)
230: throws ProjectManagementBusinessException {
231: try {
232: WorkSheetQuery query = new WorkSheetQuery();
233: if (employee != null || project != null) {
234: QueryBuilder mainQuery = query.getQueryBuilder();
235: QueryBuilder subQuery = new QueryBuilder();
236: subQuery.select(PayRateDO.PrimaryKey);
237: if (employee != null)
238: subQuery.addWhere(PayRateDO.Employee,
239: ((EmployeeImpl) employee).getDO(),
240: QueryBuilder.EQUAL);
241: if (project != null)
242: subQuery.addWhere(PayRateDO.Project,
243: ((ProjectImpl) project).getDO(),
244: QueryBuilder.EQUAL);
245: mainQuery.addWhereIn(WorkSheetDO.PayRate, subQuery);
246: }
247: WorkSheetDO[] foundWorkSheets = query.getDOArray();
248: if (foundWorkSheets.length != 0) {
249: WorkSheetImpl[] ws = new WorkSheetImpl[foundWorkSheets.length];
250: for (int i = 0; i < foundWorkSheets.length; i++) {
251: ws[i] = new WorkSheetImpl(foundWorkSheets[i]);
252: }
253: return ws;
254: } else {
255: return null;
256: }
257:
258: } catch (NonUniqueQueryException ex) {
259: Enhydra.getLogChannel().write(
260: Logger.DEBUG,
261: "Non-unique worksheet found in database: "
262: + ex.getMessage());
263: throw new ProjectManagementBusinessException(
264: "Non unique worksheet found");
265: } catch (DataObjectException ex) {
266: throw new ProjectManagementBusinessException(
267: "Database error retrieving worksheets: ", ex);
268: } catch (QueryException ex) {
269: throw new ProjectManagementBusinessException(
270: "Query exception retrieving worksheets: ", ex);
271: }
272: }
273:
274: /**
275: * The getAllWorkSheetsForEmployeeProjectPair method performs
276: * a database query to return a <CODE>WorkSheet</CODE> objects
277: * representing the row in the <CODE>worksheet</CODE> table
278: * that matches the employee given by employeeID, project given
279: * by projectID and between date1 and date2 (including date1).
280: *
281: * @param employeeID, the object id of Employee for which we need worksheets.
282: * @param projectID, the object id of Project for which we need worksheets.
283: * @param date1 begining date (including date1)
284: * @param date2 ending date
285: * @return
286: * array of worksheets. null if there isn't a worksheet associated
287: * the employeeID, projectID and between date1 and date2
288: * @exception ProjectManagementBusinessException
289: * if there is a problem retrieving worksheet information.
290: */
291: public WorkSheet[] getAllWorkSheetsForEmployeeProjectPairFromDate1ToDate2(
292: String employeeID, String projectID, java.sql.Date date1,
293: java.sql.Date date2)
294: throws ProjectManagementBusinessException {
295: try {
296: WorkSheetQuery query = new WorkSheetQuery();
297: QueryBuilder mainQuery = query.getQueryBuilder();
298: if (employeeID != null || projectID != null) {
299: QueryBuilder subQuery = new QueryBuilder();
300: subQuery.select(PayRateDO.PrimaryKey);
301: if (employeeID != null) {
302: EmployeeManagerImpl employeeManager = new EmployeeManagerImpl();
303: Employee employee = employeeManager
304: .findEmployeeByID(employeeID);
305: subQuery.addWhere(PayRateDO.Employee,
306: ((EmployeeImpl) employee).getDO(),
307: QueryBuilder.EQUAL);
308: }
309: if (projectID != null) {
310: ProjectManagerImpl projectManager = new ProjectManagerImpl();
311: Project project = projectManager
312: .findProjectByID(projectID);
313: subQuery.addWhere(PayRateDO.Project,
314: ((ProjectImpl) project).getDO(),
315: QueryBuilder.EQUAL);
316: }
317: mainQuery.addWhereIn(WorkSheetDO.PayRate, subQuery);
318: }
319: mainQuery.addWhere(WorkSheetDO.WorkingDate, date1,
320: QueryBuilder.GREATER_THAN_OR_EQUAL);
321: mainQuery.addWhere(WorkSheetDO.WorkingDate, date2,
322: QueryBuilder.LESS_THAN_OR_EQUAL);
323: WorkSheetDO[] foundWorkSheets = query.getDOArray();
324: if (foundWorkSheets.length != 0) {
325: WorkSheetImpl[] ws = new WorkSheetImpl[foundWorkSheets.length];
326: for (int i = 0; i < foundWorkSheets.length; i++) {
327: ws[i] = new WorkSheetImpl(foundWorkSheets[i]);
328: }
329: return ws;
330: } else {
331: return null;
332: }
333:
334: } catch (NonUniqueQueryException ex) {
335: Enhydra.getLogChannel().write(
336: Logger.DEBUG,
337: "Non-unique worksheet found in database: "
338: + ex.getMessage());
339: throw new ProjectManagementBusinessException(
340: "Non unique worksheet found");
341: } catch (DataObjectException ex) {
342: throw new ProjectManagementBusinessException(
343: "Database error retrieving worksheets: ", ex);
344: } catch (QueryException ex) {
345: throw new ProjectManagementBusinessException(
346: "Query exception retrieving worksheets: ", ex);
347: }
348: }
349:
350: /**
351: * The getAllWorkSheetsForEmployeeProjectPair method performs
352: * a database query to return a <CODE>WorkSheet</CODE> objects
353: * representing the row in the <CODE>worksheet</CODE> table
354: * that matches the employee, project and between date1 and date2
355: * (including date1).
356: *
357: * @param employee Employee for which we need worksheets.
358: * @param project Project for which we need worksheets.
359: * @param date1 begining date (including date1)
360: * @param date2 ending date
361: * @return
362: * array of worksheets. null if there isn't a worksheet associated
363: * the employeeID, projectID and between date1 and date2
364: * @exception ProjectManagementBusinessException
365: * if there is a problem retrieving worksheet information.
366: */
367: public WorkSheet[] getAllWorkSheetsForEmployeeProjectPairFromDate1ToDate2(
368: Employee employee, Project project, java.sql.Date date1,
369: java.sql.Date date2)
370: throws ProjectManagementBusinessException {
371: try {
372: WorkSheetQuery query = new WorkSheetQuery();
373: QueryBuilder mainQuery = query.getQueryBuilder();
374: if (employee != null || project != null) {
375: QueryBuilder subQuery = new QueryBuilder();
376: subQuery.select(PayRateDO.PrimaryKey);
377: if (employee != null)
378: subQuery.addWhere(PayRateDO.Employee,
379: ((EmployeeImpl) employee).getDO(),
380: QueryBuilder.EQUAL);
381: if (project != null)
382: subQuery.addWhere(PayRateDO.Project,
383: ((ProjectImpl) project).getDO(),
384: QueryBuilder.EQUAL);
385: mainQuery.addWhereIn(WorkSheetDO.PayRate, subQuery);
386: }
387: mainQuery.addWhere(WorkSheetDO.WorkingDate, date1,
388: QueryBuilder.GREATER_THAN_OR_EQUAL);
389: mainQuery.addWhere(WorkSheetDO.WorkingDate, date2,
390: QueryBuilder.LESS_THAN_OR_EQUAL);
391: WorkSheetDO[] foundWorkSheets = query.getDOArray();
392: if (foundWorkSheets.length != 0) {
393: WorkSheetImpl[] ws = new WorkSheetImpl[foundWorkSheets.length];
394: for (int i = 0; i < foundWorkSheets.length; i++) {
395: ws[i] = new WorkSheetImpl(foundWorkSheets[i]);
396: }
397: return ws;
398: } else {
399: return null;
400: }
401:
402: } catch (NonUniqueQueryException ex) {
403: Enhydra.getLogChannel().write(
404: Logger.DEBUG,
405: "Non-unique worksheet found in database: "
406: + ex.getMessage());
407: throw new ProjectManagementBusinessException(
408: "Non unique worksheet found");
409: } catch (DataObjectException ex) {
410: throw new ProjectManagementBusinessException(
411: "Database error retrieving worksheets: ", ex);
412: } catch (QueryException ex) {
413: throw new ProjectManagementBusinessException(
414: "Query exception retrieving worksheets: ", ex);
415: }
416: }
417:
418: /**
419: * The getAllWorkSheetsForEmployeeProjectPair method performs
420: * a database query to return a <CODE>WorkSheet</CODE> objects
421: * representing the row in the <CODE>worksheet</CODE> table
422: * that matches the employee, project and between date1 and date2
423: * (including date1).
424: *
425: * @param employeeIDs java.util.ArrayList for which we need worksheets.
426: * @param projectIDs java.util.ArrayList for which we need worksheets.
427: * @param date1 begining date (including date1)
428: * @param date2 ending date
429: * @return
430: * array of worksheets. null if there isn't a worksheet associated
431: * the employeeIDs, projectIDs and between date1 and date2
432: * @exception ProjectManagementBusinessException
433: * if there is a problem retrieving worksheet information.
434: */
435: public WorkSheet[] getAllWorksheetsForEmployeeArrayAndProjectArrayBetweenDates(
436: java.util.ArrayList employeeIDs,
437: java.util.ArrayList projectIDs, java.sql.Date date1,
438: java.sql.Date date2)
439: throws ProjectManagementBusinessException {
440:
441: String employeeID = "";
442: String projectID = "";
443: java.util.Iterator it1 = employeeIDs.iterator();
444: java.util.Iterator it2 = projectIDs.iterator();
445:
446: try {
447: WorkSheetQuery query = new WorkSheetQuery();
448: QueryBuilder mainQuery = query.getQueryBuilder();
449:
450: QueryBuilder subQuery = new QueryBuilder();
451: subQuery.select(PayRateDO.PrimaryKey);
452: subQuery.addWhereOpenParen();
453: boolean firstPass = true;
454: while (it1.hasNext()) {
455: employeeID = it1.next().toString();
456: if (employeeID != null && employeeID.length() == 0) {
457: employeeID = null;
458: }
459: if (employeeID != null) {
460: EmployeeManagerImpl employeeManager = new EmployeeManagerImpl();
461: Employee employee = employeeManager
462: .findEmployeeByID(employeeID);
463: if (!firstPass) {
464: subQuery.addWhereOr();
465: }
466: firstPass = false;
467: subQuery.addWhere(PayRateDO.Employee,
468: ((EmployeeImpl) employee).getDO(),
469: QueryBuilder.EQUAL);
470: }
471: }
472: subQuery.addWhereCloseParen();
473: subQuery.addWhereOpenParen();
474: firstPass = true;
475: while (it2.hasNext()) {
476: projectID = it2.next().toString();
477: if (projectID != null && projectID.length() == 0) {
478: projectID = null;
479: }
480: if (projectID != null) {
481: ProjectManagerImpl projectManager = new ProjectManagerImpl();
482: Project project = projectManager
483: .findProjectByID(projectID);
484: if (!firstPass) {
485: subQuery.addWhereOr();
486: }
487: firstPass = false;
488: subQuery.addWhere(PayRateDO.Project,
489: ((ProjectImpl) project).getDO(),
490: QueryBuilder.EQUAL);
491: }
492: }
493: subQuery.addWhereCloseParen();
494: mainQuery.addWhereIn(WorkSheetDO.PayRate, subQuery);
495: mainQuery.addWhere(WorkSheetDO.WorkingDate, date1,
496: QueryBuilder.GREATER_THAN_OR_EQUAL);
497: mainQuery.addWhere(WorkSheetDO.WorkingDate, date2,
498: QueryBuilder.LESS_THAN_OR_EQUAL);
499: WorkSheetDO[] foundWorkSheets = query.getDOArray();
500:
501: if (foundWorkSheets.length != 0) {
502: WorkSheetImpl[] ws = new WorkSheetImpl[foundWorkSheets.length];
503: try {
504: for (int i = 0; i < foundWorkSheets.length; i++) {
505: ws[i] = new WorkSheetImpl(foundWorkSheets[i]);
506: }
507: } catch (Exception e) {
508: e.printStackTrace();
509: }
510: return ws;
511: } else {
512: return null;
513: }
514:
515: } catch (NonUniqueQueryException ex) {
516: Enhydra.getLogChannel().write(
517: Logger.DEBUG,
518: "Non-unique worksheet found in database: "
519: + ex.getMessage());
520: throw new ProjectManagementBusinessException(
521: "Non unique worksheet found");
522: } catch (DataObjectException ex) {
523: throw new ProjectManagementBusinessException(
524: "Database error retrieving worksheets: ", ex);
525: } catch (QueryException ex) {
526: throw new ProjectManagementBusinessException(
527: "Query exception retrieving worksheets: ", ex);
528: }
529: }
530:
531: public WorkSheet getWorkSheet()
532: throws ProjectManagementBusinessException {
533: return new WorkSheetImpl();
534: }
535:
536: }
|