1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.location.web;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.kpme.core.api.location.Location;
20 import org.kuali.kpme.core.location.LocationBo;
21 import org.kuali.kpme.core.lookup.KPMELookupableHelperServiceImpl;
22 import org.kuali.kpme.core.service.HrServiceLocator;
23 import org.kuali.rice.core.api.mo.ModelObjectUtils;
24 import org.kuali.rice.kns.lookup.HtmlData;
25 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
26 import org.kuali.rice.krad.bo.BusinessObject;
27 import org.kuali.rice.krad.util.GlobalVariables;
28 import org.kuali.rice.krad.util.KRADConstants;
29 import org.kuali.rice.krad.util.UrlFactory;
30
31 import java.util.List;
32 import java.util.Map;
33 import java.util.Properties;
34
35 @SuppressWarnings("deprecation")
36 public class LocationLookupableHelper extends KPMELookupableHelperServiceImpl {
37
38 private static final long serialVersionUID = 1285833127534968764L;
39 private static final ModelObjectUtils.Transformer<Location, LocationBo> toLocationBo =
40 new ModelObjectUtils.Transformer<Location, LocationBo>() {
41 public LocationBo transform(Location input) {
42 return LocationBo.from(input);
43 };
44 };
45 @Override
46 @SuppressWarnings("rawtypes")
47 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
48 List<HtmlData> customActionUrls = super.getCustomActionUrls(businessObject, pkNames);
49
50 LocationBo locationObj = (LocationBo) businessObject;
51 String hrLocationId = locationObj.getHrLocationId();
52 Properties params = new Properties();
53 params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
54 params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
55 params.put("hrLocationId", hrLocationId);
56 AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
57 viewUrl.setDisplayText("view");
58 viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
59 customActionUrls.add(viewUrl);
60
61 return customActionUrls;
62 }
63
64 @Override
65 public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
66 String location = fieldValues.get("location");
67 String descr = fieldValues.get("description");
68 String active = fieldValues.get("active");
69 String showHist = fieldValues.get("history");
70
71 if (StringUtils.contains(location, "*")) {
72 location = "";
73 }
74
75 return ModelObjectUtils.transform(HrServiceLocator.getLocationService().searchLocations(GlobalVariables.getUserSession().getPrincipalId(), location, descr, active, showHist), toLocationBo);
76 }
77
78 @Override
79 protected void validateSearchParameterWildcardAndOperators(
80 String attributeName, String attributeValue) {
81 if (!StringUtils.equals(attributeValue, "*")) {
82 super.validateSearchParameterWildcardAndOperators(attributeName,
83 attributeValue);
84 }
85 }
86
87 }