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 java.io.Serializable;
19 import java.util.Collection;
20 import javax.xml.bind.annotation.XmlAccessType;
21 import javax.xml.bind.annotation.XmlAccessorType;
22 import javax.xml.bind.annotation.XmlAnyElement;
23 import javax.xml.bind.annotation.XmlElement;
24 import javax.xml.bind.annotation.XmlRootElement;
25 import javax.xml.bind.annotation.XmlType;
26
27 import org.apache.commons.lang.StringUtils;
28 import org.kuali.rice.core.api.CoreConstants;
29 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
30 import org.kuali.rice.core.api.mo.ModelBuilder;
31 import org.w3c.dom.Element;
32
33 @XmlRootElement(name = EntityExternalIdentifier.Constants.ROOT_ELEMENT_NAME)
34 @XmlAccessorType(XmlAccessType.NONE)
35 @XmlType(name = EntityExternalIdentifier.Constants.TYPE_NAME, propOrder = {
36 EntityExternalIdentifier.Elements.ID,
37 EntityExternalIdentifier.Elements.ENTITY_ID,
38 EntityExternalIdentifier.Elements.EXTERNAL_IDENTIFIER_TYPE_CODE,
39 EntityExternalIdentifier.Elements.EXTERNAL_IDENTIFIER_TYPE,
40 EntityExternalIdentifier.Elements.EXTERNAL_ID,
41 CoreConstants.CommonElements.VERSION_NUMBER,
42 CoreConstants.CommonElements.OBJECT_ID,
43 CoreConstants.CommonElements.FUTURE_ELEMENTS
44 })
45 public final class EntityExternalIdentifier extends AbstractDataTransferObject
46 implements EntityExternalIdentifierContract
47 {
48 @XmlElement(name = Elements.ENTITY_ID, required = false)
49 private final String entityId;
50 @XmlElement(name = Elements.EXTERNAL_IDENTIFIER_TYPE_CODE, required = false)
51 private final String externalIdentifierTypeCode;
52 @XmlElement(name = Elements.EXTERNAL_IDENTIFIER_TYPE, required = false)
53 private final EntityExternalIdentifierType externalIdentifierType;
54 @XmlElement(name = Elements.EXTERNAL_ID, required = false)
55 private final String externalId;
56 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
57 private final Long versionNumber;
58 @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
59 private final String objectId;
60 @XmlElement(name = Elements.ID, required = false)
61 private final String id;
62 @SuppressWarnings("unused")
63 @XmlAnyElement
64 private final Collection<Element> _futureElements = null;
65
66
67
68
69
70 private EntityExternalIdentifier() {
71 this.entityId = null;
72 this.externalIdentifierTypeCode = null;
73 this.externalIdentifierType = null;
74 this.externalId = null;
75 this.versionNumber = null;
76 this.objectId = null;
77 this.id = null;
78 }
79
80 private EntityExternalIdentifier(Builder builder) {
81 this.entityId = builder.getEntityId();
82 this.externalIdentifierTypeCode = builder.getExternalIdentifierTypeCode();
83 this.externalIdentifierType = builder.getExternalIdentifierType() != null ? builder.getExternalIdentifierType().build() : null;
84 this.externalId = builder.getExternalId();
85 this.versionNumber = builder.getVersionNumber();
86 this.objectId = builder.getObjectId();
87 this.id = builder.getId();
88 }
89
90 @Override
91 public String getEntityId() {
92 return this.entityId;
93 }
94
95 @Override
96 public String getExternalIdentifierTypeCode() {
97 return this.externalIdentifierTypeCode;
98 }
99
100 @Override
101 public EntityExternalIdentifierType getExternalIdentifierType() {
102 return this.externalIdentifierType;
103 }
104
105 @Override
106 public String getExternalId() {
107 return this.externalId;
108 }
109
110 @Override
111 public Long getVersionNumber() {
112 return this.versionNumber;
113 }
114
115 @Override
116 public String getObjectId() {
117 return this.objectId;
118 }
119
120 @Override
121 public String getId() {
122 return this.id;
123 }
124
125
126
127
128
129 public final static class Builder
130 implements Serializable, ModelBuilder, EntityExternalIdentifierContract
131 {
132
133 private String entityId;
134 private String externalIdentifierTypeCode;
135 private EntityExternalIdentifierType.Builder externalIdentifierType;
136 private String externalId;
137 private Long versionNumber;
138 private String objectId;
139 private String id;
140
141 private Builder() { }
142
143 public static Builder create() {
144 return new Builder();
145 }
146
147 public static Builder create(EntityExternalIdentifierContract contract) {
148 if (contract == null) {
149 throw new IllegalArgumentException("contract was null");
150 }
151 Builder builder = create();
152 builder.setEntityId(contract.getEntityId());
153 builder.setExternalIdentifierTypeCode(contract.getExternalIdentifierTypeCode());
154 if (contract.getExternalIdentifierType() != null) {
155 builder.setExternalIdentifierType(
156 EntityExternalIdentifierType.Builder.create(contract.getExternalIdentifierType()));
157 }
158 builder.setExternalId(contract.getExternalId());
159 builder.setVersionNumber(contract.getVersionNumber());
160 builder.setObjectId(contract.getObjectId());
161 builder.setId(contract.getId());
162 return builder;
163 }
164
165 public EntityExternalIdentifier build() {
166 return new EntityExternalIdentifier(this);
167 }
168
169 @Override
170 public String getEntityId() {
171 return this.entityId;
172 }
173
174 @Override
175 public String getExternalIdentifierTypeCode() {
176 return this.externalIdentifierTypeCode;
177 }
178
179 @Override
180 public EntityExternalIdentifierType.Builder getExternalIdentifierType() {
181 return this.externalIdentifierType;
182 }
183
184 @Override
185 public String getExternalId() {
186 return this.externalId;
187 }
188
189 @Override
190 public Long getVersionNumber() {
191 return this.versionNumber;
192 }
193
194 @Override
195 public String getObjectId() {
196 return this.objectId;
197 }
198
199 @Override
200 public String getId() {
201 return this.id;
202 }
203
204 public void setEntityId(String entityId) {
205 this.entityId = entityId;
206 }
207
208 public void setExternalIdentifierTypeCode(String externalIdentifierTypeCode) {
209 this.externalIdentifierTypeCode = externalIdentifierTypeCode;
210 }
211
212 public void setExternalIdentifierType(EntityExternalIdentifierType.Builder externalIdentifierType) {
213 this.externalIdentifierType = externalIdentifierType;
214 }
215
216 public void setExternalId(String externalId) {
217 this.externalId = externalId;
218 }
219
220 public void setVersionNumber(Long versionNumber) {
221 this.versionNumber = versionNumber;
222 }
223
224 public void setObjectId(String objectId) {
225 this.objectId = objectId;
226 }
227
228 public void setId(String id) {
229 if (StringUtils.isWhitespace(id)) {
230 throw new IllegalArgumentException("id is blank");
231 }
232 this.id = id;
233 }
234
235 }
236
237
238
239
240
241
242 static class Constants {
243
244 final static String ROOT_ELEMENT_NAME = "entityExternalIdentifier";
245 final static String TYPE_NAME = "EntityExternalIdentifierType";
246 }
247
248
249
250
251
252
253 static class Elements {
254
255 final static String ENTITY_ID = "entityId";
256 final static String EXTERNAL_IDENTIFIER_TYPE = "externalIdentifierType";
257 final static String EXTERNAL_IDENTIFIER_TYPE_CODE = "externalIdentifierTypeCode";
258 final static String EXTERNAL_ID = "externalId";
259 final static String ID = "id";
260
261 }
262
263 }