1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.api.type; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.kuali.rice.core.api.CoreConstants; |
20 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
21 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
22 | |
import org.kuali.rice.kim.api.KimConstants; |
23 | |
import org.w3c.dom.Element; |
24 | |
|
25 | |
import javax.xml.bind.annotation.XmlAccessType; |
26 | |
import javax.xml.bind.annotation.XmlAccessorType; |
27 | |
import javax.xml.bind.annotation.XmlAnyElement; |
28 | |
import javax.xml.bind.annotation.XmlElement; |
29 | |
import javax.xml.bind.annotation.XmlRootElement; |
30 | |
import javax.xml.bind.annotation.XmlType; |
31 | |
import java.io.Serializable; |
32 | |
import java.util.ArrayList; |
33 | |
import java.util.Collection; |
34 | |
import java.util.Collections; |
35 | |
import java.util.List; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
@XmlRootElement(name = KimType.Constants.ROOT_ELEMENT_NAME) |
45 | |
@XmlAccessorType(XmlAccessType.NONE) |
46 | |
@XmlType(name = KimType.Constants.TYPE_NAME, propOrder = { |
47 | |
KimType.Elements.ID, |
48 | |
KimType.Elements.SERVICE_NAME, |
49 | |
KimType.Elements.NAMESPACE_CODE, |
50 | |
KimType.Elements.NAME, |
51 | |
KimType.Elements.ATTRIBUTE_DEFNS, |
52 | |
KimType.Elements.ACTIVE, |
53 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
54 | |
CoreConstants.CommonElements.OBJECT_ID, |
55 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
56 | |
}) |
57 | 0 | public final class KimType extends AbstractDataTransferObject implements KimTypeContract { |
58 | |
private static final long serialVersionUID = 1L; |
59 | |
|
60 | |
@XmlElement(name = KimType.Elements.ID, required = false) |
61 | |
private final String id; |
62 | |
|
63 | |
@XmlElement(name = KimType.Elements.SERVICE_NAME, required = false) |
64 | |
private final String serviceName; |
65 | |
|
66 | |
@XmlElement(name = KimType.Elements.NAMESPACE_CODE, required = false) |
67 | |
private final String namespaceCode; |
68 | |
|
69 | |
@XmlElement(name = KimType.Elements.NAME, required = false) |
70 | |
private final String name; |
71 | |
|
72 | |
@XmlElement(name = KimType.Elements.ATTRIBUTE_DEFNS, required = false) |
73 | |
private final List<KimTypeAttribute> attributeDefinitions; |
74 | |
|
75 | |
@XmlElement(name = KimType.Elements.ACTIVE, required = false) |
76 | |
private final boolean active; |
77 | |
|
78 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
79 | |
private final Long versionNumber; |
80 | |
|
81 | |
@XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false) |
82 | |
private final String objectId; |
83 | |
|
84 | 0 | @SuppressWarnings("unused") |
85 | |
@XmlAnyElement |
86 | |
private final Collection<Element> _futureElements = null; |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | 0 | private KimType() { |
92 | 0 | this.id = null; |
93 | 0 | this.serviceName = null; |
94 | 0 | this.namespaceCode = null; |
95 | 0 | this.name = null; |
96 | 0 | this.attributeDefinitions = Collections.<KimTypeAttribute>emptyList(); |
97 | 0 | this.active = false; |
98 | 0 | this.versionNumber = Long.valueOf(1L); |
99 | 0 | this.objectId = null; |
100 | 0 | } |
101 | |
|
102 | 0 | private KimType(Builder builder) { |
103 | 0 | this.id = builder.getId(); |
104 | 0 | this.serviceName = builder.getServiceName(); |
105 | 0 | this.namespaceCode = builder.getNamespaceCode(); |
106 | 0 | this.name = builder.getName(); |
107 | 0 | final List<KimTypeAttribute> temp = new ArrayList<KimTypeAttribute>(); |
108 | 0 | for (KimTypeAttribute.Builder attr : builder.getAttributeDefinitions()) { |
109 | |
|
110 | 0 | attr.setKimTypeId(this.id); |
111 | 0 | temp.add(attr.build()); |
112 | |
} |
113 | 0 | this.attributeDefinitions = Collections.unmodifiableList(temp); |
114 | |
|
115 | 0 | this.active = builder.isActive(); |
116 | 0 | this.versionNumber = builder.getVersionNumber(); |
117 | 0 | this.objectId = builder.getObjectId(); |
118 | 0 | } |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
public KimTypeAttribute getAttributeDefinitionById(String id) { |
134 | 0 | if (StringUtils.isBlank(id)) { |
135 | 0 | throw new IllegalArgumentException("id is blank"); |
136 | |
} |
137 | |
|
138 | 0 | if (this.attributeDefinitions != null) { |
139 | 0 | for (KimTypeAttribute att : this.attributeDefinitions) { |
140 | 0 | if (att != null && att.getKimAttribute() != null |
141 | |
&& id.equals(att.getKimAttribute().getId())) { |
142 | 0 | return att; |
143 | |
} |
144 | |
} |
145 | |
} |
146 | 0 | return null; |
147 | |
} |
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
public KimTypeAttribute getAttributeDefinitionByName(String name) { |
163 | 0 | if (StringUtils.isBlank(name)) { |
164 | 0 | throw new IllegalArgumentException("name is blank"); |
165 | |
} |
166 | |
|
167 | 0 | if (this.attributeDefinitions != null) { |
168 | 0 | for (KimTypeAttribute att : this.attributeDefinitions) { |
169 | 0 | if (att != null && att.getKimAttribute() != null |
170 | |
&& name.equals(att.getKimAttribute().getAttributeName())) { |
171 | 0 | return att; |
172 | |
} |
173 | |
} |
174 | |
} |
175 | 0 | return null; |
176 | |
} |
177 | |
|
178 | |
@Override |
179 | |
public String getId() { |
180 | 0 | return id; |
181 | |
} |
182 | |
|
183 | |
@Override |
184 | |
public String getServiceName() { |
185 | 0 | return serviceName; |
186 | |
} |
187 | |
|
188 | |
@Override |
189 | |
public String getNamespaceCode() { |
190 | 0 | return namespaceCode; |
191 | |
} |
192 | |
|
193 | |
@Override |
194 | |
public String getName() { |
195 | 0 | return name; |
196 | |
} |
197 | |
|
198 | |
@Override |
199 | |
public List<KimTypeAttribute> getAttributeDefinitions() { |
200 | 0 | return attributeDefinitions; |
201 | |
} |
202 | |
|
203 | |
@Override |
204 | |
public boolean isActive() { |
205 | 0 | return active; |
206 | |
} |
207 | |
|
208 | |
@Override |
209 | |
public Long getVersionNumber() { |
210 | 0 | return versionNumber; |
211 | |
} |
212 | |
|
213 | |
@Override |
214 | |
public String getObjectId() { |
215 | 0 | return objectId; |
216 | |
} |
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | 0 | public static final class Builder implements KimTypeContract, ModelBuilder, Serializable { |
222 | |
private String id; |
223 | |
private String serviceName; |
224 | |
private String namespaceCode; |
225 | |
private String name; |
226 | 0 | private List<KimTypeAttribute.Builder> attributeDefinitions = new ArrayList<KimTypeAttribute.Builder>(); |
227 | |
private boolean active; |
228 | 0 | private Long versionNumber = 1L; |
229 | |
private String objectId; |
230 | |
|
231 | 0 | private Builder() { |
232 | 0 | } |
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
public static Builder create() { |
238 | 0 | return new Builder(); |
239 | |
} |
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
public static Builder create(KimTypeContract contract) { |
245 | 0 | if (contract == null) { |
246 | 0 | throw new IllegalArgumentException("contract was null"); |
247 | |
} |
248 | 0 | Builder builder = new Builder(); |
249 | 0 | builder.setId(contract.getId()); |
250 | 0 | builder.setServiceName(contract.getServiceName()); |
251 | 0 | builder.setNamespaceCode(contract.getNamespaceCode()); |
252 | 0 | builder.setName(contract.getName()); |
253 | |
|
254 | 0 | if (contract.getAttributeDefinitions() != null) { |
255 | 0 | final List<KimTypeAttribute.Builder> temp = new ArrayList<KimTypeAttribute.Builder>(); |
256 | 0 | for (KimTypeAttributeContract attr : contract.getAttributeDefinitions()) { |
257 | 0 | temp.add(KimTypeAttribute.Builder.create(attr)); |
258 | |
} |
259 | |
|
260 | 0 | builder.setAttributeDefinitions(Collections.unmodifiableList(temp)); |
261 | |
} |
262 | |
|
263 | 0 | builder.setActive(contract.isActive()); |
264 | 0 | builder.setVersionNumber(contract.getVersionNumber()); |
265 | 0 | builder.setObjectId(contract.getObjectId()); |
266 | 0 | return builder; |
267 | |
} |
268 | |
|
269 | |
@Override |
270 | |
public String getId() { |
271 | 0 | return id; |
272 | |
} |
273 | |
|
274 | |
public void setId(final String id) { |
275 | 0 | this.id = id; |
276 | 0 | } |
277 | |
|
278 | |
@Override |
279 | |
public String getServiceName() { |
280 | 0 | return serviceName; |
281 | |
} |
282 | |
|
283 | |
public void setServiceName(final String serviceName) { |
284 | 0 | this.serviceName = serviceName; |
285 | 0 | } |
286 | |
|
287 | |
@Override |
288 | |
public String getNamespaceCode() { |
289 | 0 | return namespaceCode; |
290 | |
} |
291 | |
|
292 | |
public void setNamespaceCode(final String namespaceCode) { |
293 | 0 | this.namespaceCode = namespaceCode; |
294 | 0 | } |
295 | |
|
296 | |
@Override |
297 | |
public String getName() { |
298 | 0 | return name; |
299 | |
} |
300 | |
|
301 | |
public void setName(final String name) { |
302 | 0 | this.name = name; |
303 | 0 | } |
304 | |
|
305 | |
@Override |
306 | |
public List<KimTypeAttribute.Builder> getAttributeDefinitions() { |
307 | 0 | return attributeDefinitions; |
308 | |
} |
309 | |
|
310 | |
public void setAttributeDefinitions(final List<KimTypeAttribute.Builder> attributeDefinitions) { |
311 | 0 | if (attributeDefinitions == null) { |
312 | 0 | throw new IllegalArgumentException("attributeDefinitions is null"); |
313 | |
} |
314 | |
|
315 | 0 | this.attributeDefinitions = attributeDefinitions; |
316 | 0 | } |
317 | |
|
318 | |
@Override |
319 | |
public boolean isActive() { |
320 | 0 | return active; |
321 | |
} |
322 | |
|
323 | |
public void setActive(final boolean active) { |
324 | 0 | this.active = active; |
325 | 0 | } |
326 | |
|
327 | |
@Override |
328 | |
public Long getVersionNumber() { |
329 | 0 | return versionNumber; |
330 | |
} |
331 | |
|
332 | |
public void setVersionNumber(final Long versionNumber) { |
333 | 0 | if (versionNumber != null && versionNumber <= 0) { |
334 | 0 | throw new IllegalArgumentException("versionNumber is invalid"); |
335 | |
} |
336 | |
|
337 | 0 | this.versionNumber = versionNumber; |
338 | 0 | } |
339 | |
|
340 | |
@Override |
341 | |
public String getObjectId() { |
342 | 0 | return objectId; |
343 | |
} |
344 | |
|
345 | |
public void setObjectId(final String objectId) { |
346 | 0 | this.objectId = objectId; |
347 | 0 | } |
348 | |
|
349 | |
@Override |
350 | |
public KimType build() { |
351 | 0 | return new KimType(this); |
352 | |
} |
353 | |
} |
354 | |
|
355 | |
|
356 | |
|
357 | |
|
358 | 0 | static class Constants { |
359 | |
static final String ROOT_ELEMENT_NAME = "kimType"; |
360 | |
static final String TYPE_NAME = "KimTypeType"; |
361 | |
} |
362 | |
|
363 | |
|
364 | |
|
365 | |
|
366 | |
|
367 | 0 | static class Elements { |
368 | |
static final String ID = "id"; |
369 | |
static final String SERVICE_NAME = "serviceName"; |
370 | |
static final String NAMESPACE_CODE = "namespaceCode"; |
371 | |
static final String NAME = "name"; |
372 | |
static final String ATTRIBUTE_DEFNS = "attributeDefinitions"; |
373 | |
static final String ACTIVE = "active"; |
374 | |
} |
375 | |
|
376 | 0 | public static class Cache { |
377 | |
public static final String NAME = KimConstants.Namespaces.KIM_NAMESPACE_2_0 + "/" + KimType.Constants.TYPE_NAME; |
378 | |
} |
379 | |
} |