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