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