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