1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.principal.service;
17
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Map;
22
23 import org.joda.time.LocalDate;
24 import org.kuali.kpme.core.KPMENamespace;
25 import org.kuali.kpme.core.department.Department;
26 import org.kuali.kpme.core.job.Job;
27 import org.kuali.kpme.core.permission.KPMEPermissionTemplate;
28 import org.kuali.kpme.core.principal.PrincipalHRAttributes;
29 import org.kuali.kpme.core.principal.dao.PrincipalHRAttributesDao;
30 import org.kuali.kpme.core.role.KPMERoleMemberAttribute;
31 import org.kuali.kpme.core.service.HrServiceLocator;
32 import org.kuali.rice.kim.api.KimConstants;
33 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
34
35 public class PrincipalHRAttributesServiceImpl implements PrincipalHRAttributesService {
36 private PrincipalHRAttributesDao principalHRAttributesDao;
37
38 public void setPrincipalHRAttributesDao(PrincipalHRAttributesDao principalHRAttributesDao) {
39 this.principalHRAttributesDao = principalHRAttributesDao;
40 }
41
42 public PrincipalHRAttributes getPrincipalCalendar(String principalId, LocalDate asOfDate){
43 PrincipalHRAttributes pc = this.principalHRAttributesDao.getPrincipalCalendar(principalId, asOfDate);
44 if(pc != null) {
45 pc.setCalendar(HrServiceLocator.getCalendarService().getCalendarByGroup(pc.getPayCalendar()));
46 pc.setLeaveCalObj(HrServiceLocator.getCalendarService().getCalendarByGroup(pc.getLeaveCalendar()));
47 }
48 return pc;
49 }
50
51 public List<PrincipalHRAttributes> getActiveEmployeesForPayCalendar(String payCalendarName, LocalDate asOfDate) {
52 return principalHRAttributesDao.getActiveEmployeesForPayCalendar(payCalendarName, asOfDate);
53 }
54
55 public List<PrincipalHRAttributes> getActiveEmployeesForLeaveCalendar(String leaveCalendarName, LocalDate asOfDate) {
56 return principalHRAttributesDao.getActiveEmployeesForLeaveCalendar(leaveCalendarName, asOfDate);
57 }
58
59 public List<String> getActiveEmployeesIdForLeaveCalendarAndIdList(String leaveCalendarName, List<String> pidList, LocalDate asOfDate) {
60 return principalHRAttributesDao.getActiveEmployeesIdForLeaveCalendarAndIdList(leaveCalendarName, pidList, asOfDate);
61 }
62
63 public List<String> getActiveEmployeesIdForTimeCalendarAndIdList(String timeCalendarName, List<String> pidList, LocalDate asOfDate) {
64 return principalHRAttributesDao.getActiveEmployeesIdForTimeCalendarAndIdList(timeCalendarName, pidList, asOfDate);
65 }
66
67
68
69
70
71 @Override
72 public List<PrincipalHRAttributes> getActiveEmployeesForLeavePlan(String leavePlan, LocalDate asOfDate) {
73 List<PrincipalHRAttributes> principals = principalHRAttributesDao.getActiveEmployeesForLeavePlan(leavePlan, asOfDate);
74
75 return principals;
76 }
77
78
79
80
81
82
83 @Override
84 public PrincipalHRAttributes getInactivePrincipalHRAttributes(String principalId, LocalDate asOfDate) {
85 return this.principalHRAttributesDao.getInactivePrincipalHRAttributes(principalId, asOfDate);
86 }
87
88 @Override
89 public PrincipalHRAttributes getPrincipalHRAttributes(String hrPrincipalAttributeId) {
90 return this.principalHRAttributesDao.getPrincipalHRAttributes(hrPrincipalAttributeId);
91 }
92
93 @Override
94 public List<PrincipalHRAttributes> getAllActivePrincipalHrAttributesForPrincipalId(String principalId, LocalDate asOfDate) {
95 return this.principalHRAttributesDao.getAllActivePrincipalHrAttributesForPrincipalId(principalId, asOfDate);
96 }
97 @Override
98 public PrincipalHRAttributes getMaxTimeStampPrincipalHRAttributes(String principalId) {
99 return principalHRAttributesDao.getMaxTimeStampPrincipalHRAttributes(principalId);
100 }
101
102 @Override
103 public List<PrincipalHRAttributes> getAllInActivePrincipalHrAttributesForPrincipalId(String principalId, LocalDate asOfDate) {
104 return this.principalHRAttributesDao.getAllInActivePrincipalHrAttributesForPrincipalId(principalId, asOfDate);
105 }
106 @Override
107 public List<PrincipalHRAttributes> getActivePrincipalHrAttributesForRange(String principalId, LocalDate startDate, LocalDate endDate) {
108 return this.principalHRAttributesDao.getActivePrincipalHrAttributesForRange(principalId, startDate, endDate);
109 }
110 @Override
111 public List<PrincipalHRAttributes> getInactivePrincipalHRAttributesForRange(String principalId, LocalDate startDate, LocalDate endDate) {
112 return this.principalHRAttributesDao.getInactivePrincipalHRAttributesForRange(principalId, startDate, endDate);
113 }
114 @Override
115 public List<PrincipalHRAttributes> getPrincipalHrAtributes(String userPrincipalId, String principalId,
116 String leavePlan, LocalDate fromEffdt, LocalDate toEffdt, String active, String showHistory) {
117 List<PrincipalHRAttributes> results = new ArrayList<PrincipalHRAttributes>();
118
119 List<PrincipalHRAttributes> principalHRAttributeObjs = principalHRAttributesDao.getPrincipalHrAtributes(principalId, leavePlan, fromEffdt, toEffdt, active, showHistory);
120
121
122 for (PrincipalHRAttributes principalHRAttributeObj : principalHRAttributeObjs) {
123 Job jobObj = HrServiceLocator.getJobService().getPrimaryJob(principalHRAttributeObj.getPrincipalId(), principalHRAttributeObj.getEffectiveLocalDate());
124
125 String department = jobObj != null ? jobObj.getDept() : null;
126 Department departmentObj = jobObj != null ? HrServiceLocator.getDepartmentService().getDepartmentWithoutRoles(department, jobObj.getEffectiveLocalDate()) : null;
127 String location = departmentObj != null ? departmentObj.getLocation() : null;
128
129 Map<String, String> roleQualification = new HashMap<String, String>();
130 roleQualification.put(KimConstants.AttributeConstants.PRINCIPAL_ID, principalHRAttributeObj.getPrincipalId());
131 roleQualification.put(KPMERoleMemberAttribute.DEPARTMENT.getRoleMemberAttributeName(), department);
132 roleQualification.put(KPMERoleMemberAttribute.LOCATION.getRoleMemberAttributeName(), location);
133
134 if (!KimApiServiceLocator.getPermissionService().isPermissionDefinedByTemplate(KPMENamespace.KPME_WKFLW.getNamespaceCode(),
135 KPMEPermissionTemplate.VIEW_KPME_RECORD.getPermissionTemplateName(), new HashMap<String, String>())
136 || KimApiServiceLocator.getPermissionService().isAuthorizedByTemplate(userPrincipalId, KPMENamespace.KPME_WKFLW.getNamespaceCode(),
137 KPMEPermissionTemplate.VIEW_KPME_RECORD.getPermissionTemplateName(), new HashMap<String, String>(), roleQualification)) {
138 results.add(principalHRAttributeObj);
139 }
140 }
141
142 return results;
143 }
144
145 @Override
146 public List<String> getUniqueLeaveCalendars(List<String> principalIds) {
147 return this.principalHRAttributesDao.getUniqueLeaveCalendars(principalIds);
148 }
149
150 @Override
151 public List<String> getUniquePayCalendars(List<String> principalIds) {
152 return this.principalHRAttributesDao.getUniquePayCalendars(principalIds);
153 }
154
155 }