1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.job.service;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.Properties;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.kuali.hr.job.Job;
25 import org.kuali.hr.time.HrEffectiveDateActiveLookupableHelper;
26 import org.kuali.hr.time.service.base.TkServiceLocator;
27 import org.kuali.hr.time.util.TKContext;
28 import org.kuali.hr.time.util.TKUtils;
29 import org.kuali.rice.kns.document.authorization.BusinessObjectRestrictions;
30 import org.kuali.rice.kns.lookup.HtmlData;
31 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
32 import org.kuali.rice.kns.web.struts.form.LookupForm;
33 import org.kuali.rice.krad.bo.BusinessObject;
34 import org.kuali.rice.krad.util.KRADConstants;
35 import org.kuali.rice.krad.util.UrlFactory;
36
37 public class JobLookupableHelper extends HrEffectiveDateActiveLookupableHelper {
38
39 private static final long serialVersionUID = 3233495722838070429L;
40
41 @Override
42 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
43 List<HtmlData> customActionUrls = new ArrayList<HtmlData>();
44
45 List<HtmlData> defaultCustomActionUrls = super.getCustomActionUrls(businessObject, pkNames);
46
47 Job job = (Job) businessObject;
48 String hrJobId = job.getHrJobId();
49 String jobNumber = String.valueOf(job.getJobNumber());
50 String principalId = job.getPrincipalId();
51 String location = job.getLocation();
52 String department = job.getDept();
53
54 boolean systemAdmin = TKContext.getUser().isSystemAdmin();
55 boolean locationAdmin = TKContext.getUser().getLocationAdminAreas().contains(location);
56 boolean departmentAdmin = TKContext.getUser().getDepartmentAdminAreas().contains(department);
57
58 for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){
59 if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) {
60 if (systemAdmin || locationAdmin || departmentAdmin) {
61 customActionUrls.add(defaultCustomActionUrl);
62 }
63 } else {
64 customActionUrls.add(defaultCustomActionUrl);
65 }
66 }
67
68 Properties params = new Properties();
69 params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
70 params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
71 params.put("hrJobId", hrJobId);
72 params.put("jobNumber", jobNumber);
73 params.put("principalId", principalId);
74 AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
75 viewUrl.setDisplayText("view");
76 viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
77 customActionUrls.add(viewUrl);
78
79 return customActionUrls;
80 }
81
82 @SuppressWarnings({"unchecked"})
83 @Override
84 public List<? extends BusinessObject> getSearchResults(
85 Map<String, String> fieldValues) {
86
87 String principalId = fieldValues.get("principalId");
88 String firstName = fieldValues.get("firstName");
89 String lastName = fieldValues.get("lastName");
90 String jobNumber = fieldValues.get("jobNumber");
91 String dept = fieldValues.get("dept");
92 String positionNumber = fieldValues.get("positionNumber");
93 String hrPayType = fieldValues.get("hrPayType");
94 String fromEffdt = fieldValues.get("rangeLowerBoundKeyPrefix_effectiveDate");
95 String toEffdt = StringUtils.isNotBlank(fieldValues.get("effectiveDate")) ? fieldValues.get("effectiveDate").replace("<=", "") : "";
96 String active = fieldValues.get("active");
97 String showHist = fieldValues.get("history");
98
99 List<Job> jobs = TkServiceLocator.getJobService().getJobs(principalId, firstName, lastName, jobNumber,
100 dept, positionNumber, hrPayType,
101 TKUtils.formatDateString(fromEffdt), TKUtils.formatDateString(toEffdt),
102 active, showHist);
103
104 return jobs;
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138 }
139
140 @SuppressWarnings("rawtypes")
141 @Override
142 public HtmlData getReturnUrl(BusinessObject businessObject,
143 LookupForm lookupForm, List returnKeys,
144 BusinessObjectRestrictions businessObjectRestrictions) {
145 if (lookupForm.getFieldConversions().containsKey("effectiveDate")) {
146 lookupForm.getFieldConversions().remove("effectiveDate");
147 }
148 if (returnKeys.contains("effectiveDate")) {
149 returnKeys.remove("effectiveDate");
150 }
151 return super.getReturnUrl(businessObject, lookupForm, returnKeys,
152 businessObjectRestrictions);
153 }
154 }