001    /**
002     * Copyright 2004-2012 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.hr.time.missedpunch.dao;
017    
018    import java.util.ArrayList;
019    import java.util.List;
020    
021    import org.apache.ojb.broker.query.Criteria;
022    import org.apache.ojb.broker.query.Query;
023    import org.apache.ojb.broker.query.QueryFactory;
024    import org.kuali.hr.time.batch.BatchJobEntry;
025    import org.kuali.hr.time.calendar.CalendarEntries;
026    import org.kuali.hr.time.missedpunch.MissedPunchDocument;
027    import org.kuali.hr.time.service.base.TkServiceLocator;
028    import org.kuali.hr.time.util.TkConstants;
029    import org.kuali.hr.time.workflow.TimesheetDocumentHeader;
030    import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
031    
032    public class MissedPunchDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements MissedPunchDao {
033    
034        @Override
035        public MissedPunchDocument getMissedPunchByRouteHeader(String headerId) {
036            MissedPunchDocument mp = null;
037    
038            Criteria root = new Criteria();
039            root.addEqualTo("documentNumber", headerId);
040            Query query = QueryFactory.newQuery(MissedPunchDocument.class, root);
041            mp = (MissedPunchDocument)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
042    
043            return mp;
044        }
045        
046        @Override
047        public MissedPunchDocument getMissedPunchByClockLogId(String clockLogId) {
048            MissedPunchDocument mp = null;
049    
050            Criteria root = new Criteria();
051            root.addEqualTo("tkClockLogId", clockLogId);
052            Query query = QueryFactory.newQuery(MissedPunchDocument.class, root);
053            mp = (MissedPunchDocument)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
054    
055            return mp;
056        }
057        
058        @Override
059        public List<MissedPunchDocument> getMissedPunchDocsByBatchJobEntry(BatchJobEntry batchJobEntry) {
060            List<MissedPunchDocument> results = new ArrayList<MissedPunchDocument>();
061                    Criteria root = new Criteria();
062                    
063                    root.addEqualTo("principalId", batchJobEntry.getPrincipalId());
064                root.addEqualTo("documentStatus", TkConstants.ROUTE_STATUS.ENROUTE);
065                Query query = QueryFactory.newQuery(MissedPunchDocument.class, root);
066                List<MissedPunchDocument> aList = (List<MissedPunchDocument>) this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
067                
068                String pcdId = batchJobEntry.getHrPyCalendarEntryId();
069                CalendarEntries pcd = TkServiceLocator.getCalendarEntriesService().getCalendarEntries(pcdId.toString());
070                if(pcd != null) {
071                        for(MissedPunchDocument aDoc : aList) {
072                            String tscId = aDoc.getTimesheetDocumentId();
073                            TimesheetDocumentHeader tsdh = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeader(tscId);
074                            if(tsdh != null) {
075                                    if(tsdh.getPayBeginDate().equals(pcd.getBeginPeriodDate()) && tsdh.getPayEndDate().equals(pcd.getEndPeriodDate())) {
076                                            results.add(aDoc);
077                                    }
078                            }
079                        }
080                }
081                
082            return results;
083        }
084        
085    }