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