1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.dept.lunch.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.department.Department;
28 import org.kuali.hr.time.dept.lunch.DeptLunchRule;
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 DepartmentLunchRuleLookupableHelper extends TkAuthorizedLookupableHelperBase {
39
40 private static final long serialVersionUID = -6171434403261481651L;
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 DeptLunchRule deptLunchRule = (DeptLunchRule) businessObject;
58 String tkDeptLunchRuleId = deptLunchRule.getTkDeptLunchRuleId();
59 String department = deptLunchRule.getDept();
60 String workArea = String.valueOf(deptLunchRule.getWorkArea());
61 Department dept = TkServiceLocator.getDepartmentService().getDepartment(deptLunchRule.getDept(), TKUtils.getCurrentDate());
62 String location = dept == null ? null : dept.getLocation();
63
64 boolean systemAdmin = TKContext.getUser().isSystemAdmin();
65 boolean locationAdmin = TKContext.getUser().getLocationAdminAreas().contains(location);
66 boolean departmentAdmin = TKContext.getUser().getDepartmentAdminAreas().contains(department);
67
68 for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){
69 if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) {
70 if (systemAdmin || locationAdmin || departmentAdmin) {
71 customActionUrls.add(defaultCustomActionUrl);
72 }
73 } else {
74 customActionUrls.add(defaultCustomActionUrl);
75 }
76 }
77
78 Properties params = new Properties();
79 params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
80 params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
81 params.put("tkDeptLunchRuleId", tkDeptLunchRuleId);
82 params.put("dept", department);
83 params.put("workArea", workArea);
84 AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
85 viewUrl.setDisplayText("view");
86 viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
87 customActionUrls.add(viewUrl);
88
89 return customActionUrls;
90 }
91
92 @Override
93 protected void validateSearchParameterWildcardAndOperators(
94 String attributeName, String attributeValue) {
95 if (!StringUtils.equals(attributeValue, "%")) {
96 super.validateSearchParameterWildcardAndOperators(attributeName,
97 attributeValue);
98 }
99 }
100
101 @Override
102 public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
103 String principalId = fieldValues.get("principalId");
104 String jobNumber = fieldValues.get("jobNumber");
105 String dept = fieldValues.get("dept");
106 String workArea = fieldValues.get("workArea");
107 String active = fieldValues.get("active");
108
109 if (StringUtils.equals(workArea,"%") || StringUtils.equals(workArea,"*")){
110 workArea = "";
111 }
112 List<DeptLunchRule> departmentLunchRules = TkServiceLocator.getDepartmentLunchRuleService().getDepartmentLunchRules(dept,
113 workArea, principalId, jobNumber, active);
114 return departmentLunchRules;
115 }
116 }