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