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