View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.hr.time.missedpunch.dao;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.ojb.broker.query.Criteria;
22  import org.apache.ojb.broker.query.Query;
23  import org.apache.ojb.broker.query.QueryFactory;
24  import org.kuali.hr.time.batch.BatchJobEntry;
25  import org.kuali.hr.time.calendar.CalendarEntries;
26  import org.kuali.hr.time.missedpunch.MissedPunchDocument;
27  import org.kuali.hr.time.service.base.TkServiceLocator;
28  import org.kuali.hr.time.util.TkConstants;
29  import org.kuali.hr.time.workflow.TimesheetDocumentHeader;
30  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
31  
32  public class MissedPunchDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements MissedPunchDao {
33  
34      @Override
35      public MissedPunchDocument getMissedPunchByRouteHeader(String headerId) {
36      	MissedPunchDocument mp = null;
37  
38          Criteria root = new Criteria();
39          root.addEqualTo("documentNumber", headerId);
40          Query query = QueryFactory.newQuery(MissedPunchDocument.class, root);
41          mp = (MissedPunchDocument)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
42  
43          return mp;
44      }
45      
46      @Override
47      public MissedPunchDocument getMissedPunchByClockLogId(String clockLogId) {
48      	MissedPunchDocument mp = null;
49  
50          Criteria root = new Criteria();
51          root.addEqualTo("tkClockLogId", clockLogId);
52          Query query = QueryFactory.newQuery(MissedPunchDocument.class, root);
53          mp = (MissedPunchDocument)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
54  
55          return mp;
56      }
57      
58      @Override
59      public List<MissedPunchDocument> getMissedPunchDocsByBatchJobEntry(BatchJobEntry batchJobEntry) {
60      	List<MissedPunchDocument> results = new ArrayList<MissedPunchDocument>();
61  		Criteria root = new Criteria();
62  		
63  		root.addEqualTo("principalId", batchJobEntry.getPrincipalId());
64  	    root.addEqualTo("documentStatus", TkConstants.ROUTE_STATUS.ENROUTE);
65  	    Query query = QueryFactory.newQuery(MissedPunchDocument.class, root);
66  	    List<MissedPunchDocument> aList = (List<MissedPunchDocument>) this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
67  	    
68  	    String pcdId = batchJobEntry.getHrPyCalendarEntryId();
69  	    CalendarEntries pcd = TkServiceLocator.getCalendarEntriesService().getCalendarEntries(pcdId.toString());
70  	    if(pcd != null) {
71  		    for(MissedPunchDocument aDoc : aList) {
72  		    	String tscId = aDoc.getTimesheetDocumentId();
73  		    	TimesheetDocumentHeader tsdh = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeader(tscId);
74  		    	if(tsdh != null) {
75  		    		if(tsdh.getPayBeginDate().equals(pcd.getBeginPeriodDate()) && tsdh.getPayEndDate().equals(pcd.getEndPeriodDate())) {
76  		    			results.add(aDoc);
77  		    		}
78  		    	}
79  		    }
80  	    }
81  	    
82      	return results;
83      }
84      
85      @Override
86      public List<MissedPunchDocument> getMissedPunchDocsByTimesheetDocumentId(String timesheetDocumentId) {
87      	List<MissedPunchDocument> missedPunchDocuments = new ArrayList<MissedPunchDocument>();
88  
89          Criteria root = new Criteria();
90          root.addEqualTo("timesheetDocumentId", timesheetDocumentId);
91          Query query = QueryFactory.newQuery(MissedPunchDocument.class, root);
92          missedPunchDocuments.addAll(this.getPersistenceBrokerTemplate().getCollectionByQuery(query));
93  
94          return missedPunchDocuments;
95      }
96      
97  }