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