1 | |
package org.kuali.rice.krms.api.repository.action; |
2 | |
|
3 | |
import java.io.Serializable; |
4 | |
import java.util.Collection; |
5 | |
import java.util.Collections; |
6 | |
import java.util.HashMap; |
7 | |
import java.util.Map; |
8 | |
|
9 | |
import javax.xml.bind.annotation.XmlAccessType; |
10 | |
import javax.xml.bind.annotation.XmlAccessorType; |
11 | |
import javax.xml.bind.annotation.XmlAnyElement; |
12 | |
import javax.xml.bind.annotation.XmlElement; |
13 | |
import javax.xml.bind.annotation.XmlRootElement; |
14 | |
import javax.xml.bind.annotation.XmlType; |
15 | |
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
16 | |
|
17 | |
import org.apache.commons.lang.StringUtils; |
18 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
19 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
20 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
21 | |
import org.kuali.rice.core.api.CoreConstants; |
22 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
23 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
24 | |
import org.kuali.rice.core.util.jaxb.MapStringStringAdapter; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
@XmlRootElement(name = ActionDefinition.Constants.ROOT_ELEMENT_NAME) |
34 | |
@XmlAccessorType(XmlAccessType.NONE) |
35 | |
@XmlType(name = ActionDefinition.Constants.TYPE_NAME, propOrder = { |
36 | |
ActionDefinition.Elements.ID, |
37 | |
ActionDefinition.Elements.NAME, |
38 | |
ActionDefinition.Elements.NAMESPACE, |
39 | |
ActionDefinition.Elements.DESC, |
40 | |
ActionDefinition.Elements.TYPE_ID, |
41 | |
ActionDefinition.Elements.RULE_ID, |
42 | |
ActionDefinition.Elements.SEQUENCE_NUMBER, |
43 | |
ActionDefinition.Elements.ATTRIBUTES, |
44 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
45 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
46 | |
}) |
47 | 3 | public final class ActionDefinition implements ActionDefinitionContract, ModelObjectComplete{ |
48 | |
private static final long serialVersionUID = 2783959459503209577L; |
49 | |
|
50 | |
@XmlElement(name = Elements.ID, required=true) |
51 | |
private String id; |
52 | |
@XmlElement(name = Elements.NAME, required=true) |
53 | |
private String name; |
54 | |
@XmlElement(name = Elements.NAMESPACE, required=true) |
55 | |
private String namespace; |
56 | |
@XmlElement(name = Elements.DESC, required=true) |
57 | |
private String description; |
58 | |
@XmlElement(name = Elements.TYPE_ID, required=true) |
59 | |
private String typeId; |
60 | |
@XmlElement(name = Elements.RULE_ID, required=true) |
61 | |
private String ruleId; |
62 | |
@XmlElement(name = Elements.SEQUENCE_NUMBER, required=true) |
63 | |
private Integer sequenceNumber; |
64 | |
|
65 | |
@XmlElement(name = Elements.ATTRIBUTES, required = false) |
66 | |
@XmlJavaTypeAdapter(value = MapStringStringAdapter.class) |
67 | |
private final Map<String, String> attributes; |
68 | |
|
69 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
70 | |
private final Long versionNumber; |
71 | |
|
72 | 6 | @SuppressWarnings("unused") |
73 | |
@XmlAnyElement |
74 | |
private final Collection<org.w3c.dom.Element> _futureElements = null; |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | 3 | private ActionDefinition() { |
82 | 3 | this.id = null; |
83 | 3 | this.name = null; |
84 | 3 | this.namespace = null; |
85 | 3 | this.description = null; |
86 | 3 | this.typeId = null; |
87 | 3 | this.ruleId = null; |
88 | 3 | this.sequenceNumber = null; |
89 | 3 | this.attributes = null; |
90 | 3 | this.versionNumber = null; |
91 | 3 | } |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | 3 | private ActionDefinition(Builder builder) { |
100 | 3 | this.id = builder.getId(); |
101 | 3 | this.name = builder.getName(); |
102 | 3 | this.namespace = builder.getNamespace(); |
103 | 3 | this.description = builder.getDescription(); |
104 | 3 | this.typeId = builder.getTypeId(); |
105 | 3 | this.ruleId = builder.getRuleId(); |
106 | 3 | this.sequenceNumber = builder.getSequenceNumber(); |
107 | 3 | if (builder.attributes != null){ |
108 | 3 | this.attributes = Collections.unmodifiableMap(builder.getAttributes()); |
109 | |
} else { |
110 | 0 | this.attributes = null; |
111 | |
} |
112 | 3 | this.versionNumber = builder.getVersionNumber(); |
113 | 3 | } |
114 | |
|
115 | |
@Override |
116 | |
public String getId() { |
117 | 1 | return this.id; |
118 | |
} |
119 | |
|
120 | |
@Override |
121 | |
public String getName() { |
122 | 0 | return this.name; |
123 | |
} |
124 | |
|
125 | |
@Override |
126 | |
public String getNamespace() { |
127 | 0 | return this.namespace; |
128 | |
} |
129 | |
|
130 | |
@Override |
131 | |
public String getDescription() { |
132 | 0 | return this.description; |
133 | |
} |
134 | |
|
135 | |
@Override |
136 | |
public String getTypeId() { |
137 | 0 | return this.typeId; |
138 | |
} |
139 | |
|
140 | |
@Override |
141 | |
public String getRuleId() { |
142 | 1 | return this.ruleId; |
143 | |
} |
144 | |
|
145 | |
@Override |
146 | |
public Integer getSequenceNumber() { |
147 | 0 | return this.sequenceNumber; |
148 | |
} |
149 | |
|
150 | |
@Override |
151 | |
public Map<String, String> getAttributes() { |
152 | 0 | return this.attributes; |
153 | |
} |
154 | |
|
155 | |
@Override |
156 | |
public Long getVersionNumber() { |
157 | 0 | return versionNumber; |
158 | |
} |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | 6 | public static class Builder implements ActionDefinitionContract, ModelBuilder, Serializable { |
164 | |
private static final long serialVersionUID = -6773634512570180267L; |
165 | |
|
166 | |
private String id; |
167 | |
private String name; |
168 | |
private String namespace; |
169 | |
private String description; |
170 | |
private String typeId; |
171 | |
private String ruleId; |
172 | |
private Integer sequenceNumber; |
173 | |
private Map<String, String> attributes; |
174 | |
private Long versionNumber; |
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | 22 | private Builder(String actionId, String name, String namespace, String typeId, String ruleId, Integer sequenceNumber) { |
180 | 22 | setId(actionId); |
181 | 20 | setName(name); |
182 | 16 | setNamespace(namespace); |
183 | 13 | setTypeId(typeId); |
184 | 10 | setRuleId(ruleId); |
185 | 7 | setSequenceNumber(sequenceNumber); |
186 | 6 | setAttributes(new HashMap<String, String>()); |
187 | 6 | } |
188 | |
|
189 | |
public static Builder create(String actionId, String name, String namespace, String typeId, String ruleId, Integer sequenceNumber){ |
190 | 22 | return new Builder(actionId, name, namespace, typeId, ruleId, sequenceNumber); |
191 | |
} |
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
public static Builder create(ActionDefinitionContract contract) { |
199 | 0 | if (contract == null) { |
200 | 0 | throw new IllegalArgumentException("contract is null"); |
201 | |
} |
202 | 0 | Builder builder = new Builder(contract.getId(), contract.getName(), |
203 | |
contract.getNamespace(), contract.getTypeId(), contract.getRuleId(), |
204 | |
contract.getSequenceNumber()); |
205 | 0 | builder.setDescription(contract.getDescription()); |
206 | 0 | if (contract.getAttributes() != null){ |
207 | 0 | builder.setAttributes(new HashMap<String, String>(contract.getAttributes())); |
208 | |
} |
209 | 0 | builder.setVersionNumber(contract.getVersionNumber()); |
210 | 0 | return builder; |
211 | |
} |
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
public void setId(String actionId) { |
221 | 22 | if (actionId != null && StringUtils.isBlank(actionId)) { |
222 | 2 | throw new IllegalArgumentException("action ID must be null or non-blank"); |
223 | |
} |
224 | 20 | this.id = actionId; |
225 | 20 | } |
226 | |
|
227 | |
|
228 | |
public void setName(String name) { |
229 | 20 | if (StringUtils.isBlank(name)) { |
230 | 4 | throw new IllegalArgumentException("name is blank"); |
231 | |
} |
232 | 16 | this.name = name; |
233 | 16 | } |
234 | |
|
235 | |
public void setNamespace(String namespace) { |
236 | 16 | if (StringUtils.isBlank(namespace)) { |
237 | 3 | throw new IllegalArgumentException("namespace is blank"); |
238 | |
} |
239 | 13 | this.namespace = namespace; |
240 | 13 | } |
241 | |
|
242 | |
public void setDescription(String desc) { |
243 | 4 | this.description = desc; |
244 | 4 | } |
245 | |
|
246 | |
public void setTypeId(String typeId) { |
247 | 13 | if (StringUtils.isBlank(typeId)) { |
248 | 3 | throw new IllegalArgumentException("KRMS type id is blank"); |
249 | |
} |
250 | 10 | this.typeId = typeId; |
251 | 10 | } |
252 | |
|
253 | |
public void setRuleId(String ruleId) { |
254 | 10 | if (StringUtils.isBlank(ruleId)) { |
255 | 3 | throw new IllegalArgumentException("rule id is blank"); |
256 | |
} |
257 | 7 | this.ruleId = ruleId; |
258 | 7 | } |
259 | |
|
260 | |
public void setSequenceNumber(Integer sequenceNumber) { |
261 | 7 | if (sequenceNumber == null) { |
262 | 1 | throw new IllegalArgumentException("sequence number is null"); |
263 | |
} |
264 | 6 | this.sequenceNumber = sequenceNumber; |
265 | 6 | } |
266 | |
|
267 | |
public void setAttributes(Map<String, String> attributes){ |
268 | 9 | if (attributes == null){ |
269 | 0 | this.attributes = Collections.emptyMap(); |
270 | |
} |
271 | 9 | this.attributes = Collections.unmodifiableMap(attributes); |
272 | 9 | } |
273 | |
|
274 | |
public void setVersionNumber(Long versionNumber){ |
275 | 0 | this.versionNumber = versionNumber; |
276 | 0 | } |
277 | |
|
278 | |
@Override |
279 | |
public String getId() { |
280 | 3 | return id; |
281 | |
} |
282 | |
|
283 | |
@Override |
284 | |
public String getName() { |
285 | 3 | return name; |
286 | |
} |
287 | |
|
288 | |
@Override |
289 | |
public String getNamespace() { |
290 | 3 | return namespace; |
291 | |
} |
292 | |
|
293 | |
@Override |
294 | |
public String getDescription() { |
295 | 3 | return description; |
296 | |
} |
297 | |
|
298 | |
@Override |
299 | |
public String getTypeId() { |
300 | 3 | return typeId; |
301 | |
} |
302 | |
|
303 | |
@Override |
304 | |
public String getRuleId() { |
305 | 3 | return ruleId; |
306 | |
} |
307 | |
|
308 | |
@Override |
309 | |
public Integer getSequenceNumber() { |
310 | 3 | return sequenceNumber; |
311 | |
} |
312 | |
|
313 | |
@Override |
314 | |
public Map<String, String> getAttributes() { |
315 | 3 | return attributes; |
316 | |
} |
317 | |
|
318 | |
@Override |
319 | |
public Long getVersionNumber() { |
320 | 3 | return versionNumber; |
321 | |
} |
322 | |
|
323 | |
|
324 | |
|
325 | |
|
326 | |
|
327 | |
|
328 | |
@Override |
329 | |
public ActionDefinition build() { |
330 | 3 | return new ActionDefinition(this); |
331 | |
} |
332 | |
|
333 | |
} |
334 | |
@Override |
335 | |
public int hashCode() { |
336 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
337 | |
} |
338 | |
|
339 | |
@Override |
340 | |
public boolean equals(Object obj) { |
341 | 1 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
342 | |
} |
343 | |
|
344 | |
@Override |
345 | |
public String toString() { |
346 | 0 | return ToStringBuilder.reflectionToString(this); |
347 | |
} |
348 | |
|
349 | |
|
350 | |
|
351 | |
|
352 | 0 | static class Constants { |
353 | |
final static String ROOT_ELEMENT_NAME = "action"; |
354 | |
final static String TYPE_NAME = "ActionType"; |
355 | 1 | final static String[] HASH_CODE_EQUALS_EXCLUDE = { CoreConstants.CommonElements.FUTURE_ELEMENTS }; |
356 | |
} |
357 | |
|
358 | |
|
359 | |
|
360 | |
|
361 | |
|
362 | 0 | public static class Elements { |
363 | |
final static String ID = "id"; |
364 | |
final static String NAME = "name"; |
365 | |
final static String NAMESPACE = "namespace"; |
366 | |
final static String DESC = "description"; |
367 | |
final static String TYPE_ID = "typeId"; |
368 | |
final static String RULE_ID = "ruleId"; |
369 | |
final static String SEQUENCE_NUMBER = "sequenceNumber"; |
370 | |
final static String ATTRIBUTES = "attributes"; |
371 | |
} |
372 | |
|
373 | |
} |