1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.api.identity.entity; |
17 | |
|
18 | |
import org.apache.commons.collections.CollectionUtils; |
19 | |
import org.kuali.rice.core.api.CoreConstants; |
20 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
21 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
22 | |
import org.kuali.rice.kim.api.KimConstants; |
23 | |
import org.kuali.rice.kim.api.identity.EntityUtils; |
24 | |
import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliation; |
25 | |
import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliationContract; |
26 | |
import org.kuali.rice.kim.api.identity.employment.EntityEmployment; |
27 | |
import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifier; |
28 | |
import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifierContract; |
29 | |
import org.kuali.rice.kim.api.identity.name.EntityName; |
30 | |
import org.kuali.rice.kim.api.identity.principal.Principal; |
31 | |
import org.kuali.rice.kim.api.identity.principal.PrincipalContract; |
32 | |
import org.kuali.rice.kim.api.identity.privacy.EntityPrivacyPreferences; |
33 | |
import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfoContract; |
34 | |
import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfoDefault; |
35 | |
import org.w3c.dom.Element; |
36 | |
|
37 | |
import javax.xml.bind.annotation.XmlAccessType; |
38 | |
import javax.xml.bind.annotation.XmlAccessorType; |
39 | |
import javax.xml.bind.annotation.XmlAnyElement; |
40 | |
import javax.xml.bind.annotation.XmlElement; |
41 | |
import javax.xml.bind.annotation.XmlElementWrapper; |
42 | |
import javax.xml.bind.annotation.XmlRootElement; |
43 | |
import javax.xml.bind.annotation.XmlType; |
44 | |
import java.io.Serializable; |
45 | |
import java.util.ArrayList; |
46 | |
import java.util.Collection; |
47 | |
import java.util.Collections; |
48 | |
import java.util.List; |
49 | |
|
50 | |
@XmlRootElement(name = EntityDefault.Constants.ROOT_ELEMENT_NAME) |
51 | |
@XmlAccessorType(XmlAccessType.NONE) |
52 | |
@XmlType(name = EntityDefault.Constants.TYPE_NAME, propOrder = { |
53 | |
EntityDefault.Elements.ENTITY_ID, |
54 | |
EntityDefault.Elements.NAME, |
55 | |
EntityDefault.Elements.PRINCIPALS, |
56 | |
EntityDefault.Elements.ENTITY_TYPE_CONTACT_INFOS, |
57 | |
EntityDefault.Elements.AFFILIATIONS, |
58 | |
EntityDefault.Elements.DEFAULT_AFFILIATION, |
59 | |
EntityDefault.Elements.EMPLOYMENT, |
60 | |
EntityDefault.Elements.EXTERNAL_IDENTIFIERS, |
61 | |
EntityDefault.Elements.PRIVACY_PREFERENCES, |
62 | |
EntityDefault.Elements.ACTIVE, |
63 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
64 | |
}) |
65 | |
public class EntityDefault extends AbstractDataTransferObject { |
66 | |
@XmlElement(name = Elements.ENTITY_ID, required = false) |
67 | |
private final String entityId; |
68 | |
@XmlElement(name = Elements.NAME, required = false) |
69 | |
private final EntityName name; |
70 | |
@XmlElementWrapper(name = Elements.PRINCIPALS, required = false) |
71 | |
@XmlElement(name = Elements.PRINCIPAL, required = false) |
72 | |
private final List<Principal> principals; |
73 | |
@XmlElementWrapper(name = Elements.ENTITY_TYPE_CONTACT_INFOS, required = false) |
74 | |
@XmlElement(name = Elements.ENTITY_TYPE_CONTACT_INFO, required = false) |
75 | |
private final List<EntityTypeContactInfoDefault> entityTypeContactInfos; |
76 | |
@XmlElementWrapper(name = Elements.AFFILIATIONS, required = false) |
77 | |
@XmlElement(name = Elements.AFFILIATION, required = false) |
78 | |
private final List<EntityAffiliation> affiliations; |
79 | |
@XmlElement(name = Elements.DEFAULT_AFFILIATION, required = false) |
80 | |
private final EntityAffiliation defaultAffiliation; |
81 | |
@XmlElement(name = Elements.EMPLOYMENT, required = false) |
82 | |
private final EntityEmployment employment; |
83 | |
@XmlElementWrapper(name = Elements.EXTERNAL_IDENTIFIERS, required = false) |
84 | |
@XmlElement(name = Elements.EXTERNAL_IDENTIFIER, required = false) |
85 | |
private final List<EntityExternalIdentifier> externalIdentifiers; |
86 | |
@XmlElement(name = Elements.PRIVACY_PREFERENCES, required = false) |
87 | |
private final EntityPrivacyPreferences privacyPreferences; |
88 | |
@XmlElement(name = Elements.ACTIVE, required = false) |
89 | |
private final boolean active; |
90 | 0 | @SuppressWarnings("unused") |
91 | |
@XmlAnyElement |
92 | |
private final Collection<Element> _futureElements = null; |
93 | |
|
94 | 0 | private EntityDefault() { |
95 | 0 | entityId = null; |
96 | 0 | name = null; |
97 | 0 | principals = null; |
98 | 0 | affiliations = null; |
99 | 0 | defaultAffiliation = null; |
100 | 0 | entityTypeContactInfos = null; |
101 | 0 | employment = null; |
102 | 0 | externalIdentifiers = null; |
103 | 0 | privacyPreferences = null; |
104 | 0 | active = false; |
105 | 0 | } |
106 | |
|
107 | |
public EntityDefault(String entityId, EntityName name, List<Principal> principals, |
108 | |
List<EntityTypeContactInfoDefault> entityTypes, List<EntityAffiliation> affiliations, |
109 | |
EntityAffiliation defaultAffiliation, EntityEmployment employment, |
110 | 0 | List<EntityExternalIdentifier> externalIdentifiers, EntityPrivacyPreferences privacyPreferences, boolean active) { |
111 | 0 | this.entityId = entityId; |
112 | 0 | this.name = name; |
113 | 0 | this.principals = principals; |
114 | 0 | this.entityTypeContactInfos = entityTypes; |
115 | 0 | this.affiliations = affiliations; |
116 | 0 | this.defaultAffiliation = defaultAffiliation; |
117 | 0 | this.employment = employment; |
118 | 0 | this.externalIdentifiers = externalIdentifiers; |
119 | 0 | this.privacyPreferences = privacyPreferences; |
120 | 0 | this.active = active; |
121 | 0 | } |
122 | |
|
123 | 0 | public EntityDefault(Builder builder) { |
124 | 0 | this.entityId = builder.entityId; |
125 | 0 | this.name = builder.getName() == null ? null : builder.getName().build(); |
126 | 0 | this.principals = new ArrayList<Principal>(); |
127 | 0 | if (CollectionUtils.isNotEmpty(builder.getPrincipals())) { |
128 | 0 | for (Principal.Builder principal : builder.getPrincipals()) { |
129 | 0 | this.principals.add(principal.build()); |
130 | |
} |
131 | |
} |
132 | 0 | this.entityTypeContactInfos = new ArrayList<EntityTypeContactInfoDefault>(); |
133 | 0 | if (CollectionUtils.isNotEmpty(builder.getEntityTypeContactInfos())) { |
134 | 0 | for (EntityTypeContactInfoDefault.Builder entityType : builder.getEntityTypeContactInfos()) { |
135 | 0 | this.entityTypeContactInfos.add(entityType.build()); |
136 | |
} |
137 | |
} |
138 | 0 | this.affiliations = new ArrayList<EntityAffiliation>(); |
139 | 0 | if (CollectionUtils.isNotEmpty(builder.getAffiliations())) { |
140 | 0 | for (EntityAffiliation.Builder affiliation : builder.getAffiliations()) { |
141 | 0 | this.affiliations.add(affiliation.build()); |
142 | |
} |
143 | |
} |
144 | 0 | if (builder.getDefaultAffiliation() == null |
145 | |
&& CollectionUtils.isNotEmpty(this.affiliations)) { |
146 | 0 | this.defaultAffiliation = EntityUtils.getDefaultItem(this.affiliations); |
147 | |
} else { |
148 | 0 | this.defaultAffiliation = builder.getDefaultAffiliation() == null ? null : builder.getDefaultAffiliation().build(); |
149 | |
} |
150 | 0 | this.employment = builder.getEmployment() == null ? null : builder.getEmployment().build(); |
151 | 0 | this.externalIdentifiers = new ArrayList<EntityExternalIdentifier>(); |
152 | 0 | if (CollectionUtils.isNotEmpty(builder.getExternalIdentifiers())) { |
153 | 0 | for (EntityExternalIdentifier.Builder externalId : builder.getExternalIdentifiers()) { |
154 | 0 | this.externalIdentifiers.add(externalId.build()); |
155 | |
} |
156 | |
} |
157 | 0 | this.privacyPreferences = builder.getPrivacyPreferences() == null ? null : builder.getPrivacyPreferences().build(); |
158 | 0 | this.active = builder.isActive(); |
159 | 0 | } |
160 | |
|
161 | |
public String getEntityId() { |
162 | 0 | return entityId; |
163 | |
} |
164 | |
|
165 | |
public EntityName getName() { |
166 | 0 | return name; |
167 | |
} |
168 | |
|
169 | |
public List<Principal> getPrincipals() { |
170 | 0 | return Collections.unmodifiableList(principals); |
171 | |
} |
172 | |
|
173 | |
public List<EntityTypeContactInfoDefault> getEntityTypeContactInfos() { |
174 | 0 | return Collections.unmodifiableList(entityTypeContactInfos); |
175 | |
} |
176 | |
|
177 | |
public List<EntityAffiliation> getAffiliations() { |
178 | 0 | return Collections.unmodifiableList(affiliations); |
179 | |
} |
180 | |
|
181 | |
public EntityAffiliation getDefaultAffiliation() { |
182 | 0 | return defaultAffiliation; |
183 | |
} |
184 | |
|
185 | |
public EntityEmployment getEmployment() { |
186 | 0 | return employment; |
187 | |
} |
188 | |
|
189 | |
public List<EntityExternalIdentifier> getExternalIdentifiers() { |
190 | 0 | return Collections.unmodifiableList(externalIdentifiers); |
191 | |
} |
192 | |
|
193 | |
public EntityPrivacyPreferences getPrivacyPreferences() { |
194 | 0 | return privacyPreferences; |
195 | |
} |
196 | |
|
197 | |
public boolean isActive() { |
198 | 0 | return active; |
199 | |
} |
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
public EntityTypeContactInfoDefault getEntityType(String entityTypeCode) { |
207 | 0 | if (entityTypeContactInfos == null) { |
208 | 0 | return null; |
209 | |
} |
210 | 0 | for (EntityTypeContactInfoDefault entType : entityTypeContactInfos) { |
211 | 0 | if (entType.getEntityTypeCode().equals(entityTypeCode)) { |
212 | 0 | return entType; |
213 | |
} |
214 | |
} |
215 | 0 | return null; |
216 | |
} |
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | 0 | public final static class Builder |
224 | |
implements Serializable, ModelBuilder |
225 | |
{ |
226 | |
private String entityId; |
227 | |
private EntityName.Builder name; |
228 | |
private List<Principal.Builder> principals; |
229 | |
private List<EntityTypeContactInfoDefault.Builder> entityTypeContactInfos; |
230 | |
private List<EntityAffiliation.Builder> affiliations; |
231 | |
private EntityAffiliation.Builder defaultAffiliation; |
232 | |
private EntityEmployment.Builder employment; |
233 | |
private List<EntityExternalIdentifier.Builder> externalIdentifiers; |
234 | |
private EntityPrivacyPreferences.Builder privacyPreferences; |
235 | |
private boolean active; |
236 | |
|
237 | 0 | private Builder() { } |
238 | |
|
239 | |
public static Builder create() { |
240 | 0 | return new Builder(); |
241 | |
} |
242 | |
|
243 | |
public static Builder create(String entityId) { |
244 | 0 | Builder builder = new Builder(); |
245 | 0 | builder.setEntityId(entityId); |
246 | 0 | return builder; |
247 | |
} |
248 | |
|
249 | |
public static Builder create(EntityContract contract) { |
250 | 0 | if (contract == null) { |
251 | 0 | throw new IllegalArgumentException("contract was null"); |
252 | |
} |
253 | 0 | Builder builder = new Builder(); |
254 | 0 | builder.setEntityId(contract.getId()); |
255 | 0 | builder.setActive(contract.isActive()); |
256 | 0 | List<Principal.Builder> principalBuilders = new ArrayList<Principal.Builder>(); |
257 | 0 | for ( PrincipalContract p : contract.getPrincipals() ) { |
258 | 0 | principalBuilders.add( Principal.Builder.create(p) ); |
259 | |
} |
260 | 0 | builder.setPrincipals(principalBuilders); |
261 | |
|
262 | 0 | builder.setPrivacyPreferences(contract.getPrivacyPreferences() == null ? |
263 | |
EntityPrivacyPreferences.Builder.create(contract.getId()) : EntityPrivacyPreferences.Builder.create(contract.getPrivacyPreferences())); |
264 | |
|
265 | 0 | builder.setName(contract.getDefaultName() == null ? null : EntityName.Builder.create(contract.getDefaultName())); |
266 | 0 | List<EntityTypeContactInfoDefault.Builder> typeBuilders = new ArrayList<EntityTypeContactInfoDefault.Builder>(); |
267 | 0 | for ( EntityTypeContactInfoContract etContract : contract.getEntityTypeContactInfos() ) { |
268 | 0 | typeBuilders.add(EntityTypeContactInfoDefault.Builder.create(etContract)); |
269 | |
} |
270 | 0 | builder.setEntityTypeContactInfos(typeBuilders); |
271 | |
|
272 | 0 | List<EntityAffiliation.Builder> affiliationBuilders = new ArrayList<EntityAffiliation.Builder>( ); |
273 | 0 | for ( EntityAffiliationContract aff : contract.getAffiliations() ) { |
274 | 0 | affiliationBuilders.add(EntityAffiliation.Builder.create(aff)); |
275 | 0 | if ( aff.isActive() && aff.isDefaultValue() ) { |
276 | 0 | builder.setDefaultAffiliation( EntityAffiliation.Builder.create(aff) ); |
277 | |
} |
278 | |
} |
279 | 0 | builder.setAffiliations(affiliationBuilders); |
280 | |
|
281 | 0 | builder.setEmployment(contract.getPrimaryEmployment() == null ? null : EntityEmployment.Builder.create(contract.getPrimaryEmployment()) ); |
282 | 0 | List<EntityExternalIdentifier.Builder> externalIdBuilders = new ArrayList<EntityExternalIdentifier.Builder>(); |
283 | 0 | for ( EntityExternalIdentifierContract id : contract.getExternalIdentifiers() ) { |
284 | 0 | externalIdBuilders.add( EntityExternalIdentifier.Builder.create(id) ); |
285 | |
} |
286 | 0 | builder.setExternalIdentifiers( externalIdBuilders ); |
287 | |
|
288 | 0 | return builder; |
289 | |
} |
290 | |
|
291 | |
public EntityDefault build() { |
292 | 0 | return new EntityDefault(this); |
293 | |
} |
294 | |
|
295 | |
public String getEntityId() { |
296 | 0 | return entityId; |
297 | |
} |
298 | |
|
299 | |
public void setEntityId(String entityId) { |
300 | 0 | this.entityId = entityId; |
301 | 0 | } |
302 | |
|
303 | |
public EntityName.Builder getName() { |
304 | 0 | return name; |
305 | |
} |
306 | |
|
307 | |
public void setName(EntityName.Builder name) { |
308 | 0 | this.name = name; |
309 | 0 | } |
310 | |
|
311 | |
public List<Principal.Builder> getPrincipals() { |
312 | 0 | return principals; |
313 | |
} |
314 | |
|
315 | |
public void setPrincipals(List<Principal.Builder> principals) { |
316 | 0 | this.principals = principals; |
317 | 0 | } |
318 | |
|
319 | |
public List<EntityTypeContactInfoDefault.Builder> getEntityTypeContactInfos() { |
320 | 0 | return entityTypeContactInfos; |
321 | |
} |
322 | |
|
323 | |
public void setEntityTypeContactInfos(List<EntityTypeContactInfoDefault.Builder> entityTypeContactInfos) { |
324 | 0 | this.entityTypeContactInfos = entityTypeContactInfos; |
325 | 0 | } |
326 | |
|
327 | |
public List<EntityAffiliation.Builder> getAffiliations() { |
328 | 0 | return affiliations; |
329 | |
} |
330 | |
|
331 | |
public void setAffiliations(List<EntityAffiliation.Builder> affiliations) { |
332 | 0 | this.affiliations = affiliations; |
333 | 0 | } |
334 | |
|
335 | |
public EntityAffiliation.Builder getDefaultAffiliation() { |
336 | 0 | return defaultAffiliation; |
337 | |
} |
338 | |
|
339 | |
public void setDefaultAffiliation(EntityAffiliation.Builder defaultAffiliation) { |
340 | 0 | this.defaultAffiliation = defaultAffiliation; |
341 | 0 | } |
342 | |
|
343 | |
public EntityEmployment.Builder getEmployment() { |
344 | 0 | return employment; |
345 | |
} |
346 | |
|
347 | |
public void setEmployment(EntityEmployment.Builder employment) { |
348 | 0 | this.employment = employment; |
349 | 0 | } |
350 | |
|
351 | |
public List<EntityExternalIdentifier.Builder> getExternalIdentifiers() { |
352 | 0 | return externalIdentifiers; |
353 | |
} |
354 | |
|
355 | |
public void setExternalIdentifiers(List<EntityExternalIdentifier.Builder> externalIdentifiers) { |
356 | 0 | this.externalIdentifiers = externalIdentifiers; |
357 | 0 | } |
358 | |
|
359 | |
public EntityPrivacyPreferences.Builder getPrivacyPreferences() { |
360 | 0 | return privacyPreferences; |
361 | |
} |
362 | |
|
363 | |
public void setPrivacyPreferences(EntityPrivacyPreferences.Builder privacyPreferences) { |
364 | 0 | this.privacyPreferences = privacyPreferences; |
365 | 0 | } |
366 | |
|
367 | |
public boolean isActive() { |
368 | 0 | return this.active; |
369 | |
} |
370 | |
|
371 | |
public void setActive(boolean active) { |
372 | 0 | this.active = active; |
373 | 0 | } |
374 | |
} |
375 | |
|
376 | |
|
377 | |
|
378 | |
|
379 | 0 | static class Constants { |
380 | |
|
381 | |
final static String ROOT_ELEMENT_NAME = "entityDefault"; |
382 | |
final static String TYPE_NAME = "EntityDefaultType"; |
383 | |
} |
384 | |
|
385 | |
|
386 | |
|
387 | |
|
388 | |
|
389 | |
|
390 | 0 | static class Elements { |
391 | |
final static String ENTITY_ID = "entityId"; |
392 | |
final static String NAME = "name"; |
393 | |
final static String PRINCIPALS = "principals"; |
394 | |
final static String PRINCIPAL = "principal"; |
395 | |
final static String ENTITY_TYPE_CONTACT_INFOS = "entityTypeContactInfos"; |
396 | |
final static String ENTITY_TYPE_CONTACT_INFO = "entityTypeContactInfo"; |
397 | |
final static String AFFILIATIONS = "affiliations"; |
398 | |
final static String AFFILIATION = "affiliation"; |
399 | |
final static String DEFAULT_AFFILIATION = "defaultAffiliation"; |
400 | |
final static String EMPLOYMENT = "employment"; |
401 | |
final static String EXTERNAL_IDENTIFIERS = "externalIdentifiers"; |
402 | |
final static String EXTERNAL_IDENTIFIER = "externalIdentifier"; |
403 | |
final static String PRIVACY_PREFERENCES = "privacyPreferences"; |
404 | |
final static String ACTIVE = "active"; |
405 | |
|
406 | |
} |
407 | |
|
408 | 0 | public static class Cache { |
409 | |
public static final String NAME = KimConstants.Namespaces.KIM_NAMESPACE_2_0 + "/" + EntityDefault.Constants.TYPE_NAME; |
410 | |
} |
411 | |
} |