1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kim.api.common.attribute;
18
19 import org.apache.commons.lang.StringUtils;
20 import org.apache.commons.lang.builder.EqualsBuilder;
21 import org.apache.commons.lang.builder.HashCodeBuilder;
22 import org.apache.commons.lang.builder.ToStringBuilder;
23 import org.kuali.rice.core.api.CoreConstants;
24 import org.kuali.rice.core.api.mo.ModelBuilder;
25 import org.kuali.rice.core.api.mo.ModelObjectComplete;
26 import org.kuali.rice.kim.api.type.KimType;
27 import org.w3c.dom.Element;
28
29 import javax.xml.bind.annotation.XmlAccessType;
30 import javax.xml.bind.annotation.XmlAccessorType;
31 import javax.xml.bind.annotation.XmlAnyElement;
32 import javax.xml.bind.annotation.XmlElement;
33 import javax.xml.bind.annotation.XmlRootElement;
34 import javax.xml.bind.annotation.XmlType;
35 import java.io.Serializable;
36 import java.util.Collection;
37
38
39 @XmlRootElement(name = KimAttributeData.Constants.ROOT_ELEMENT_NAME)
40 @XmlAccessorType(XmlAccessType.NONE)
41 @XmlType(name = KimAttributeData.Constants.TYPE_NAME, propOrder = {
42 KimAttributeData.Elements.ID,
43 KimAttributeData.Elements.ASSIGNED_TO_ID,
44 KimAttributeData.Elements.KIM_TYPE_ID,
45 KimAttributeData.Elements.KIM_TYPE,
46 KimAttributeData.Elements.KIM_ATTRIBUTE,
47 KimAttributeData.Elements.ATTRIBUTE_VALUE,
48 CoreConstants.CommonElements.VERSION_NUMBER,
49 CoreConstants.CommonElements.OBJECT_ID,
50 CoreConstants.CommonElements.FUTURE_ELEMENTS
51 })
52 public final class KimAttributeData implements KimAttributeDataContract, ModelObjectComplete {
53 @XmlElement(name = Elements.ID, required = false)
54 private final String id;
55
56 @XmlElement(name = Elements.ASSIGNED_TO_ID, required = false)
57 private final String assignedToId;
58
59 @XmlElement(name = Elements.KIM_TYPE_ID, required = true)
60 private final String kimTypeId;
61
62 @XmlElement(name = Elements.KIM_TYPE, required = false)
63 private final KimType kimType;
64
65 @XmlElement(name = Elements.KIM_ATTRIBUTE, required = false)
66 private final KimAttribute kimAttribute;
67
68 @XmlElement(name = Elements.ATTRIBUTE_VALUE, required = false)
69 private final String attributeValue;
70
71 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
72 private final Long versionNumber;
73
74 @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
75 private final String objectId;
76
77 @SuppressWarnings("unused")
78 @XmlAnyElement
79 private final Collection<Element> _futureElements = null;
80
81 @SuppressWarnings("unused")
82 private KimAttributeData() {
83 this.id = null;
84 this.assignedToId = null;
85 this.kimTypeId = null;
86 this.kimType = null;
87 this.kimAttribute = null;
88 this.attributeValue = null;
89 this.versionNumber = null;
90 this.objectId = null;
91 }
92
93 private KimAttributeData(Builder builder) {
94 this.id = builder.getId();
95 this.assignedToId = builder.getAssignedToId();
96 this.kimTypeId = builder.getKimTypeId();
97 this.kimType =
98 builder.getKimType() != null ? builder.getKimType().build() : null;
99 this.kimAttribute =
100 builder.getKimAttribute() != null ? builder.getKimAttribute().build() : null;
101 this.attributeValue = builder.getAttributeValue();
102 this.versionNumber = builder.getVersionNumber();
103 this.objectId = builder.getObjectId();
104 }
105
106 @Override
107 public String getId() {
108 return id;
109 }
110
111 @Override
112 public String getAssignedToId() {
113 return assignedToId;
114 }
115
116 @Override
117 public String getKimTypeId() {
118 return kimTypeId;
119 }
120
121 @Override
122 public KimType getKimType() {
123 return kimType;
124 }
125
126 @Override
127 public KimAttribute getKimAttribute() {
128 return kimAttribute;
129 }
130
131 @Override
132 public String getAttributeValue() {
133 return attributeValue;
134 }
135
136 @Override
137 public Long getVersionNumber() {
138 return versionNumber;
139 }
140
141 @Override
142 public String getObjectId() {
143 return objectId;
144 }
145
146 @Override
147 public int hashCode() {
148 return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
149 }
150
151 @Override
152 public boolean equals(Object obj) {
153 return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
154 }
155
156 @Override
157 public String toString() {
158 return ToStringBuilder.reflectionToString(this);
159 }
160
161 public static final class Builder implements KimAttributeDataContract, ModelBuilder, Serializable {
162 private String id;
163 private String assignedToId;
164 private String kimTypeId;
165 private KimType.Builder kimType;
166 private KimAttribute.Builder kimAttribute;
167 private String attributeValue;
168 private Long versionNumber;
169 private String objectId;
170
171 private Builder(String kimTypeId) {
172 setKimTypeId(kimTypeId);
173 }
174
175
176
177
178 public static Builder create(String kimTypeId) {
179 return new Builder(kimTypeId);
180 }
181
182
183
184
185 public static Builder create(KimAttributeDataContract contract) {
186 Builder builder = new Builder(contract.getKimTypeId());
187 builder.setAssignedToId(contract.getAssignedToId());
188
189 builder.setId(contract.getId());
190 if (contract.getKimAttribute() != null) {
191 builder.setKimAttribute(KimAttribute.Builder.create(contract.getKimAttribute()));
192 }
193 if (contract.getKimType() != null) {
194 builder.setKimType(KimType.Builder.create(contract.getKimType()));
195 }
196 builder.setValue(contract.getAttributeValue());
197 builder.setVersionNumber(contract.getVersionNumber());
198 builder.setObjectId(contract.getObjectId());
199 return builder;
200 }
201
202 @Override
203 public String getId() {
204 return id;
205 }
206
207 public void setId(final String id) {
208 if (StringUtils.isWhitespace(id)) {
209 throw new IllegalArgumentException("id is blank");
210 }
211 this.id = id;
212 }
213
214 @Override
215 public String getAssignedToId() {
216 return assignedToId;
217 }
218
219 public void setAssignedToId(final String assignedToId) {
220 this.assignedToId = assignedToId;
221 }
222
223 @Override
224 public String getKimTypeId(){
225 return kimTypeId;
226 }
227
228 public void setKimTypeId(String kimTypeId) {
229 this.kimTypeId = kimTypeId;
230 }
231
232 @Override
233 public KimType.Builder getKimType() {
234 return kimType;
235 }
236
237 public void setKimType(final KimType.Builder kimType) {
238 this.kimType = kimType;
239 }
240
241 @Override
242 public KimAttribute.Builder getKimAttribute() {
243 return kimAttribute;
244 }
245
246 public void setKimAttribute(final KimAttribute.Builder kimAttribute) {
247 this.kimAttribute = kimAttribute;
248 }
249
250 @Override
251 public String getAttributeValue() {
252 return attributeValue;
253 }
254
255 public void setValue(final String attributeValue) {
256 this.attributeValue = attributeValue;
257 }
258
259 @Override
260 public Long getVersionNumber() {
261 return versionNumber;
262 }
263
264 public void setVersionNumber(Long versionNumber) {
265 this.versionNumber = versionNumber;
266 }
267
268 @Override
269 public String getObjectId() {
270 return objectId;
271 }
272
273 public void setObjectId(final String objectId) {
274 this.objectId = objectId;
275 }
276
277 @Override
278 public KimAttributeData build() {
279 return new KimAttributeData(this);
280 }
281 }
282
283
284
285
286 static class Constants {
287 final static String ROOT_ELEMENT_NAME = "kimAttributeData";
288 final static String TYPE_NAME = "KimAttributeDataType";
289 final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS};
290 }
291
292
293
294
295
296 static class Elements {
297 final static String ID = "id";
298 final static String ASSIGNED_TO_ID = "assignedToId";
299 final static String KIM_TYPE_ID = "kimTypeId";
300 final static String KIM_TYPE = "kimType";
301 final static String KIM_ATTRIBUTE = "kimAttribute";
302 final static String ATTRIBUTE_VALUE = "attributeValue";
303 }
304 }