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