1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
69 }
70 if(!findLeaveCal) {
71 pcal = principalCalendar.getCalendar();
72 if (pcal == null){
73
74
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
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
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
118
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 }