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