1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.location.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.location.Location;
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.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 LocationLookupableHelper extends HrEffectiveDateActiveLookupableHelper {
37
38 private static final long serialVersionUID = 1285833127534968764L;
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 Location locationObj = (Location) businessObject;
47 String hrLocationId = locationObj.getHrLocationId();
48 String location = locationObj.getLocation();
49
50 boolean systemAdmin = TKUser.isSystemAdmin();
51 boolean locationAdmin = TKUser.getLocationAdminAreas().contains(location);
52
53 for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){
54 if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) {
55 if (systemAdmin || locationAdmin) {
56 customActionUrls.add(defaultCustomActionUrl);
57 }
58 } else {
59 customActionUrls.add(defaultCustomActionUrl);
60 }
61 }
62
63 Properties params = new Properties();
64 params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
65 params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
66 params.put("hrLocationId", hrLocationId);
67 AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
68 viewUrl.setDisplayText("view");
69 viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
70 customActionUrls.add(viewUrl);
71
72 return customActionUrls;
73 }
74
75 @SuppressWarnings({"unchecked"})
76 @Override
77 public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
78
79
80 String location = fieldValues.get("location");
81 String descr = fieldValues.get("description");
82 String active = fieldValues.get("active");
83 String showHist = fieldValues.get("history");
84
85 List<Location> locations = TkServiceLocator.getLocationService().searchLocations(location, descr, active, showHist);
86
87 return locations;
88 }
89 }