View Javadoc
1   /**
2    * Copyright 2004-2015 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.kpme.core.calendar.service;
17  
18  import java.util.List;
19  
20  import org.apache.log4j.Logger;
21  import org.joda.time.LocalDate;
22  import org.kuali.kpme.core.calendar.Calendar;
23  import org.kuali.kpme.core.calendar.dao.CalendarDao;
24  import org.kuali.kpme.core.job.Job;
25  import org.kuali.kpme.core.paytype.PayType;
26  import org.kuali.kpme.core.principal.PrincipalHRAttributes;
27  import org.kuali.kpme.core.service.HrServiceLocator;
28  
29  public class CalendarServiceImpl implements CalendarService {
30  
31  	private static final Logger LOG = Logger.getLogger(CalendarServiceImpl.class);
32  	private CalendarDao calendarDao;
33  
34  	public void setCalendarDao(CalendarDao calendarDao) {
35  		this.calendarDao = calendarDao;
36  	}
37  
38  	@Override
39  	public Calendar getCalendar(String hrCalendarId) {
40  		return calendarDao.getCalendar(hrCalendarId);
41  	}
42  
43  	@Override
44  	public Calendar getCalendarByGroup(String calendarName) {
45  		return calendarDao.getCalendarByGroup(calendarName);
46  	}
47  
48  	@Override
49      public Calendar getCalendarByPrincipalIdAndDate(String principalId, LocalDate beginDate, LocalDate endDate, boolean findLeaveCal) {
50          Calendar pcal = null;
51          List<Job> currentJobs = HrServiceLocator.getJobService().getJobs(principalId, endDate);
52          if(currentJobs.size() < 1){
53              return pcal;
54          }
55          Job job = currentJobs.get(0);
56          if (principalId == null || job == null) {
57              return pcal;
58          } else {
59              PayType payType = job.getPayTypeObj();
60              if (payType == null)  {
61  //                throw new RuntimeException("No paytype setup for "+principalId + " job number: "+job.getJobNumber());
62              	LOG.warn("No paytype setup for "+principalId + " job number: "+job.getJobNumber());
63              }
64  
65              PrincipalHRAttributes principalCalendar = HrServiceLocator.getPrincipalHRAttributeService().getPrincipalCalendar(principalId, beginDate);
66              if(principalCalendar == null){
67              	return null;
68                  //throw new RuntimeException("No principal hr attribute setup for "+principalId);
69              }
70              if(!findLeaveCal) {
71                  pcal = principalCalendar.getCalendar();
72                  if (pcal == null){
73                  	//shouldn't we just be returning null?
74                  	//which code expects a non-null value being returned?
75                      pcal = principalCalendar.getLeaveCalObj();
76                      if(pcal == null){
77                          return pcal;
78                      }
79                  }
80              } else {
81                  pcal = principalCalendar.getLeaveCalObj();
82                  if(pcal == null){
83                      return pcal;
84                  }
85              }
86          }
87  
88          return pcal;
89      }
90  
91  	@Override
92  	public Calendar getCalendarByPrincipalIdAndDate(String principalId, LocalDate asOfDate, boolean findLeaveCal) {
93  		Calendar pcal = null;
94          List<Job> currentJobs = HrServiceLocator.getJobService().getJobs(principalId, asOfDate);
95          if(currentJobs.size() < 1){
96             return pcal;
97          }
98          Job job = currentJobs.get(0);
99          if (principalId == null || job == null) {
100             return pcal;
101         } else {
102             PayType payType = job.getPayTypeObj();
103             if (payType == null)  {
104 //                throw new RuntimeException("No paytype setup for "+principalId + " job number: "+job.getJobNumber());
105             	LOG.warn("No paytype setup for "+principalId + " job number: "+job.getJobNumber());
106             }
107 
108             PrincipalHRAttributes principalCalendar = HrServiceLocator.getPrincipalHRAttributeService().getPrincipalCalendar(principalId, asOfDate);
109             if(principalCalendar == null){
110 //                throw new RuntimeException("No principal hr attribute setup for "+principalId);
111             	LOG.warn("No principal hr attribute setup for "+principalId);
112             	return null;
113             }
114             if(!findLeaveCal) {
115             	pcal = principalCalendar.getCalendar();
116             	if (pcal == null){
117                 	//shouldn't we just be returning null?
118                 	//which code expects a non-null value being returned?
119             		pcal = principalCalendar.getLeaveCalObj();
120             		if(pcal == null){
121             			return pcal;
122             		}
123             	}
124             } else {
125         		pcal = principalCalendar.getLeaveCalObj();
126         		if(pcal == null){
127         			return pcal;
128         		}
129             }
130         }
131 
132         return pcal;
133 	}
134 	
135 	@Override
136     public List<Calendar> getCalendars(String calendarName, String calendarTypes, String flsaBeginDay, String flsaBeginTime) {
137         return  calendarDao.getCalendars(calendarName, calendarTypes, flsaBeginDay, flsaBeginTime);
138     }
139 	
140 	@Override
141 	public Calendar getCalendarByName(String calendarName){
142 		return calendarDao.getCalendarByName(calendarName);
143 	}
144 
145 }