1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.calendar.service;
17
18 import java.sql.Time;
19 import java.util.Date;
20 import java.util.List;
21
22 import org.kuali.hr.job.Job;
23 import org.kuali.hr.time.calendar.Calendar;
24 import org.kuali.hr.time.calendar.CalendarEntries;
25 import org.kuali.hr.time.calendar.dao.CalendarDao;
26 import org.kuali.hr.time.paytype.PayType;
27 import org.kuali.hr.time.principal.PrincipalHRAttributes;
28 import org.kuali.hr.time.service.base.TkServiceLocator;
29
30 public class CalendarServiceImpl implements CalendarService {
31
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 CalendarEntries getCalendarDatesByPayEndDate(String principalId, Date payEndDate, String calendarType) {
50 CalendarEntries pcd = null;
51
52 Calendar calendar = getCalendar(principalId, payEndDate, false);
53 pcd = TkServiceLocator.getCalendarEntriesService().getCalendarEntriesByIdAndPeriodEndDate(calendar.getHrCalendarId(), payEndDate);
54 pcd.setCalendarObj(calendar);
55
56 return pcd;
57 }
58
59 @Override
60 public CalendarEntries getCurrentCalendarDates(String principalId, Date currentDate) {
61 CalendarEntries pcd = null;
62 Calendar calendar = getCalendarByPrincipalIdAndDate(principalId, currentDate);
63 if(calendar != null) {
64 pcd = TkServiceLocator.getCalendarEntriesService().getCurrentCalendarEntriesByCalendarId(calendar.getHrCalendarId(), currentDate);
65 if(pcd != null) {
66 pcd.setCalendarObj(calendar);
67 }
68 }
69 return pcd;
70 }
71
72
73
74
75
76
77
78 private Calendar getCalendar(String principalId, Date date, boolean findLeaveCal) {
79 Calendar pcal = null;
80
81 List<Job> currentJobs = TkServiceLocator.getJobService().getJobs(principalId, date);
82 if(currentJobs.size() < 1){
83 throw new RuntimeException("No jobs found for principal id "+principalId);
84 }
85 Job job = currentJobs.get(0);
86
87 if (principalId == null || job == null) {
88 throw new RuntimeException("Null parameters passed to getPayEndDate");
89 } else {
90 PayType payType = job.getPayTypeObj();
91 if (payType == null)
92 throw new RuntimeException("Null pay type on Job in getPayEndDate");
93 PrincipalHRAttributes principalCalendar = TkServiceLocator.getPrincipalHRAttributeService().getPrincipalCalendar(principalId, date);
94 if(principalCalendar == null){
95 throw new RuntimeException("Null principal calendar for principalid "+principalId);
96 }
97 pcal = principalCalendar.getCalendar();
98 if(pcal == null){
99 throw new RuntimeException("Null principal calendar for principalId " + principalId);
100 }
101 }
102
103 return pcal;
104 }
105
106 @Override
107 public CalendarEntries getPreviousCalendarEntry(String tkCalendarId, Date beginDateCurrentCalendar){
108 return calendarDao.getPreviousCalendarEntry(tkCalendarId, beginDateCurrentCalendar);
109 }
110
111 @Override
112 public Calendar getCalendarByPrincipalIdAndDate(String principalId, Date asOfDate) {
113 Calendar pcal = null;
114 List<Job> currentJobs = TkServiceLocator.getJobService().getJobs(principalId, asOfDate);
115 if(currentJobs.size() < 1){
116 return pcal;
117 }
118 Job job = currentJobs.get(0);
119 if (principalId == null || job == null) {
120 return pcal;
121 } else {
122 PayType payType = job.getPayTypeObj();
123 if (payType == null) {
124 throw new RuntimeException("No paytype setup for "+principalId + " job number: "+job.getJobNumber());
125 }
126 PrincipalHRAttributes principalCalendar = TkServiceLocator.getPrincipalHRAttributeService().getPrincipalCalendar(principalId, asOfDate);
127 if(principalCalendar == null){
128 throw new RuntimeException("No principal hr attribute setup for "+principalId);
129 }
130 pcal = principalCalendar.getCalendar();
131 if (pcal == null){
132 return pcal;
133 }
134 }
135
136 return pcal;
137 }
138
139 @Override
140 public List<Calendar> getCalendars(String calendarName, String flsaBeginDay, String flsaBeginTime) {
141 return calendarDao.getCalendars(calendarName, flsaBeginDay, flsaBeginTime);
142 }
143
144 }