1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.leave.payout.web;
17
18 import java.util.HashMap;
19 import java.util.Iterator;
20 import java.util.List;
21 import java.util.Map;
22 import java.util.Properties;
23
24 import org.joda.time.DateTime;
25 import org.joda.time.LocalDate;
26 import org.kuali.kpme.core.KPMENamespace;
27 import org.kuali.kpme.core.assignment.Assignment;
28 import org.kuali.kpme.core.department.Department;
29 import org.kuali.kpme.core.job.Job;
30 import org.kuali.kpme.core.lookup.KPMELookupableHelper;
31 import org.kuali.kpme.core.permission.KPMEPermissionTemplate;
32 import org.kuali.kpme.core.role.KPMERole;
33 import org.kuali.kpme.core.role.KPMERoleMemberAttribute;
34 import org.kuali.kpme.core.service.HrServiceLocator;
35 import org.kuali.kpme.core.util.HrContext;
36 import org.kuali.kpme.core.util.TKUtils;
37 import org.kuali.kpme.tklm.leave.payout.LeavePayout;
38 import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
39 import org.kuali.rice.kim.api.KimConstants;
40 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
41 import org.kuali.rice.kns.lookup.HtmlData;
42 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
43 import org.kuali.rice.krad.bo.BusinessObject;
44 import org.kuali.rice.krad.util.GlobalVariables;
45 import org.kuali.rice.krad.util.KRADConstants;
46 import org.kuali.rice.krad.util.UrlFactory;
47
48 @SuppressWarnings("deprecation")
49 public class LeavePayoutLookupableHelper extends KPMELookupableHelper {
50
51 private static final long serialVersionUID = -2654300078605742618L;
52
53 @Override
54 @SuppressWarnings("rawtypes")
55 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
56 List<HtmlData> customActionUrls = super.getCustomActionUrls(businessObject, pkNames);
57
58 LeavePayout lp = (LeavePayout) businessObject;
59 String lmLeavePayoutId = lp.getLmLeavePayoutId();
60
61 Properties params = new Properties();
62 params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
63 params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
64 params.put("lmLeavePayoutId", lmLeavePayoutId);
65 AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
66 viewUrl.setDisplayText("view");
67 viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
68 customActionUrls.add(viewUrl);
69
70 return customActionUrls;
71 }
72
73 @Override
74 public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
75 String principalId = fieldValues.get("principalId");
76 String fromAccrualCategory = fieldValues.get("fromAccrualCategory");
77 String payoutAmount = fieldValues.get("payoutAmount");
78 String earnCode = fieldValues.get("earnCode");
79 String forfeitedAmount = fieldValues.get("forfeitedAmount");
80 String fromEffdt = TKUtils.getFromDateString(fieldValues.get("effectiveDate"));
81 String toEffdt = TKUtils.getToDateString(fieldValues.get("effectiveDate"));
82
83 List<LeavePayout> payouts = LmServiceLocator.getLeavePayoutService().getLeavePayouts(principalId, fromAccrualCategory, payoutAmount, earnCode, forfeitedAmount,
84 TKUtils.formatDateString(fromEffdt), TKUtils.formatDateString(toEffdt));
85 payouts = filterByPrincipalId(payouts);
86
87 return payouts;
88 }
89
90 private List<LeavePayout> filterByPrincipalId(
91 List<LeavePayout> payouts) {
92 if(!payouts.isEmpty()) {
93 Iterator<? extends BusinessObject> iter = payouts.iterator();
94 while(iter.hasNext()) {
95 LeavePayout payout = (LeavePayout) iter.next();
96 LocalDate effectiveLocalDate = payout.getEffectiveLocalDate();
97 DateTime effectiveDate = effectiveLocalDate.toDateTimeAtStartOfDay();
98 String principalId = payout.getPrincipalId();
99 List<Job> principalsJobs = HrServiceLocator.getJobService().getActiveLeaveJobs(principalId, effectiveLocalDate);
100 String userPrincipalId = HrContext.getPrincipalId();
101 boolean canView = false;
102
103
104 for(Job job : principalsJobs) {
105
106 if(job.isEligibleForLeave()) {
107
108 String department = job != null ? job.getDept() : null;
109 Department departmentObj = job != null ? HrServiceLocator.getDepartmentService().getDepartmentWithoutRoles(department, effectiveLocalDate) : null;
110 String location = departmentObj != null ? departmentObj.getLocation() : null;
111 if (LmServiceLocator.getLMPermissionService().isAuthorizedInDepartment(userPrincipalId, "View Leave Payout", department, effectiveDate)
112 || LmServiceLocator.getLMPermissionService().isAuthorizedInLocation(userPrincipalId, "View Leave Payout", location, effectiveDate)) {
113 canView = true;
114 break;
115 }
116 else {
117
118 List<Assignment> assignments = HrServiceLocator.getAssignmentService().getActiveAssignmentsForJob(principalId, job.getJobNumber(), effectiveLocalDate);
119 for(Assignment assignment : assignments) {
120 if(HrServiceLocator.getKPMERoleService().principalHasRoleInWorkArea(userPrincipalId, KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.APPROVER.getRoleName(), assignment.getWorkArea(), new DateTime(effectiveDate))
121 || HrServiceLocator.getKPMERoleService().principalHasRoleInWorkArea(userPrincipalId, KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.APPROVER_DELEGATE.getRoleName(), assignment.getWorkArea(), new DateTime(effectiveDate))
122 || HrServiceLocator.getKPMERoleService().principalHasRoleInWorkArea(userPrincipalId, KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.PAYROLL_PROCESSOR.getRoleName(), assignment.getWorkArea(), new DateTime(effectiveDate))
123 || HrServiceLocator.getKPMERoleService().principalHasRoleInWorkArea(userPrincipalId, KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.PAYROLL_PROCESSOR_DELEGATE.getRoleName(), assignment.getWorkArea(), new DateTime(effectiveDate))) {
124 canView = true;
125 break;
126 }
127 }
128 }
129 }
130 }
131 if(!canView) {
132 iter.remove();
133 }
134 }
135
136
137 }
138
139 return payouts;
140 }
141
142 }