1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.api.identity.external;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.joda.time.DateTime;
20 import org.kuali.rice.core.api.CoreConstants;
21 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
22 import org.kuali.rice.core.api.mo.ModelBuilder;
23 import org.kuali.rice.core.api.mo.common.active.InactivatableFromToUtils;
24 import org.kuali.rice.core.api.util.jaxb.DateTimeAdapter;
25 import org.w3c.dom.Element;
26
27 import javax.xml.bind.annotation.XmlAccessType;
28 import javax.xml.bind.annotation.XmlAccessorType;
29 import javax.xml.bind.annotation.XmlAnyElement;
30 import javax.xml.bind.annotation.XmlElement;
31 import javax.xml.bind.annotation.XmlRootElement;
32 import javax.xml.bind.annotation.XmlType;
33 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
34 import java.io.Serializable;
35 import java.util.Collection;
36
37 @XmlRootElement(name = EntityExternalIdentifierHistory.Constants.ROOT_ELEMENT_NAME)
38 @XmlAccessorType(XmlAccessType.NONE)
39 @XmlType(name = EntityExternalIdentifierHistory.Constants.TYPE_NAME, propOrder = {
40 EntityExternalIdentifierHistory.Elements.ID,
41 EntityExternalIdentifierHistory.Elements.ENTITY_ID,
42 EntityExternalIdentifierHistory.Elements.EXTERNAL_IDENTIFIER_TYPE_CODE,
43 EntityExternalIdentifierHistory.Elements.EXTERNAL_IDENTIFIER_TYPE,
44 EntityExternalIdentifierHistory.Elements.EXTERNAL_ID,
45 CoreConstants.CommonElements.HISTORY_ID,
46 CoreConstants.CommonElements.ACTIVE_FROM_DATE,
47 CoreConstants.CommonElements.ACTIVE_TO_DATE,
48 CoreConstants.CommonElements.VERSION_NUMBER,
49 CoreConstants.CommonElements.OBJECT_ID,
50 CoreConstants.CommonElements.FUTURE_ELEMENTS
51 })
52 public final class EntityExternalIdentifierHistory extends AbstractDataTransferObject
53 implements EntityExternalIdentifierHistoryContract
54 {
55 @XmlElement(name = Elements.ENTITY_ID, required = false)
56 private final String entityId;
57 @XmlElement(name = Elements.EXTERNAL_IDENTIFIER_TYPE_CODE, required = false)
58 private final String externalIdentifierTypeCode;
59 @XmlElement(name = Elements.EXTERNAL_IDENTIFIER_TYPE, required = false)
60 private final EntityExternalIdentifierTypeHistory externalIdentifierType;
61 @XmlElement(name = Elements.EXTERNAL_ID, required = false)
62 private final String externalId;
63 @XmlElement(name = CoreConstants.CommonElements.HISTORY_ID, required = false)
64 private final Long historyId;
65 @XmlElement(name = CoreConstants.CommonElements.ACTIVE_FROM_DATE, required = false)
66 @XmlJavaTypeAdapter(DateTimeAdapter.class)
67 private final DateTime activeFromDate;
68 @XmlElement(name = CoreConstants.CommonElements.ACTIVE_TO_DATE, required = false)
69 @XmlJavaTypeAdapter(DateTimeAdapter.class)
70 private final DateTime activeToDate;
71 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
72 private final Long versionNumber;
73 @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
74 private final String objectId;
75 @XmlElement(name = Elements.ID, required = false)
76 private final String id;
77 @SuppressWarnings("unused")
78 @XmlAnyElement
79 private final Collection<Element> _futureElements = null;
80
81
82
83
84
85 private EntityExternalIdentifierHistory() {
86 this.entityId = null;
87 this.externalIdentifierTypeCode = null;
88 this.externalIdentifierType = null;
89 this.externalId = null;
90 this.versionNumber = null;
91 this.objectId = null;
92 this.id = null;
93 this.historyId = null;
94 this.activeFromDate = null;
95 this.activeToDate = null;
96 }
97
98 private EntityExternalIdentifierHistory(Builder builder) {
99 this.entityId = builder.getEntityId();
100 this.externalIdentifierTypeCode = builder.getExternalIdentifierTypeCode();
101 this.externalIdentifierType = builder.getExternalIdentifierType() != null ? builder.getExternalIdentifierType().build() : null;
102 this.externalId = builder.getExternalId();
103 this.versionNumber = builder.getVersionNumber();
104 this.objectId = builder.getObjectId();
105 this.id = builder.getId();
106 this.historyId = builder.getHistoryId();
107 this.activeFromDate = builder.getActiveFromDate();
108 this.activeToDate = builder.getActiveToDate();
109 }
110
111 @Override
112 public String getEntityId() {
113 return this.entityId;
114 }
115
116 @Override
117 public String getExternalIdentifierTypeCode() {
118 return this.externalIdentifierTypeCode;
119 }
120
121 @Override
122 public EntityExternalIdentifierTypeHistory getExternalIdentifierType() {
123 return this.externalIdentifierType;
124 }
125
126 @Override
127 public String getExternalId() {
128 return this.externalId;
129 }
130
131 @Override
132 public Long getVersionNumber() {
133 return this.versionNumber;
134 }
135
136 @Override
137 public String getObjectId() {
138 return this.objectId;
139 }
140
141 @Override
142 public String getId() {
143 return this.id;
144 }
145
146 @Override
147 public Long getHistoryId() {
148 return this.historyId;
149 }
150
151 @Override
152 public DateTime getActiveFromDate() {
153 return this.activeFromDate;
154 }
155
156 @Override
157 public DateTime getActiveToDate() {
158 return this.activeToDate;
159 }
160
161 @Override
162 public boolean isActiveNow() {
163 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, null);
164 }
165
166 @Override
167 public boolean isActive(DateTime activeAsOf) {
168 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, activeAsOf);
169 }
170
171 @Override
172 public boolean isActive() {
173 return isActiveNow();
174 }
175
176
177
178
179
180 public final static class Builder
181 implements Serializable, ModelBuilder, EntityExternalIdentifierHistoryContract
182 {
183
184 private String entityId;
185 private String externalIdentifierTypeCode;
186 private EntityExternalIdentifierTypeHistory.Builder externalIdentifierType;
187 private String externalId;
188 private Long versionNumber;
189 private String objectId;
190 private String id;
191 private Long historyId;
192 private DateTime activeFromDate;
193 private DateTime activeToDate;
194
195 private Builder() { }
196
197 public static Builder create() {
198 return new Builder();
199 }
200
201 public static Builder create(EntityExternalIdentifierHistoryContract contract) {
202 if (contract == null) {
203 throw new IllegalArgumentException("contract was null");
204 }
205 Builder builder = create();
206 builder.setEntityId(contract.getEntityId());
207 builder.setExternalIdentifierTypeCode(contract.getExternalIdentifierTypeCode());
208 if (contract.getExternalIdentifierType() != null) {
209 builder.setExternalIdentifierType(
210 EntityExternalIdentifierTypeHistory.Builder.create(contract.getExternalIdentifierType()));
211 }
212 builder.setExternalId(contract.getExternalId());
213 builder.setVersionNumber(contract.getVersionNumber());
214 builder.setObjectId(contract.getObjectId());
215 builder.setId(contract.getId());
216 builder.setHistoryId(contract.getHistoryId());
217 builder.setActiveFromDate(contract.getActiveFromDate());
218 builder.setActiveToDate(contract.getActiveToDate());
219 return builder;
220 }
221
222 public EntityExternalIdentifierHistory build() {
223 return new EntityExternalIdentifierHistory(this);
224 }
225
226 @Override
227 public String getEntityId() {
228 return this.entityId;
229 }
230
231 @Override
232 public String getExternalIdentifierTypeCode() {
233 return this.externalIdentifierTypeCode;
234 }
235
236 @Override
237 public EntityExternalIdentifierTypeHistory.Builder getExternalIdentifierType() {
238 return this.externalIdentifierType;
239 }
240
241 @Override
242 public String getExternalId() {
243 return this.externalId;
244 }
245
246 @Override
247 public Long getVersionNumber() {
248 return this.versionNumber;
249 }
250
251 @Override
252 public String getObjectId() {
253 return this.objectId;
254 }
255
256 @Override
257 public String getId() {
258 return this.id;
259 }
260
261 @Override
262 public Long getHistoryId() {
263 return this.historyId;
264 }
265
266 @Override
267 public boolean isActiveNow() {
268 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, null);
269 }
270
271 @Override
272 public boolean isActive(DateTime activeAsOf) {
273 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, activeAsOf);
274 }
275
276 @Override
277 public DateTime getActiveFromDate() {
278 return this.activeFromDate;
279 }
280
281 @Override
282 public boolean isActive() {
283 return isActiveNow();
284 }
285
286 @Override
287 public DateTime getActiveToDate() {
288 return this.activeToDate;
289 }
290
291 public void setHistoryId(Long historyId) {
292 this.historyId = historyId;
293 }
294
295 public void setActiveFromDate(DateTime activeFromDate) {
296 this.activeFromDate = activeFromDate;
297 }
298
299 public void setActiveToDate(DateTime activeToDate) {
300 this.activeToDate = activeToDate;
301 }
302
303 public void setEntityId(String entityId) {
304 this.entityId = entityId;
305 }
306
307 public void setExternalIdentifierTypeCode(String externalIdentifierTypeCode) {
308 this.externalIdentifierTypeCode = externalIdentifierTypeCode;
309 }
310
311 public void setExternalIdentifierType(EntityExternalIdentifierTypeHistory.Builder externalIdentifierType) {
312 this.externalIdentifierType = externalIdentifierType;
313 }
314
315 public void setExternalId(String externalId) {
316 this.externalId = externalId;
317 }
318
319 public void setVersionNumber(Long versionNumber) {
320 this.versionNumber = versionNumber;
321 }
322
323 public void setObjectId(String objectId) {
324 this.objectId = objectId;
325 }
326
327 public void setId(String id) {
328 if (StringUtils.isWhitespace(id)) {
329 throw new IllegalArgumentException("id is blank");
330 }
331 this.id = id;
332 }
333
334 }
335
336
337
338
339
340
341 static class Constants {
342
343 final static String ROOT_ELEMENT_NAME = "entityExternalIdentifier";
344 final static String TYPE_NAME = "EntityExternalIdentifierType";
345 }
346
347
348
349
350
351
352 static class Elements {
353
354 final static String ENTITY_ID = "entityId";
355 final static String EXTERNAL_IDENTIFIER_TYPE = "externalIdentifierType";
356 final static String EXTERNAL_IDENTIFIER_TYPE_CODE = "externalIdentifierTypeCode";
357 final static String EXTERNAL_ID = "externalId";
358 final static String ID = "id";
359
360 }
361
362 }