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