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.util.ArrayList;
19 import java.util.Comparator;
20 import java.util.List;
21 import java.util.Map;
22 import java.util.Properties;
23
24 import org.apache.commons.lang.StringUtils;
25 import org.kuali.hr.time.authorization.DepartmentalRule;
26 import org.kuali.hr.time.authorization.DepartmentalRuleAuthorizer;
27 import org.kuali.hr.time.authorization.TkAuthorizedLookupableHelperBase;
28 import org.kuali.hr.time.clock.location.ClockLocationRule;
29 import org.kuali.hr.time.department.Department;
30 import org.kuali.hr.time.service.base.TkServiceLocator;
31 import org.kuali.hr.time.util.TKContext;
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 ClockLocationRuleLookupableHelper extends TkAuthorizedLookupableHelperBase {
40
41 private static final long serialVersionUID = 7261054962204557586L;
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 ClockLocationRule clockLocationRule = (ClockLocationRule) businessObject;
59 String tkClockLocationRuleId = clockLocationRule.getTkClockLocationRuleId();
60 Department dept = TkServiceLocator.getDepartmentService().getDepartment(clockLocationRule.getDept(), TKUtils.getCurrentDate());
61 String location = dept == null ? null : dept.getLocation();
62 String department = clockLocationRule.getDept();
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("tkClockLocationRuleId", tkClockLocationRuleId);
82 AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
83 viewUrl.setDisplayText("view");
84 viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
85 customActionUrls.add(viewUrl);
86
87 return customActionUrls;
88 }
89
90 @Override
91 protected void validateSearchParameterWildcardAndOperators(
92 String attributeName, String attributeValue) {
93 if (!StringUtils.equals(attributeValue, "%")) {
94 super.validateSearchParameterWildcardAndOperators(attributeName,
95 attributeValue);
96 }
97 }
98
99 @SuppressWarnings("rawtypes")
100 public class EffectiveDateTimestampCompare implements Comparator{
101
102 @Override
103 public int compare(Object arg0, Object arg1) {
104 ClockLocationRule clockLocationRule = (ClockLocationRule)arg0;
105 ClockLocationRule clockLocationRule2 = (ClockLocationRule)arg1;
106 int result = clockLocationRule.getEffectiveDate().compareTo(clockLocationRule2.getEffectiveDate());
107 if(result==0){
108 return clockLocationRule.getTimestamp().compareTo(clockLocationRule2.getTimestamp());
109 }
110 return result;
111 }
112
113 }
114
115 public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
116 String fromEffdt = TKUtils.getFromDateString(fieldValues.get("effectiveDate"));
117 String toEffdt = TKUtils.getToDateString(fieldValues.get("effectiveDate"));
118 String principalId = fieldValues.get("principalId");
119 String jobNumber = fieldValues.get("jobNumber");
120 String dept = fieldValues.get("dept");
121 String workArea = fieldValues.get("workArea");
122 String active = fieldValues.get("active");
123 String showHist = fieldValues.get("history");
124
125 return TkServiceLocator.getClockLocationRuleService().getClockLocationRules(TKUtils.formatDateString(fromEffdt), TKUtils.formatDateString(toEffdt),
126 principalId, jobNumber, dept, workArea, active, showHist);
127 }
128
129 }