KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > projectmanagement > business > timewage > WorkSheetManagerImpl


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 /**
18  * Used to find the instance of WorkSheet.
19  *
20  * @author Sasa Bojanic
21  * @version 1.0
22  */

23 public class WorkSheetManagerImpl implements WorkSheetManager{
24
25    /**
26     * The getAllWorkSheets method performs a database query to
27     * return all <CODE>WorkSheet</CODE> objects representing the
28     * row in the <CODE>WorkSheets</CODE> table.
29     * @return all the worksheets, or null if there are no any.
30     * @exception ProjectManagementBusinessException
31     * if there is a problem retrieving workshit information.
32     */

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       } /*catch(QueryException ex) {
55          throw new ProjectManagementBusinessException("Query exception retrieving worksheets: ", ex);
56       }*/

57    }
58
59    /**
60     * The getAllWorkSheetsForEmployee method performs a database query to
61     * return all <CODE>WorkSheet</CODE> objects representing the
62     * row in the <CODE>WorkSheets</CODE> table that belongs to the
63     * given employee.
64     * @param employee the employee
65     * @return all the worksheets for given employee
66     * @exception ProjectManagementBusinessException
67     * if there is a problem retrieving worksheet information.
68     */

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    /**
101     * The findWorkSheetByID method performs a database query to
102     * return a <CODE>WorkSheet</CODE> object
103     * representing the row in the <CODE>worksheet</CODE> table
104     * that matches the object id.
105     *
106     * @param id, the object id of the worksheet table.
107     * @return
108     * the worksheet. null if there isn't a worksheet associated
109     * the id
110     * @exception ProjectManagementBusinessException
111     * if there is a problem retrieving worksheet information.
112     */

113    public WorkSheet findWorkSheetByID(String JavaDoc id)
114          throws ProjectManagementBusinessException {
115       WorkSheetImpl theWorkSheet = null;
116
117       try {
118          WorkSheetQuery query = new WorkSheetQuery();
119          //set query
120
query.setQueryOId(new ObjectId(id));
121          // Throw an exception if more than one user by this name is found
122
query.requireUniqueInstance();
123          WorkSheetDO theWorkSheetDO = query.getNextDO();
124          theWorkSheet = new WorkSheetImpl(theWorkSheetDO);
125          return theWorkSheet;
126       } catch(Exception JavaDoc ex) {
127          throw new ProjectManagementBusinessException("Exception in findWorkSheetByID()", ex);
128       }
129    }
130
131     /**
132      * The getAllWorkSheetsForEmployeeProjectPair method performs
133      * a database query to return a <CODE>WorkSheet</CODE> objects
134      * representing the row in the <CODE>worksheet</CODE> table
135      * that matches the employee given by employeeID and project
136      * given by projectID.
137      *
138      * @param employeeID, the object id of Employee for which we need worksheets.
139      * @param projectID, the object id of Project for which we need worksheets.
140      * @return
141      * array of worksheets. null if there isn't a worksheet associated
142      * the employeeID and projectID
143      * @exception ProjectManagementBusinessException
144      * if there is a problem retrieving worksheet information.
145      */

146     public WorkSheet[] getAllWorkSheetsForEmployeeProjectPair(String JavaDoc employeeID,String JavaDoc 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     /**
191      * The getAllWorkSheetsForEmployeeProjectPair method performs
192      * a database query to return a <CODE>WorkSheet</CODE> objects
193      * representing the row in the <CODE>worksheet</CODE> table
194      * that matches the employee and project.
195      *
196      * @param employee employee for which we need worksheets.
197      * @param project project for which we need worksheets.
198      * @return
199      * array of worksheets. null if there isn't a worksheet associated
200      * the employee and project
201      * @exception ProjectManagementBusinessException
202      * if there is a problem retrieving worksheet information.
203      */

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     /**
241      * The getAllWorkSheetsForEmployeeProjectPair method performs
242      * a database query to return a <CODE>WorkSheet</CODE> objects
243      * representing the row in the <CODE>worksheet</CODE> table
244      * that matches the employee given by employeeID, project given
245      * by projectID and between date1 and date2 (including date1).
246      *
247      * @param employeeID, the object id of Employee for which we need worksheets.
248      * @param projectID, the object id of Project for which we need worksheets.
249      * @param date1 begining date (including date1)
250      * @param date2 ending date
251      * @return
252      * array of worksheets. null if there isn't a worksheet associated
253      * the employeeID, projectID and between date1 and date2
254      * @exception ProjectManagementBusinessException
255      * if there is a problem retrieving worksheet information.
256      */

257     public WorkSheet[] getAllWorkSheetsForEmployeeProjectPairFromDate1ToDate2(
258                     String JavaDoc employeeID, String JavaDoc projectID, java.sql.Date JavaDoc date1, java.sql.Date JavaDoc 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     /**
303      * The getAllWorkSheetsForEmployeeProjectPair method performs
304      * a database query to return a <CODE>WorkSheet</CODE> objects
305      * representing the row in the <CODE>worksheet</CODE> table
306      * that matches the employee, project and between date1 and date2
307      * (including date1).
308      *
309      * @param employee Employee for which we need worksheets.
310      * @param project Project for which we need worksheets.
311      * @param date1 begining date (including date1)
312      * @param date2 ending date
313      * @return
314      * array of worksheets. null if there isn't a worksheet associated
315      * the employeeID, projectID and between date1 and date2
316      * @exception ProjectManagementBusinessException
317      * if there is a problem retrieving worksheet information.
318      */

319     public WorkSheet[] getAllWorkSheetsForEmployeeProjectPairFromDate1ToDate2(
320                     Employee employee, Project project, java.sql.Date JavaDoc date1, java.sql.Date JavaDoc 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     /**
358      * The getAllWorkSheetsForEmployeeProjectPair method performs
359      * a database query to return a <CODE>WorkSheet</CODE> objects
360      * representing the row in the <CODE>worksheet</CODE> table
361      * that matches the employee, project and between date1 and date2
362      * (including date1).
363      *
364      * @param employeeIDs java.util.ArrayList for which we need worksheets.
365      * @param projectIDs java.util.ArrayList for which we need worksheets.
366      * @param date1 begining date (including date1)
367      * @param date2 ending date
368      * @return
369      * array of worksheets. null if there isn't a worksheet associated
370      * the employeeIDs, projectIDs and between date1 and date2
371      * @exception ProjectManagementBusinessException
372      * if there is a problem retrieving worksheet information.
373      */

374     public WorkSheet[] getAllWorksheetsForEmployeeArrayAndProjectArrayBetweenDates(
375             java.util.ArrayList JavaDoc employeeIDs, java.util.ArrayList JavaDoc projectIDs, java.sql.Date JavaDoc date1, java.sql.Date JavaDoc date2)
376     throws ProjectManagementBusinessException {
377             
378             String JavaDoc employeeID="";
379             String JavaDoc projectID="";
380             java.util.Iterator JavaDoc it1=employeeIDs.iterator();
381             java.util.Iterator JavaDoc 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 JavaDoc 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