1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.clock.location.service;
17
18 import java.io.Serializable;
19 import java.util.ArrayList;
20 import java.util.Comparator;
21 import java.util.List;
22 import java.util.Map;
23 import java.util.Properties;
24
25 import org.apache.commons.lang.StringUtils;
26 import org.kuali.hr.time.authorization.DepartmentalRule;
27 import org.kuali.hr.time.authorization.DepartmentalRuleAuthorizer;
28 import org.kuali.hr.time.authorization.TkAuthorizedLookupableHelperBase;
29 import org.kuali.hr.time.clock.location.ClockLocationRule;
30 import org.kuali.hr.time.department.Department;
31 import org.kuali.hr.time.service.base.TkServiceLocator;
32 import org.kuali.hr.time.util.TKContext;
33 import org.kuali.hr.time.util.TKUser;
34 import org.kuali.hr.time.util.TKUtils;
35 import org.kuali.rice.kns.lookup.HtmlData;
36 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
37 import org.kuali.rice.krad.bo.BusinessObject;
38 import org.kuali.rice.krad.util.KRADConstants;
39 import org.kuali.rice.krad.util.UrlFactory;
40
41 public class ClockLocationRuleLookupableHelper extends TkAuthorizedLookupableHelperBase {
42
43 private static final long serialVersionUID = 7261054962204557586L;
44
45 @Override
46
47
48
49
50 public boolean shouldShowBusinessObject(BusinessObject bo) {
51 return (bo instanceof DepartmentalRule) && DepartmentalRuleAuthorizer.hasAccessToRead((DepartmentalRule)bo);
52 }
53
54 @Override
55 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
56 List<HtmlData> customActionUrls = new ArrayList<HtmlData>();
57
58 List<HtmlData> defaultCustomActionUrls = super.getCustomActionUrls(businessObject, pkNames);
59
60 ClockLocationRule clockLocationRule = (ClockLocationRule) businessObject;
61 String tkClockLocationRuleId = clockLocationRule.getTkClockLocationRuleId();
62 Department dept = TkServiceLocator.getDepartmentService().getDepartment(clockLocationRule.getDept(), TKUtils.getCurrentDate());
63 String location = dept == null ? null : dept.getLocation();
64 String department = clockLocationRule.getDept();
65
66 boolean systemAdmin = TKUser.isSystemAdmin();
67 boolean locationAdmin = TKUser.getLocationAdminAreas().contains(location);
68 boolean departmentAdmin = TKUser.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("tkClockLocationRuleId", tkClockLocationRuleId);
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 @SuppressWarnings("rawtypes")
102 public static class EffectiveDateTimestampCompare implements Comparator, Serializable {
103
104 @Override
105 public int compare(Object arg0, Object arg1) {
106 ClockLocationRule clockLocationRule = (ClockLocationRule)arg0;
107 ClockLocationRule clockLocationRule2 = (ClockLocationRule)arg1;
108 int result = clockLocationRule.getEffectiveDate().compareTo(clockLocationRule2.getEffectiveDate());
109 if(result==0){
110 return clockLocationRule.getTimestamp().compareTo(clockLocationRule2.getTimestamp());
111 }
112 return result;
113 }
114
115 }
116
117 public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
118 String fromEffdt = TKUtils.getFromDateString(fieldValues.get("effectiveDate"));
119 String toEffdt = TKUtils.getToDateString(fieldValues.get("effectiveDate"));
120 String principalId = fieldValues.get("principalId");
121 String jobNumber = fieldValues.get("jobNumber");
122 String dept = fieldValues.get("dept");
123 String workArea = fieldValues.get("workArea");
124 String active = fieldValues.get("active");
125 String showHist = fieldValues.get("history");
126
127 return TkServiceLocator.getClockLocationRuleService().getClockLocationRules(TKUtils.formatDateString(fromEffdt), TKUtils.formatDateString(toEffdt),
128 principalId, jobNumber, dept, workArea, active, showHist);
129 }
130
131 }