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.*;
19
20 import org.kuali.kpme.core.api.department.Department;
21 import org.kuali.kpme.core.api.namespace.KPMENamespace;
22 import org.kuali.kpme.core.api.permission.KPMEPermissionTemplate;
23 import org.kuali.kpme.core.lookup.KPMELookupableImpl;
24 import org.kuali.kpme.core.role.KPMERoleMemberAttribute;
25 import org.kuali.kpme.core.service.HrServiceLocator;
26 import org.kuali.kpme.core.workarea.WorkAreaBo;
27 import org.kuali.kpme.tklm.time.clocklog.ClockLogBo;
28 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
29 import org.kuali.rice.kim.api.KimConstants;
30 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
31 import org.kuali.rice.krad.lookup.LookupUtils;
32 import org.kuali.rice.krad.uif.view.LookupView;
33 import org.kuali.rice.krad.util.GlobalVariables;
34 import org.kuali.rice.krad.web.form.LookupForm;
35
36 public class ClockLogLookupableImpl extends KPMELookupableImpl {
37
38 @Override
39 public void initSuppressAction(LookupForm lookupForm) {
40 ((LookupView) lookupForm.getView()).setSuppressActions(false);
41 }
42
43 @Override
44 public List<?> getSearchResults(LookupForm form, Map<String, String> searchCriteria, boolean unbounded) {
45 String userPrincipalId = GlobalVariables.getUserSession().getPrincipalId();
46
47 Integer searchResultsLimit = null;
48
49 Collection<?> rawSearchResults;
50
51
52 Map<String, String> nonBlankSearchCriteria = processSearchCriteria(form, searchCriteria);
53
54 if (nonBlankSearchCriteria == null) {
55 return new ArrayList<Object>();
56 }
57
58 if (!unbounded) {
59 searchResultsLimit = LookupUtils.getSearchResultsLimit(getDataObjectClass(), form);
60 }
61
62 rawSearchResults = getLookupService().findCollectionBySearchHelper(getDataObjectClass(),
63 nonBlankSearchCriteria, unbounded, searchResultsLimit);
64
65 if (rawSearchResults == null) {
66 rawSearchResults = new ArrayList<Object>();
67 } else {
68 sortSearchResults(form, (List<?>) rawSearchResults);
69 }
70
71 List<ClockLogBo> filteredResults = filterLookupResults((List<ClockLogBo>)rawSearchResults, userPrincipalId);
72
73 generateLookupResultsMessages(form, nonBlankSearchCriteria, filteredResults, unbounded);
74
75 for (ClockLogBo searchResult : filteredResults) {
76 if(searchResult != null) {
77 searchResult.setClockedByMissedPunch(TkServiceLocator.getClockLogService().isClockLogCreatedByMissedPunch(searchResult.getTkClockLogId()));
78 }
79 }
80
81 return filteredResults;
82 }
83
84 protected List<ClockLogBo> filterLookupResults(List<ClockLogBo> rawResults, String userPrincipalId) {
85 List<ClockLogBo> results = new ArrayList<ClockLogBo>();
86 for (ClockLogBo clockLogObj : rawResults) {
87
88
89 String department = clockLogObj.getDept();
90 String groupKeyCode = clockLogObj.getGroupKeyCode();
91 Department departmentObj = HrServiceLocator.getDepartmentService().getDepartment(department, groupKeyCode, clockLogObj.getClockDateTime().toLocalDate());
92 String location = departmentObj != null ? departmentObj.getGroupKey().getLocationId() : null;
93
94 Map<String, String> roleQualification = new HashMap<String, String>();
95
96 roleQualification.put(KimConstants.AttributeConstants.PRINCIPAL_ID, userPrincipalId);
97 roleQualification.put(KPMERoleMemberAttribute.DEPARTMENT.getRoleMemberAttributeName(), department);
98 roleQualification.put(KPMERoleMemberAttribute.GROUP_KEY_CODE.getRoleMemberAttributeName(), groupKeyCode);
99 roleQualification.put(KPMERoleMemberAttribute.LOCATION.getRoleMemberAttributeName(), location);
100
101 if (!KimApiServiceLocator.getPermissionService().isPermissionDefinedByTemplate(KPMENamespace.KPME_WKFLW.getNamespaceCode(),
102 KPMEPermissionTemplate.VIEW_KPME_RECORD.getPermissionTemplateName(), new HashMap<String, String>())
103 || KimApiServiceLocator.getPermissionService().isAuthorizedByTemplate(userPrincipalId, KPMENamespace.KPME_WKFLW.getNamespaceCode(),
104 KPMEPermissionTemplate.VIEW_KPME_RECORD.getPermissionTemplateName(), new HashMap<String, String>(), roleQualification)) {
105 results.add(clockLogObj);
106 }
107 }
108
109 return results;
110 }
111
112 }