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