1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.department.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.department.Department;
26 import org.kuali.hr.time.service.base.TkServiceLocator;
27 import org.kuali.hr.time.util.TKContext;
28 import org.kuali.hr.time.util.TKUser;
29 import org.kuali.hr.time.util.TKUtils;
30 import org.kuali.rice.kns.lookup.HtmlData;
31 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
32 import org.kuali.rice.krad.bo.BusinessObject;
33 import org.kuali.rice.krad.util.KRADConstants;
34 import org.kuali.rice.krad.util.UrlFactory;
35
36 public class DepartmentLookupableHelper extends HrEffectiveDateActiveLookupableHelper {
37
38 private static final long serialVersionUID = 566277764259830850L;
39
40 @Override
41 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
42 List<HtmlData> customActionUrls = new ArrayList<HtmlData>();
43
44 List<HtmlData> defaultCustomActionUrls = super.getCustomActionUrls(businessObject, pkNames);
45
46 Department departmentObj = (Department) businessObject;
47 String hrDeptId = departmentObj.getHrDeptId();
48 Department dept = TkServiceLocator.getDepartmentService().getDepartment(departmentObj.getDept(), TKUtils.getCurrentDate());
49 String location = dept == null ? null : dept.getLocation();
50 String department = departmentObj.getDept();
51
52 boolean systemAdmin = TKUser.isSystemAdmin();
53 boolean locationAdmin = TKUser.getLocationAdminAreas().contains(location);
54 boolean departmentAdmin = TKUser.getDepartmentAdminAreas().contains(department);
55
56 for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){
57 if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) {
58 if (systemAdmin || locationAdmin || departmentAdmin) {
59 customActionUrls.add(defaultCustomActionUrl);
60 }
61 } else {
62 customActionUrls.add(defaultCustomActionUrl);
63 }
64 }
65
66 Properties params = new Properties();
67 params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
68 params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
69 params.put("hrDeptId", hrDeptId);
70 params.put("dept", department);
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 @SuppressWarnings({"unchecked"})
80 @Override
81 public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
82 String dept = fieldValues.get("dept");
83 String location = fieldValues.get("location");
84 String descr = fieldValues.get("description");
85 String active = fieldValues.get("active");
86 String showHist = fieldValues.get("history");
87
88 List<Department> departments = TkServiceLocator.getDepartmentService().getDepartments(dept, location, descr, active, showHist);
89
90 return departments;
91 }
92 }