1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.assignment.web;
17
18 import org.kuali.kpme.core.api.namespace.KPMENamespace;
19 import org.kuali.kpme.core.api.permission.KPMEPermissionTemplate;
20 import org.kuali.kpme.core.groupkey.HrGroupKeyBo;
21 import org.kuali.kpme.core.lookup.KpmeHrGroupKeyedBusinessObjectLookupableImpl;
22 import org.kuali.kpme.core.role.KPMERoleMemberAttribute;
23 import org.kuali.rice.kim.api.KimConstants;
24 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
25 import org.kuali.rice.krad.util.GlobalVariables;
26 import org.kuali.rice.krad.web.form.LookupForm;
27 import org.kuali.kpme.core.assignment.AssignmentBo;
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.List;
31 import java.util.Map;
32
33 public class AssignmentLookupableImpl extends KpmeHrGroupKeyedBusinessObjectLookupableImpl {
34 private static final long serialVersionUID = 774015772672806415L;
35
36
37 protected List<AssignmentBo> filterLookupAssignments(List<AssignmentBo> rawResults, String userPrincipalId) {
38 List<AssignmentBo> results = new ArrayList<AssignmentBo>();
39 for (AssignmentBo assignmentObj : rawResults) {
40 Map<String, String> roleQualification = new HashMap<String, String>();
41 roleQualification.put(KimConstants.AttributeConstants.PRINCIPAL_ID, userPrincipalId);
42 roleQualification.put(KPMERoleMemberAttribute.DEPARTMENT.getRoleMemberAttributeName(), assignmentObj.getDept());
43 roleQualification.put(KPMERoleMemberAttribute.GROUP_KEY_CODE.getRoleMemberAttributeName(), assignmentObj.getGroupKeyCode());
44 roleQualification.put(KPMERoleMemberAttribute.WORK_AREA.getRoleMemberAttributeName(), assignmentObj.getWorkArea().toString());
45
46 HrGroupKeyBo groupKey = assignmentObj.getGroupKey();
47 if(groupKey != null) {
48 roleQualification.put(KPMERoleMemberAttribute.LOCATION.getRoleMemberAttributeName(), groupKey.getLocationId());
49 roleQualification.put(KPMERoleMemberAttribute.INSTITUION.getRoleMemberAttributeName(), groupKey.getInstitutionCode());
50 }
51
52 if (!KimApiServiceLocator.getPermissionService().isPermissionDefinedByTemplate(KPMENamespace.KPME_WKFLW.getNamespaceCode(),
53 KPMEPermissionTemplate.VIEW_KPME_RECORD.getPermissionTemplateName(), new HashMap<String, String>())
54 || KimApiServiceLocator.getPermissionService().isAuthorizedByTemplate(userPrincipalId, KPMENamespace.KPME_WKFLW.getNamespaceCode(),
55 KPMEPermissionTemplate.VIEW_KPME_RECORD.getPermissionTemplateName(), new HashMap<String, String>(), roleQualification)) {
56 results.add(assignmentObj);
57 }
58 }
59
60 return results;
61 }
62
63 @SuppressWarnings("unchecked")
64 @Override
65 protected List<?> getSearchResults(LookupForm form, Map<String, String> searchCriteria, boolean unbounded) {
66 String userPrincipalId = GlobalVariables.getUserSession().getPrincipalId();
67 List<AssignmentBo> results = (List<AssignmentBo>) super.getSearchResults(form, searchCriteria, unbounded);
68 List<AssignmentBo> filteredResults = filterLookupAssignments(results, userPrincipalId);
69 generateLookupResultsMessages(form, searchCriteria, filteredResults, unbounded);
70 return filteredResults;
71 }
72 }