1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.assignment.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.time.HrEffectiveDateActiveLookupableHelper;
25 import org.kuali.hr.time.assignment.Assignment;
26 import org.kuali.hr.time.department.Department;
27 import org.kuali.hr.time.service.base.TkServiceLocator;
28 import org.kuali.hr.time.util.TKContext;
29 import org.kuali.hr.time.util.TKUser;
30 import org.kuali.hr.time.util.TKUtils;
31 import org.kuali.rice.kns.lookup.HtmlData;
32 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
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 AssignmentLookupableHelper extends HrEffectiveDateActiveLookupableHelper {
38
39 private static final long serialVersionUID = 774015772672806415L;
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 Assignment assignment = (Assignment) businessObject;
48 String tkAssignmentId = assignment.getTkAssignmentId();
49 Department dept = TkServiceLocator.getDepartmentService().getDepartment(assignment.getDept(), TKUtils.getCurrentDate());
50 String location = dept == null ? null : dept.getLocation();
51 String department = assignment.getDept();
52
53 boolean systemAdmin = TKUser.isSystemAdmin();
54 boolean locationAdmin = TKUser.getLocationAdminAreas().contains(location);
55 boolean departmentAdmin = TKUser.getDepartmentAdminAreas().contains(department);
56
57 for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){
58 if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) {
59 if (systemAdmin || locationAdmin || departmentAdmin) {
60 customActionUrls.add(defaultCustomActionUrl);
61 }
62 } else {
63 customActionUrls.add(defaultCustomActionUrl);
64 }
65 }
66
67 Properties params = new Properties();
68 params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
69 params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
70 params.put("tkAssignmentId", tkAssignmentId);
71 AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
72 viewUrl.setDisplayText("view");
73 viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
74 customActionUrls.add(viewUrl);
75
76 return customActionUrls;
77 }
78
79 @Override
80 public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
81 String fromEffdt = TKUtils.getFromDateString(fieldValues.get("effectiveDate"));
82 String toEffdt = TKUtils.getToDateString(fieldValues.get("effectiveDate"));
83 String principalId = fieldValues.get("principalId");
84 String jobNumber = fieldValues.get("jobNumber");
85 String dept = fieldValues.get("dept");
86 String workArea = fieldValues.get("workArea");
87 String active = fieldValues.get("active");
88 String showHist = fieldValues.get("history");
89
90 return TkServiceLocator.getAssignmentService().searchAssignments(TKUtils.formatDateString(fromEffdt), TKUtils.formatDateString(toEffdt), principalId,
91 jobNumber, dept, workArea, active, showHist);
92 }
93
94 }