1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.timecollection.rule.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.authorization.DepartmentalRule;
25 import org.kuali.hr.time.authorization.DepartmentalRuleAuthorizer;
26 import org.kuali.hr.time.authorization.TkAuthorizedLookupableHelperBase;
27 import org.kuali.hr.time.collection.rule.TimeCollectionRule;
28 import org.kuali.hr.time.department.Department;
29 import org.kuali.hr.time.service.base.TkServiceLocator;
30 import org.kuali.hr.time.util.TKContext;
31 import org.kuali.hr.time.util.TKUser;
32 import org.kuali.hr.time.util.TKUtils;
33 import org.kuali.rice.kns.lookup.HtmlData;
34 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
35 import org.kuali.rice.krad.bo.BusinessObject;
36 import org.kuali.rice.krad.util.KRADConstants;
37 import org.kuali.rice.krad.util.UrlFactory;
38
39 public class TimeCollectionRuleLookupableHelper extends TkAuthorizedLookupableHelperBase {
40
41 private static final long serialVersionUID = -1690980961895784168L;
42
43 @Override
44
45
46
47
48 public boolean shouldShowBusinessObject(BusinessObject bo) {
49 return (bo instanceof DepartmentalRule) && DepartmentalRuleAuthorizer.hasAccessToRead((DepartmentalRule)bo);
50 }
51
52 @Override
53 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
54 List<HtmlData> customActionUrls = new ArrayList<HtmlData>();
55
56 List<HtmlData> defaultCustomActionUrls = super.getCustomActionUrls(businessObject, pkNames);
57
58 TimeCollectionRule timeCollectionRule = (TimeCollectionRule) businessObject;
59 String tkTimeCollectionRuleId = timeCollectionRule.getTkTimeCollectionRuleId();
60 String department = timeCollectionRule.getDept();
61 String workArea = String.valueOf(timeCollectionRule.getWorkArea());
62 String location = null;
63 if (timeCollectionRule.getDept() != null) {
64 Department dept = TkServiceLocator.getDepartmentService().getDepartment(timeCollectionRule.getDept(), TKUtils.getCurrentDate());
65 location = dept == null ? null : dept.getLocation();
66 }
67 boolean systemAdmin = TKUser.isSystemAdmin();
68 boolean locationAdmin = TKUser.getLocationAdminAreas().contains(location);
69 boolean departmentAdmin = TKUser.getDepartmentAdminAreas().contains(department);
70
71 for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){
72 if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) {
73 if (systemAdmin || locationAdmin || departmentAdmin) {
74 customActionUrls.add(defaultCustomActionUrl);
75 }
76 } else {
77 customActionUrls.add(defaultCustomActionUrl);
78 }
79 }
80
81 Properties params = new Properties();
82 params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
83 params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
84 params.put("tkTimeCollectionRuleId", tkTimeCollectionRuleId);
85 params.put("dept", department);
86 params.put("workArea", workArea);
87 AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
88 viewUrl.setDisplayText("view");
89 viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
90 customActionUrls.add(viewUrl);
91
92 return customActionUrls;
93 }
94
95 @Override
96 public List<? extends BusinessObject> getSearchResults( Map<String, String> fieldValues) {
97 String workArea = fieldValues.get("workArea");
98 String dept = fieldValues.get("dept");
99 String payType = fieldValues.get("payType");
100 String active = fieldValues.get("active");
101 String history = fieldValues.get("history");
102
103 List<TimeCollectionRule> timeCollectionRules = TkServiceLocator.getTimeCollectionRuleService().getTimeCollectionRules(dept, workArea, payType, active, history);
104 return timeCollectionRules;
105 }
106
107 @Override
108 protected void validateSearchParameterWildcardAndOperators(
109 String attributeName, String attributeValue) {
110 if (!StringUtils.equals(attributeValue, "%")) {
111 super.validateSearchParameterWildcardAndOperators(attributeName,
112 attributeValue);
113 }
114 }
115 }