1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.lum.kim.role.type; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
20 | |
import org.kuali.rice.kim.api.KimConstants; |
21 | |
import org.kuali.rice.kim.api.role.RoleMembership; |
22 | |
import org.kuali.rice.kns.kim.role.DerivedRoleTypeServiceBase; |
23 | |
import org.kuali.rice.student.bo.KualiStudentKimAttributes; |
24 | |
import org.kuali.student.core.organization.dto.OrgPersonRelationInfo; |
25 | |
import org.kuali.student.core.organization.service.OrganizationService; |
26 | |
|
27 | |
import javax.xml.namespace.QName; |
28 | |
import java.util.*; |
29 | |
|
30 | 0 | public class OrgDerivedRoleTypeServiceImpl extends DerivedRoleTypeServiceBase { |
31 | |
|
32 | 0 | private static final org.apache.log4j.Logger LOG = |
33 | |
org.apache.log4j.Logger.getLogger(OrgDerivedRoleTypeServiceImpl.class); |
34 | |
|
35 | |
private OrganizationService orgService; |
36 | 0 | private List<String> includedOrgPersonRelationTypes = null; |
37 | 0 | private List<String> excludedOrgPersonRelationTypes = null; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
@Override |
51 | |
public List<RoleMembership> getRoleMembersFromDerivedRole( |
52 | |
String namespaceCode, String roleName, Map<String,String> qualification) { |
53 | 0 | if (null == orgService) { |
54 | 0 | orgService = (OrganizationService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/organization","OrganizationService")); |
55 | |
} |
56 | |
|
57 | 0 | validateRequiredAttributesAgainstReceived(qualification); |
58 | 0 | List<RoleMembership> members = new ArrayList<RoleMembership>(); |
59 | |
|
60 | 0 | String orgId = qualification.get(KualiStudentKimAttributes.QUALIFICATION_ORG_ID); |
61 | |
|
62 | 0 | if (LOG.isDebugEnabled()) { |
63 | 0 | LOG.debug("Using Org Values:"); |
64 | 0 | LOG.debug("------ Org ID: " + orgId); |
65 | |
|
66 | |
} |
67 | 0 | if (StringUtils.isEmpty(orgId)) { |
68 | 0 | throw new RuntimeException("No valid qualifier value found for key: " + KualiStudentKimAttributes.QUALIFICATION_ORG_ID); |
69 | |
} |
70 | |
|
71 | 0 | Map<String,String> attributes = new LinkedHashMap<String,String>(); |
72 | |
|
73 | |
|
74 | |
try { |
75 | |
|
76 | 0 | if(includedOrgPersonRelationTypes!=null){ |
77 | 0 | for(String orgPersonRelationType:includedOrgPersonRelationTypes){ |
78 | 0 | List<String> principalIds = orgService.getPersonIdsForOrgByRelationType(orgId, orgPersonRelationType); |
79 | 0 | for(String principalId:principalIds){ |
80 | 0 | RoleMembership member = RoleMembership.Builder.create(null, null, principalId, KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE, attributes).build(); |
81 | 0 | members.add(member); |
82 | 0 | } |
83 | 0 | } |
84 | |
|
85 | |
}else{ |
86 | |
|
87 | 0 | Date now = new Date(); |
88 | 0 | List<OrgPersonRelationInfo> relations = orgService.getAllOrgPersonRelationsByOrg(orgId); |
89 | 0 | for(OrgPersonRelationInfo relation:relations){ |
90 | 0 | if(excludedOrgPersonRelationTypes==null||!excludedOrgPersonRelationTypes.contains(relation.getType())){ |
91 | |
|
92 | 0 | if(relation.getExpirationDate()!=null){ |
93 | 0 | if(relation.getExpirationDate().compareTo(now)>=0){ |
94 | 0 | RoleMembership member = RoleMembership.Builder.create(null, null, relation.getPersonId(), KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE, attributes).build(); |
95 | 0 | members.add(member); |
96 | 0 | } |
97 | |
} |
98 | |
else{ |
99 | 0 | RoleMembership member = RoleMembership.Builder.create(null, null, relation.getPersonId(), KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE, attributes).build(); |
100 | 0 | members.add(member); |
101 | 0 | } |
102 | |
} |
103 | |
} |
104 | |
} |
105 | 0 | } catch (Exception e) { |
106 | 0 | LOG.warn("Error getting relations from Org Service for Org:"+orgId+". ",e); |
107 | 0 | } |
108 | |
|
109 | 0 | return members; |
110 | |
} |
111 | |
|
112 | |
public OrganizationService getOrgService() { |
113 | 0 | return orgService; |
114 | |
} |
115 | |
|
116 | |
public void setOrgService(OrganizationService orgService) { |
117 | 0 | this.orgService = orgService; |
118 | 0 | } |
119 | |
|
120 | |
public List<String> getIncludedOrgPersonRelationTypes() { |
121 | 0 | return includedOrgPersonRelationTypes; |
122 | |
} |
123 | |
|
124 | |
public void setIncludedOrgPersonRelationTypes( |
125 | |
List<String> includedOrgPersonRelationTypes) { |
126 | 0 | this.includedOrgPersonRelationTypes = includedOrgPersonRelationTypes; |
127 | 0 | } |
128 | |
|
129 | |
public List<String> getExcludedOrgPersonRelationTypes() { |
130 | 0 | return excludedOrgPersonRelationTypes; |
131 | |
} |
132 | |
|
133 | |
public void setExcludedOrgPersonRelationTypes( |
134 | |
List<String> excludedOrgPersonRelationTypes) { |
135 | 0 | this.excludedOrgPersonRelationTypes = excludedOrgPersonRelationTypes; |
136 | 0 | } |
137 | |
|
138 | |
|
139 | |
|
140 | |
} |