1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.kuali.student.lum.kim.role.type; |
20 | |
|
21 | |
import java.util.ArrayList; |
22 | |
import java.util.LinkedHashMap; |
23 | |
import java.util.List; |
24 | |
import java.util.Map; |
25 | |
|
26 | |
import javax.xml.namespace.QName; |
27 | |
|
28 | |
import org.apache.commons.lang.StringUtils; |
29 | |
import org.apache.log4j.Logger; |
30 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
31 | |
import org.kuali.rice.core.web.format.BooleanFormatter; |
32 | |
import org.kuali.rice.kns.kim.role.RoleTypeServiceBase; |
33 | |
import org.kuali.rice.student.bo.KualiStudentKimAttributes; |
34 | |
import org.kuali.student.common.exceptions.DoesNotExistException; |
35 | |
import org.kuali.student.common.exceptions.InvalidParameterException; |
36 | |
import org.kuali.student.common.exceptions.MissingParameterException; |
37 | |
import org.kuali.student.common.exceptions.OperationFailedException; |
38 | |
import org.kuali.student.common.exceptions.PermissionDeniedException; |
39 | |
import org.kuali.student.core.organization.dto.OrgInfo; |
40 | |
import org.kuali.student.core.organization.service.OrganizationService; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 0 | public class OrganizationHierarchyRoleTypeService extends RoleTypeServiceBase { |
47 | 0 | private static final Logger LOG = Logger.getLogger(OrganizationHierarchyRoleTypeService.class); |
48 | |
|
49 | |
public static final String DESCEND_HIERARCHY_TRUE_VALUE = "Y"; |
50 | |
public static final String DESCEND_HIERARCHY_FALSE_VALUE = "N"; |
51 | |
|
52 | |
protected OrganizationService orgService; |
53 | |
|
54 | |
@Override |
55 | |
protected boolean performMatch(Map<String,String> inputQualification, Map<String,String> roleMemberQualifier) { |
56 | |
|
57 | |
|
58 | 0 | if ( inputQualification == null || inputQualification.isEmpty() || roleMemberQualifier == null || roleMemberQualifier.isEmpty() ) { |
59 | 0 | return true; |
60 | |
} |
61 | |
|
62 | 0 | String roleMemberOrganizationId = roleMemberQualifier.get(KualiStudentKimAttributes.QUALIFICATION_ORG_ID); |
63 | |
|
64 | 0 | if (StringUtils.isBlank(roleMemberOrganizationId)) { |
65 | 0 | return true; |
66 | |
} |
67 | 0 | String inputOrgId = inputQualification.get(KualiStudentKimAttributes.QUALIFICATION_ORG_ID); |
68 | 0 | List<Map<String,String>> inputSets = new ArrayList<Map<String,String>>(); |
69 | |
try { |
70 | |
|
71 | 0 | BooleanFormatter format = new BooleanFormatter(); |
72 | 0 | Boolean b = (Boolean)format.convertFromPresentationFormat(roleMemberQualifier.get(KualiStudentKimAttributes.DESCEND_HIERARCHY)); |
73 | 0 | if (b.booleanValue()) { |
74 | |
|
75 | 0 | inputSets.addAll(getHierarchyOrgIds(inputOrgId)); |
76 | |
} |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | 0 | return hasMatch(inputSets, roleMemberOrganizationId); |
86 | 0 | } catch (Exception e) { |
87 | 0 | LOG.error(e); |
88 | 0 | throw new RuntimeException(e); |
89 | |
} |
90 | |
} |
91 | |
|
92 | |
protected boolean hasMatch(List<Map<String,String>> inputAttributeSets, String roleMemberOrganizationId) { |
93 | 0 | for (Map<String,String> inputSet : inputAttributeSets) { |
94 | 0 | if (StringUtils.equals(roleMemberOrganizationId, inputSet.get(KualiStudentKimAttributes.QUALIFICATION_ORG_ID))) { |
95 | 0 | return true; |
96 | |
} |
97 | |
} |
98 | 0 | return false; |
99 | |
} |
100 | |
|
101 | |
protected List<Map<String,String>> getHierarchyOrgIds(String inputOrgId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
102 | 0 | List<Map<String,String>> returnSets = new ArrayList<Map<String,String>>(); |
103 | 0 | returnSets.addAll(getOrgIdsForHierarchy(inputOrgId, "kuali.org.hierarchy.Main")); |
104 | 0 | returnSets.addAll(getOrgIdsForHierarchy(inputOrgId, "kuali.org.hierarchy.Curriculum")); |
105 | 0 | return returnSets; |
106 | |
} |
107 | |
|
108 | |
protected List<Map<String,String>> getOrgIdsForHierarchy(String inputOrgId, String orgHierarchy) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException { |
109 | 0 | List<Map<String,String>> returnSets = new ArrayList<Map<String,String>>(); |
110 | 0 | List<String> ids = getOrganizationService().getAllAncestors(inputOrgId, orgHierarchy); |
111 | 0 | if (ids.size() > 0) { |
112 | 0 | List<OrgInfo> orgs = getOrganizationService().getOrganizationsByIdList(ids); |
113 | 0 | for (OrgInfo orgInfo : orgs) { |
114 | 0 | Map<String, String> attrs = new LinkedHashMap<String,String>(); |
115 | 0 | attrs.put(KualiStudentKimAttributes.QUALIFICATION_ORG_ID, orgInfo.getId()); |
116 | 0 | returnSets.add(attrs); |
117 | 0 | } |
118 | |
} |
119 | 0 | return returnSets; |
120 | |
} |
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
protected OrganizationService getOrganizationService() { |
144 | 0 | if (null == orgService) { |
145 | 0 | orgService = (OrganizationService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/organization","OrganizationService")); |
146 | |
} |
147 | 0 | return orgService; |
148 | |
} |
149 | |
|
150 | |
} |