1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.principal.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.principal.PrincipalHRAttributes;
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 PrincipalHRAttributesLookupableHelper extends HrEffectiveDateActiveLookupableHelper {
37
38 private static final long serialVersionUID = 6198072858175242923L;
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 PrincipalHRAttributes principalHRAttributes = (PrincipalHRAttributes) businessObject;
47 String hrPrincipalAttributeId = principalHRAttributes.getHrPrincipalAttributeId();
48
49 boolean systemAdmin = TKUser.isSystemAdmin();
50 boolean locationAdmin = TKUser.isLocationAdmin();
51
52 for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){
53 if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) {
54 if (systemAdmin || locationAdmin) {
55 customActionUrls.add(defaultCustomActionUrl);
56 }
57 } else {
58 customActionUrls.add(defaultCustomActionUrl);
59 }
60 }
61
62 Properties params = new Properties();
63 params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
64 params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
65 params.put("hrPrincipalAttributeId", hrPrincipalAttributeId);
66 AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
67 viewUrl.setDisplayText("view");
68 viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
69 customActionUrls.add(viewUrl);
70
71 return customActionUrls;
72 }
73
74 @Override
75 public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
76 String principalId = fieldValues.get("principalId");
77 String leavePlan = fieldValues.get("leavePlan");
78 String fromEffdt = TKUtils.getFromDateString(fieldValues.get("effectiveDate"));
79 String toEffdt = TKUtils.getToDateString(fieldValues.get("effectiveDate"));
80 String active = fieldValues.get("active");
81 String showHist = fieldValues.get("history");
82
83 return TkServiceLocator.getPrincipalHRAttributeService().getPrincipalHrAtributes(principalId, leavePlan, TKUtils.formatDateString(fromEffdt),
84 TKUtils.formatDateString(toEffdt), active, showHist);
85 }
86 }