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.Properties;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.hr.time.HrEffectiveDateActiveLookupableHelper;
24 import org.kuali.hr.time.department.Department;
25 import org.kuali.hr.time.service.base.TkServiceLocator;
26 import org.kuali.hr.time.util.TKContext;
27 import org.kuali.hr.time.util.TKUtils;
28 import org.kuali.rice.kns.lookup.HtmlData;
29 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
30 import org.kuali.rice.krad.bo.BusinessObject;
31 import org.kuali.rice.krad.util.KRADConstants;
32 import org.kuali.rice.krad.util.UrlFactory;
33
34 public class DepartmentLookupableHelper extends HrEffectiveDateActiveLookupableHelper {
35
36 private static final long serialVersionUID = 566277764259830850L;
37
38 @Override
39 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
40 List<HtmlData> customActionUrls = new ArrayList<HtmlData>();
41
42 List<HtmlData> defaultCustomActionUrls = super.getCustomActionUrls(businessObject, pkNames);
43
44 Department departmentObj = (Department) businessObject;
45 String hrDeptId = departmentObj.getHrDeptId();
46 Department dept = TkServiceLocator.getDepartmentService().getDepartment(departmentObj.getDept(), TKUtils.getCurrentDate());
47 String location = dept == null ? null : dept.getLocation();
48 String department = departmentObj.getDept();
49
50 boolean systemAdmin = TKContext.getUser().isSystemAdmin();
51 boolean locationAdmin = TKContext.getUser().getLocationAdminAreas().contains(location);
52 boolean departmentAdmin = TKContext.getUser().getDepartmentAdminAreas().contains(department);
53
54 for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){
55 if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) {
56 if (systemAdmin || locationAdmin || departmentAdmin) {
57 customActionUrls.add(defaultCustomActionUrl);
58 }
59 } else {
60 customActionUrls.add(defaultCustomActionUrl);
61 }
62 }
63
64 Properties params = new Properties();
65 params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
66 params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
67 params.put("hrDeptId", hrDeptId);
68 AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
69 viewUrl.setDisplayText("view");
70 viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
71 customActionUrls.add(viewUrl);
72
73 return customActionUrls;
74 }
75
76 }