1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.impl.jaxb; |
17 | |
|
18 | |
import java.io.Serializable; |
19 | |
import java.util.ArrayList; |
20 | |
import java.util.Collections; |
21 | |
import java.util.HashSet; |
22 | |
import java.util.List; |
23 | |
import java.util.Set; |
24 | |
|
25 | |
import javax.xml.bind.Marshaller; |
26 | |
import javax.xml.bind.UnmarshalException; |
27 | |
import javax.xml.bind.Unmarshaller; |
28 | |
import javax.xml.bind.annotation.XmlAccessType; |
29 | |
import javax.xml.bind.annotation.XmlAccessorType; |
30 | |
import javax.xml.bind.annotation.XmlElement; |
31 | |
import javax.xml.bind.annotation.XmlTransient; |
32 | |
import javax.xml.bind.annotation.XmlType; |
33 | |
|
34 | |
import org.kuali.rice.core.api.criteria.QueryByCriteria; |
35 | |
import org.kuali.rice.core.util.jaxb.RiceXmlExportList; |
36 | |
import org.kuali.rice.core.util.jaxb.RiceXmlImportList; |
37 | |
import org.kuali.rice.core.util.jaxb.RiceXmlListAdditionListener; |
38 | |
import org.kuali.rice.core.util.jaxb.RiceXmlListGetterListener; |
39 | |
import org.kuali.rice.kim.api.role.RoleMember; |
40 | |
import org.kuali.rice.kim.api.role.RoleMemberContract; |
41 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
42 | |
|
43 | |
import static org.kuali.rice.core.api.criteria.PredicateFactory.equal; |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
@XmlTransient |
52 | 0 | public abstract class RoleMembersXmlDTO<T extends RoleMemberXmlDTO> implements RiceXmlListAdditionListener<T>, Serializable { |
53 | |
|
54 | |
private static final long serialVersionUID = 1L; |
55 | |
|
56 | |
public abstract List<T> getRoleMembers(); |
57 | |
|
58 | |
public abstract void setRoleMembers(List<T> roleMembers); |
59 | |
|
60 | |
void beforeUnmarshal(Unmarshaller unmarshaller, Object parent) throws UnmarshalException { |
61 | 0 | setRoleMembers(new RiceXmlImportList<T>(this)); |
62 | 0 | } |
63 | |
|
64 | |
void afterUnmarshal(Unmarshaller unmarshaller, Object parent) throws UnmarshalException { |
65 | 0 | setRoleMembers(null); |
66 | 0 | } |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | 0 | @XmlAccessorType(XmlAccessType.FIELD) |
76 | |
@XmlType(name="StandaloneRoleMembersType", propOrder={"roleMembers"}) |
77 | 0 | public static class OutsideOfRole extends RoleMembersXmlDTO<RoleMemberXmlDTO.OutsideOfRole> { |
78 | |
|
79 | |
private static final long serialVersionUID = 1L; |
80 | |
|
81 | |
@XmlElement(name="roleMember") |
82 | |
private List<RoleMemberXmlDTO.OutsideOfRole> roleMembers; |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
@Override |
88 | |
public List<RoleMemberXmlDTO.OutsideOfRole> getRoleMembers() { |
89 | 0 | return this.roleMembers; |
90 | |
} |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
@Override |
96 | |
public void setRoleMembers(List<RoleMemberXmlDTO.OutsideOfRole> roleMembers) { |
97 | 0 | this.roleMembers = roleMembers; |
98 | 0 | } |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
@Override |
104 | |
public void newItemAdded(RoleMemberXmlDTO.OutsideOfRole item) { |
105 | |
try { |
106 | 0 | RoleXmlUtil.validateAndPersistNewRoleMember(item); |
107 | 0 | } catch (UnmarshalException e) { |
108 | 0 | throw new RuntimeException(e); |
109 | 0 | } |
110 | 0 | } |
111 | |
} |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | 0 | @XmlAccessorType(XmlAccessType.FIELD) |
121 | |
@XmlType(name="RoleMembersType", propOrder={"roleMembers"}) |
122 | |
public static class WithinRole extends RoleMembersXmlDTO<RoleMemberXmlDTO.WithinRole> |
123 | |
implements RiceXmlListGetterListener<RoleMemberXmlDTO.WithinRole,String> { |
124 | |
|
125 | |
private static final long serialVersionUID = 1L; |
126 | |
|
127 | |
@XmlElement(name="roleMember") |
128 | |
private List<RoleMemberXmlDTO.WithinRole> roleMembers; |
129 | |
|
130 | |
@XmlTransient |
131 | |
private String roleId; |
132 | |
|
133 | |
@XmlTransient |
134 | |
private Set<String> existingRoleMemberIds; |
135 | |
|
136 | 0 | public WithinRole() {} |
137 | |
|
138 | 0 | public WithinRole(String roleId) { |
139 | 0 | this.roleId = roleId; |
140 | 0 | } |
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
@Override |
146 | |
public List<org.kuali.rice.kim.impl.jaxb.RoleMemberXmlDTO.WithinRole> getRoleMembers() { |
147 | 0 | return this.roleMembers; |
148 | |
} |
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
@Override |
154 | |
public void setRoleMembers(List<org.kuali.rice.kim.impl.jaxb.RoleMemberXmlDTO.WithinRole> roleMembers) { |
155 | 0 | this.roleMembers = roleMembers; |
156 | 0 | } |
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
public String getRoleId() { |
162 | 0 | return this.roleId; |
163 | |
} |
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
@Override |
169 | |
void beforeUnmarshal(Unmarshaller unmarshaller, Object parent) throws UnmarshalException { |
170 | 0 | if (parent instanceof RoleXmlDTO) { |
171 | |
|
172 | 0 | RoleXmlDTO parentRole = (RoleXmlDTO) parent; |
173 | 0 | if (!parentRole.isAlreadyPersisted()) { |
174 | 0 | RoleXmlUtil.validateAndPersistNewRole(parentRole); |
175 | |
} |
176 | 0 | roleId = parentRole.getRoleId(); |
177 | |
} |
178 | 0 | existingRoleMemberIds = new HashSet<String>(); |
179 | 0 | super.beforeUnmarshal(unmarshaller, parent); |
180 | 0 | } |
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
@Override |
188 | |
void afterUnmarshal(Unmarshaller unmarshaller, Object parent) throws UnmarshalException { |
189 | 0 | super.afterUnmarshal(unmarshaller, parent); |
190 | 0 | if (parent instanceof RoleXmlDTO) { |
191 | 0 | ((RoleXmlDTO)parent).setExistingRoleMemberIds(existingRoleMemberIds); |
192 | |
} |
193 | 0 | existingRoleMemberIds = null; |
194 | 0 | } |
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
@Override |
200 | |
public void newItemAdded(org.kuali.rice.kim.impl.jaxb.RoleMemberXmlDTO.WithinRole item) { |
201 | |
|
202 | |
try { |
203 | 0 | existingRoleMemberIds.add(RoleXmlUtil.validateAndPersistNewRoleMember(item)); |
204 | 0 | } catch (UnmarshalException e) { |
205 | 0 | throw new RuntimeException(e); |
206 | 0 | } |
207 | 0 | } |
208 | |
|
209 | |
void beforeMarshal(Marshaller marshaller) { |
210 | 0 | List<RoleMember> tempMembers = KimApiServiceLocator.getRoleService().findRoleMembers( |
211 | |
QueryByCriteria.Builder.fromPredicates(equal("roleId", roleId))).getResults(); |
212 | 0 | if (tempMembers != null && !tempMembers.isEmpty()) { |
213 | 0 | List<String> roleMemberIds = new ArrayList<String>(); |
214 | |
|
215 | 0 | for (RoleMemberContract tempMember : tempMembers) { |
216 | 0 | if (tempMember.isActive(null)) { |
217 | 0 | roleMemberIds.add(tempMember.getRoleMemberId()); |
218 | |
} |
219 | |
} |
220 | |
|
221 | 0 | if (!roleMemberIds.isEmpty()) { |
222 | 0 | setRoleMembers(new RiceXmlExportList<RoleMemberXmlDTO.WithinRole,String>(roleMemberIds, this)); |
223 | |
} |
224 | |
} |
225 | 0 | } |
226 | |
|
227 | |
void afterMarshal(Marshaller marshaller) { |
228 | 0 | setRoleMembers(null); |
229 | 0 | } |
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
@Override |
235 | |
public RoleMemberXmlDTO.WithinRole gettingNextItem(String nextItem, int index) { |
236 | 0 | return new RoleMemberXmlDTO.WithinRole(KimApiServiceLocator.getRoleService().findRoleMembers(QueryByCriteria.Builder.fromPredicates(equal("roleMemberId", nextItem))).getResults().get(0), false); |
237 | |
} |
238 | |
} |
239 | |
} |