1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.lm.earncodesec.service;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.hr.lm.earncodesec.EarnCodeSecurity;
20 import org.kuali.hr.time.HrEffectiveDateActiveLookupableHelper;
21 import org.kuali.hr.time.service.base.TkServiceLocator;
22 import org.kuali.hr.time.util.TKContext;
23 import org.kuali.hr.time.util.TKUser;
24 import org.kuali.hr.time.util.TKUtils;
25 import org.kuali.rice.kns.lookup.HtmlData;
26 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
27 import org.kuali.rice.krad.bo.BusinessObject;
28 import org.kuali.rice.krad.util.KRADConstants;
29 import org.kuali.rice.krad.util.UrlFactory;
30
31 import java.util.ArrayList;
32 import java.util.List;
33 import java.util.Map;
34 import java.util.Properties;
35
36 public class EarnCodeSecurityLookupableHelper extends HrEffectiveDateActiveLookupableHelper {
37
38 private static final long serialVersionUID = 696878785547265569L;
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 EarnCodeSecurity earnCodeSecurity = (EarnCodeSecurity) businessObject;
47 String hrEarnCodeSecurityId = earnCodeSecurity.getHrEarnCodeSecurityId();
48 String location = earnCodeSecurity.getLocation();
49 String department = earnCodeSecurity.getDept();
50
51 boolean systemAdmin = TKUser.isSystemAdmin();
52 boolean locationAdmin = TKUser.getLocationAdminAreas().contains(location);
53 boolean departmentAdmin = TKUser.getDepartmentAdminAreas().contains(department);
54
55 for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){
56 if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) {
57 if (systemAdmin || locationAdmin || departmentAdmin) {
58 customActionUrls.add(defaultCustomActionUrl);
59 }
60 } else {
61 customActionUrls.add(defaultCustomActionUrl);
62 }
63 }
64
65 Properties params = new Properties();
66 params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
67 params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
68 params.put("hrEarnCodeSecurityId", hrEarnCodeSecurityId);
69 AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
70 viewUrl.setDisplayText("view");
71 viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
72 customActionUrls.add(viewUrl);
73
74 return customActionUrls;
75 }
76
77 @Override
78 public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
79 String salGroup = fieldValues.get("hrSalGroup");
80 String dept = fieldValues.get("dept");
81 String earnCode = fieldValues.get("earnCode");
82 String location = fieldValues.get("location");
83 String fromEffdt = TKUtils.getFromDateString(fieldValues.get("effectiveDate"));
84 String toEffdt = TKUtils.getToDateString(fieldValues.get("effectiveDate"));
85 String active = fieldValues.get("active");
86 String showHist = fieldValues.get("history");
87
88 return TkServiceLocator.getEarnCodeSecurityService().searchEarnCodeSecurities(dept, salGroup, earnCode, location, TKUtils.formatDateString(fromEffdt),
89 TKUtils.formatDateString(toEffdt), active, showHist);
90 }
91
92 }