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.List; |
23 | |
|
24 | |
import javax.xml.namespace.QName; |
25 | |
|
26 | |
import org.apache.commons.lang.StringUtils; |
27 | |
import org.apache.log4j.Logger; |
28 | |
import org.kuali.rice.core.resourceloader.GlobalResourceLoader; |
29 | |
import org.kuali.rice.kim.bo.types.dto.AttributeSet; |
30 | |
import org.kuali.rice.kim.service.support.impl.KimRoleTypeServiceBase; |
31 | |
import org.kuali.rice.kns.web.format.BooleanFormatter; |
32 | |
import org.kuali.rice.student.bo.KualiStudentKimAttributes; |
33 | |
import org.kuali.student.core.exceptions.DoesNotExistException; |
34 | |
import org.kuali.student.core.exceptions.InvalidParameterException; |
35 | |
import org.kuali.student.core.exceptions.MissingParameterException; |
36 | |
import org.kuali.student.core.exceptions.OperationFailedException; |
37 | |
import org.kuali.student.core.exceptions.PermissionDeniedException; |
38 | |
import org.kuali.student.core.organization.dto.OrgInfo; |
39 | |
import org.kuali.student.core.organization.service.OrganizationService; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | 0 | public class OrganizationHierarchyRoleTypeService extends KimRoleTypeServiceBase { |
46 | 0 | private static final Logger LOG = Logger.getLogger(OrganizationHierarchyRoleTypeService.class); |
47 | |
|
48 | |
public static final String DESCEND_HIERARCHY_TRUE_VALUE = "Y"; |
49 | |
public static final String DESCEND_HIERARCHY_FALSE_VALUE = "N"; |
50 | |
|
51 | |
{ |
52 | 0 | requiredAttributes.add(KualiStudentKimAttributes.QUALIFICATION_ORG_ID); |
53 | 0 | } |
54 | |
|
55 | |
protected OrganizationService orgService; |
56 | |
|
57 | |
@Override |
58 | |
protected boolean performMatch(AttributeSet inputQualification, AttributeSet roleMemberQualifier) { |
59 | |
|
60 | |
|
61 | 0 | if ( inputQualification == null || inputQualification.isEmpty() || roleMemberQualifier == null || roleMemberQualifier.isEmpty() ) { |
62 | 0 | return true; |
63 | |
} |
64 | 0 | String roleMemberOrganizationShortName = roleMemberQualifier.get(KualiStudentKimAttributes.QUALIFICATION_ORG); |
65 | |
|
66 | 0 | if (StringUtils.isBlank(roleMemberOrganizationShortName)) { |
67 | 0 | return true; |
68 | |
} |
69 | 0 | String inputOrgId = inputQualification.get(KualiStudentKimAttributes.QUALIFICATION_ORG_ID); |
70 | 0 | List<AttributeSet> inputSets = new ArrayList<AttributeSet>(); |
71 | |
try { |
72 | |
|
73 | 0 | BooleanFormatter format = new BooleanFormatter(); |
74 | 0 | Boolean b = (Boolean)format.convertFromPresentationFormat(roleMemberQualifier.get(KualiStudentKimAttributes.DESCEND_HIERARCHY)); |
75 | 0 | if (b.booleanValue()) { |
76 | 0 | inputSets.addAll(getHierarchyOrgShortNames(inputOrgId)); |
77 | |
} |
78 | |
|
79 | 0 | if(inputOrgId!=null){ |
80 | 0 | OrgInfo org = getOrganizationService().getOrganization(inputOrgId); |
81 | 0 | inputSets.add(new AttributeSet(KualiStudentKimAttributes.QUALIFICATION_ORG,org.getShortName())); |
82 | |
} |
83 | |
|
84 | 0 | return hasMatch(inputSets, roleMemberOrganizationShortName); |
85 | 0 | } catch (Exception e) { |
86 | 0 | LOG.error(e); |
87 | 0 | throw new RuntimeException(e); |
88 | |
} |
89 | |
} |
90 | |
|
91 | |
protected boolean hasMatch(List<AttributeSet> inputAttributeSets, String roleMemberOrganizationShortName) { |
92 | 0 | for (AttributeSet inputSet : inputAttributeSets) { |
93 | 0 | if (StringUtils.equals(roleMemberOrganizationShortName, inputSet.get(KualiStudentKimAttributes.QUALIFICATION_ORG))) { |
94 | 0 | return true; |
95 | |
} |
96 | |
} |
97 | 0 | return false; |
98 | |
} |
99 | |
|
100 | |
protected List<AttributeSet> getHierarchyOrgShortNames(String inputOrgId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
101 | 0 | List<AttributeSet> returnSets = new ArrayList<AttributeSet>(); |
102 | 0 | returnSets.addAll(getOrgShortNamesForHierarchy(inputOrgId, "kuali.org.hierarchy.Main")); |
103 | 0 | returnSets.addAll(getOrgShortNamesForHierarchy(inputOrgId, "kuali.org.hierarchy.Curriculum")); |
104 | 0 | return returnSets; |
105 | |
} |
106 | |
|
107 | |
protected List<AttributeSet> getOrgShortNamesForHierarchy(String inputOrgId, String orgHierarchy) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException { |
108 | 0 | List<AttributeSet> returnSets = new ArrayList<AttributeSet>(); |
109 | 0 | List<String> ids = getOrganizationService().getAllAncestors(inputOrgId, orgHierarchy); |
110 | 0 | if (ids.size() > 0) { |
111 | 0 | List<OrgInfo> orgs = getOrganizationService().getOrganizationsByIdList(ids); |
112 | 0 | for (OrgInfo orgInfo : orgs) { |
113 | 0 | returnSets.add(new AttributeSet(KualiStudentKimAttributes.QUALIFICATION_ORG, orgInfo.getShortName())); |
114 | |
} |
115 | |
} |
116 | 0 | return returnSets; |
117 | |
} |
118 | |
|
119 | |
protected OrganizationService getOrganizationService() { |
120 | 0 | if (null == orgService) { |
121 | 0 | orgService = (OrganizationService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/organization","OrganizationService")); |
122 | |
} |
123 | 0 | return orgService; |
124 | |
} |
125 | |
|
126 | |
} |