1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.time.clocklog.web;
17
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Map;
22 import java.util.Properties;
23
24 import org.joda.time.LocalDate;
25 import org.kuali.kpme.core.KPMENamespace;
26 import org.kuali.kpme.core.department.Department;
27 import org.kuali.kpme.core.job.Job;
28 import org.kuali.kpme.core.lookup.KPMELookupableHelper;
29 import org.kuali.kpme.core.permission.KPMEPermissionTemplate;
30 import org.kuali.kpme.core.role.KPMERoleMemberAttribute;
31 import org.kuali.kpme.core.service.HrServiceLocator;
32 import org.kuali.kpme.tklm.time.clocklog.ClockLog;
33 import org.kuali.kpme.tklm.time.missedpunch.MissedPunch;
34 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
35 import org.kuali.kpme.tklm.time.workflow.TimesheetDocumentHeader;
36 import org.kuali.rice.kim.api.KimConstants;
37 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
38 import org.kuali.rice.kns.lookup.HtmlData;
39 import org.kuali.rice.krad.bo.BusinessObject;
40 import org.kuali.rice.krad.util.GlobalVariables;
41 import org.kuali.rice.krad.util.KRADConstants;
42 import org.kuali.rice.krad.util.UrlFactory;
43
44 @SuppressWarnings("deprecation")
45 public class ClockLogLookupableHelper extends KPMELookupableHelper {
46
47 private static final long serialVersionUID = -469827905426221716L;
48
49 @Override
50 @SuppressWarnings("rawtypes")
51 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
52 List<HtmlData> customActionUrls = super.getCustomActionUrls(businessObject, pkNames);
53
54 ClockLog clockLog = (ClockLog)businessObject;
55 String tkClockLogId = clockLog.getTkClockLogId();
56
57 MissedPunch missedPunch = TkServiceLocator.getMissedPunchService().getMissedPunchByClockLogId(clockLog.getTkClockLogId());
58 if (missedPunch != null) {
59 clockLog.setClockedByMissedPunch(true);
60 }
61
62 Properties params = new Properties();
63 params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
64 params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
65 params.put("tkClockLogId", tkClockLogId);
66 HtmlData.AnchorHtmlData viewUrl = new HtmlData.AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
67 viewUrl.setDisplayText("view");
68 viewUrl.setTarget(HtmlData.AnchorHtmlData.TARGET_BLANK);
69 customActionUrls.add(viewUrl);
70
71 return customActionUrls;
72 }
73
74 @Override
75 public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
76 List<ClockLog> results = new ArrayList<ClockLog>();
77
78 List<? extends BusinessObject> searchResults = super.getSearchResults(fieldValues);
79
80 for (BusinessObject searchResult : searchResults) {
81 ClockLog clockLog = (ClockLog) searchResult;
82 results.add(clockLog);
83 }
84
85 results = filterByPrincipalId(results, GlobalVariables.getUserSession().getPrincipalId());
86
87 return results;
88 }
89
90 private List<ClockLog> filterByPrincipalId(List<ClockLog> clockLogs, String principalId) {
91 List<ClockLog> results = new ArrayList<ClockLog>();
92
93 for (ClockLog clockLog : clockLogs) {
94 if (clockLog.getDocumentId() == null) {
95 TimesheetDocumentHeader tsdh = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeaderForDate(clockLog.getPrincipalId(), clockLog.getClockDateTime());
96 if (tsdh != null) {
97 clockLog.setDocumentId(tsdh.getDocumentId());
98 }
99 }
100
101 Job jobObj = HrServiceLocator.getJobService().getJob(clockLog.getPrincipalId(), clockLog.getJobNumber(), LocalDate.fromDateFields(clockLog.getClockTimestamp()), false);
102 String department = jobObj != null ? jobObj.getDept() : null;
103
104 Department departmentObj = jobObj != null ? HrServiceLocator.getDepartmentService().getDepartmentWithoutRoles(department, LocalDate.fromDateFields(clockLog.getClockTimestamp())) : null;
105 String location = departmentObj != null ? departmentObj.getLocation() : null;
106
107 Map<String, String> roleQualification = new HashMap<String, String>();
108 roleQualification.put(KimConstants.AttributeConstants.PRINCIPAL_ID, GlobalVariables.getUserSession().getPrincipalId());
109 roleQualification.put(KPMERoleMemberAttribute.DEPARTMENT.getRoleMemberAttributeName(), department);
110 roleQualification.put(KPMERoleMemberAttribute.LOCATION.getRoleMemberAttributeName(), location);
111
112 if (!KimApiServiceLocator.getPermissionService().isPermissionDefinedByTemplate(KPMENamespace.KPME_WKFLW.getNamespaceCode(),
113 KPMEPermissionTemplate.VIEW_KPME_RECORD.getPermissionTemplateName(), new HashMap<String, String>())
114 || KimApiServiceLocator.getPermissionService().isAuthorizedByTemplate(principalId, KPMENamespace.KPME_WKFLW.getNamespaceCode(),
115 KPMEPermissionTemplate.VIEW_KPME_RECORD.getPermissionTemplateName(), new HashMap<String, String>(), roleQualification)) {
116 results.add(clockLog);
117 }
118 }
119
120 return results;
121 }
122 }