1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.api.rule; |
17 | |
|
18 | |
import java.io.Serializable; |
19 | |
import java.util.ArrayList; |
20 | |
import java.util.Collection; |
21 | |
import java.util.Collections; |
22 | |
import java.util.List; |
23 | |
import javax.xml.bind.annotation.XmlAccessType; |
24 | |
import javax.xml.bind.annotation.XmlAccessorType; |
25 | |
import javax.xml.bind.annotation.XmlAnyElement; |
26 | |
import javax.xml.bind.annotation.XmlElement; |
27 | |
import javax.xml.bind.annotation.XmlRootElement; |
28 | |
import javax.xml.bind.annotation.XmlType; |
29 | |
|
30 | |
import org.apache.commons.collections.CollectionUtils; |
31 | |
import org.apache.commons.lang.StringUtils; |
32 | |
import org.kuali.rice.core.api.CoreConstants; |
33 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
34 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
35 | |
import org.kuali.rice.kew.api.KewApiConstants; |
36 | |
import org.w3c.dom.Element; |
37 | |
|
38 | 0 | @XmlRootElement(name = RuleTemplate.Constants.ROOT_ELEMENT_NAME) |
39 | |
@XmlAccessorType(XmlAccessType.NONE) |
40 | |
@XmlType(name = RuleTemplate.Constants.TYPE_NAME, propOrder = { |
41 | |
RuleTemplate.Elements.NAME, |
42 | |
RuleTemplate.Elements.DESCRIPTION, |
43 | |
RuleTemplate.Elements.DELEGATION_TEMPLATE, |
44 | |
RuleTemplate.Elements.RULE_TEMPLATE_ATTRIBUTES, |
45 | |
RuleTemplate.Elements.RULE_TEMPLATE_OPTIONS, |
46 | |
RuleTemplate.Elements.ID, |
47 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
48 | |
CoreConstants.CommonElements.OBJECT_ID, |
49 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
50 | |
}) |
51 | 0 | public final class RuleTemplate |
52 | |
extends AbstractDataTransferObject |
53 | |
implements RuleTemplateContract |
54 | |
{ |
55 | |
|
56 | |
@XmlElement(name = Elements.NAME, required = false) |
57 | |
private final String name; |
58 | |
@XmlElement(name = Elements.DESCRIPTION, required = false) |
59 | |
private final String description; |
60 | |
@XmlElement(name = Elements.DELEGATION_TEMPLATE, required = false) |
61 | |
private final RuleTemplate delegationTemplate; |
62 | |
@XmlElement(name = Elements.RULE_TEMPLATE_ATTRIBUTES, required = false) |
63 | |
private final List<RuleTemplateAttribute> ruleTemplateAttributes; |
64 | |
@XmlElement(name = Elements.RULE_TEMPLATE_OPTIONS, required = false) |
65 | |
private final List<RuleTemplateOption> ruleTemplateOptions; |
66 | |
@XmlElement(name = Elements.ID, required = false) |
67 | |
private final String id; |
68 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
69 | |
private final Long versionNumber; |
70 | |
@XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false) |
71 | |
private final String objectId; |
72 | 0 | @SuppressWarnings("unused") |
73 | |
@XmlAnyElement |
74 | |
private final Collection<Element> _futureElements = null; |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | 0 | private RuleTemplate() { |
81 | 0 | this.name = null; |
82 | 0 | this.description = null; |
83 | 0 | this.delegationTemplate = null; |
84 | 0 | this.ruleTemplateAttributes = null; |
85 | 0 | this.ruleTemplateOptions = null; |
86 | 0 | this.id = null; |
87 | 0 | this.versionNumber = null; |
88 | 0 | this.objectId = null; |
89 | 0 | } |
90 | |
|
91 | 0 | private RuleTemplate(Builder builder) { |
92 | 0 | this.name = builder.getName(); |
93 | 0 | this.description = builder.getDescription(); |
94 | 0 | this.delegationTemplate = builder.getDelegationTemplate() == null ? null : builder.getDelegationTemplate().build(); |
95 | 0 | if (CollectionUtils.isNotEmpty(builder.getRuleTemplateAttributes())) { |
96 | 0 | List<RuleTemplateAttribute> rta = new ArrayList<RuleTemplateAttribute>(); |
97 | 0 | for (RuleTemplateAttribute.Builder attribute : builder.getRuleTemplateAttributes()) { |
98 | 0 | rta.add(attribute.build()); |
99 | |
} |
100 | 0 | this.ruleTemplateAttributes = Collections.unmodifiableList(rta); |
101 | 0 | } else { |
102 | 0 | this.ruleTemplateAttributes = Collections.emptyList(); |
103 | |
} |
104 | 0 | if (CollectionUtils.isNotEmpty(builder.getRuleTemplateOptions())) { |
105 | 0 | List<RuleTemplateOption> rto = new ArrayList<RuleTemplateOption>(); |
106 | 0 | for (RuleTemplateOption.Builder option : builder.getRuleTemplateOptions()) { |
107 | 0 | rto.add(option.build()); |
108 | |
} |
109 | 0 | this.ruleTemplateOptions = Collections.unmodifiableList(rto); |
110 | 0 | } else { |
111 | 0 | this.ruleTemplateOptions = Collections.emptyList(); |
112 | |
} |
113 | 0 | this.id = builder.getId(); |
114 | 0 | this.versionNumber = builder.getVersionNumber(); |
115 | 0 | this.objectId = builder.getObjectId(); |
116 | 0 | } |
117 | |
|
118 | |
@Override |
119 | |
public String getName() { |
120 | 0 | return this.name; |
121 | |
} |
122 | |
|
123 | |
@Override |
124 | |
public String getDescription() { |
125 | 0 | return this.description; |
126 | |
} |
127 | |
|
128 | |
@Override |
129 | |
public RuleTemplate getDelegationTemplate() { |
130 | 0 | return this.delegationTemplate; |
131 | |
} |
132 | |
|
133 | |
@Override |
134 | |
public List<RuleTemplateAttribute> getRuleTemplateAttributes() { |
135 | 0 | return this.ruleTemplateAttributes; |
136 | |
} |
137 | |
|
138 | |
public List<RuleTemplateAttribute> getActiveRuleTemplateAttributes() { |
139 | 0 | List<RuleTemplateAttribute> activeAttributes = new ArrayList<RuleTemplateAttribute>(); |
140 | 0 | for (RuleTemplateAttribute templateAttribute : getRuleTemplateAttributes()) |
141 | |
{ |
142 | 0 | if (templateAttribute.isActive()) |
143 | |
{ |
144 | 0 | activeAttributes.add(templateAttribute); |
145 | |
} |
146 | |
} |
147 | 0 | Collections.sort(activeAttributes); |
148 | 0 | return activeAttributes; |
149 | |
} |
150 | |
|
151 | |
@Override |
152 | |
public List<RuleTemplateOption> getRuleTemplateOptions() { |
153 | 0 | return this.ruleTemplateOptions; |
154 | |
} |
155 | |
|
156 | |
@Override |
157 | |
public String getId() { |
158 | 0 | return this.id; |
159 | |
} |
160 | |
|
161 | |
@Override |
162 | |
public Long getVersionNumber() { |
163 | 0 | return this.versionNumber; |
164 | |
} |
165 | |
|
166 | |
@Override |
167 | |
public String getObjectId() { |
168 | 0 | return this.objectId; |
169 | |
} |
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | 0 | public final static class Builder |
177 | |
implements Serializable, ModelBuilder, RuleTemplateContract |
178 | |
{ |
179 | |
|
180 | |
private String name; |
181 | |
private String description; |
182 | |
private RuleTemplate.Builder delegationTemplate; |
183 | |
private List<RuleTemplateAttribute.Builder> ruleTemplateAttributes; |
184 | |
private List<RuleTemplateOption.Builder> ruleTemplateOptions; |
185 | |
private String id; |
186 | |
private Long versionNumber; |
187 | |
private String objectId; |
188 | |
|
189 | 0 | private Builder() { |
190 | |
|
191 | 0 | } |
192 | |
|
193 | |
public static Builder create() { |
194 | |
|
195 | 0 | return new Builder(); |
196 | |
} |
197 | |
|
198 | |
public static Builder create(RuleTemplateContract contract) { |
199 | 0 | if (contract == null) { |
200 | 0 | throw new IllegalArgumentException("contract was null"); |
201 | |
} |
202 | |
|
203 | 0 | Builder builder = create(); |
204 | 0 | builder.setName(contract.getName()); |
205 | 0 | builder.setDescription(contract.getDescription()); |
206 | 0 | builder.setDelegationTemplate( |
207 | |
contract.getDelegationTemplate() == null ? |
208 | |
null : RuleTemplate.Builder.create(contract.getDelegationTemplate())); |
209 | 0 | if (CollectionUtils.isNotEmpty(contract.getRuleTemplateAttributes())) { |
210 | 0 | List<RuleTemplateAttribute.Builder> attrs = new ArrayList<RuleTemplateAttribute.Builder>(); |
211 | 0 | for (RuleTemplateAttributeContract attr : contract.getRuleTemplateAttributes()) { |
212 | 0 | attrs.add(RuleTemplateAttribute.Builder.create(attr)); |
213 | |
} |
214 | 0 | builder.setRuleTemplateAttributes(attrs); |
215 | 0 | } else { |
216 | 0 | builder.setRuleTemplateAttributes(Collections.<RuleTemplateAttribute.Builder>emptyList()); |
217 | |
} |
218 | 0 | if (CollectionUtils.isNotEmpty(contract.getRuleTemplateOptions())) { |
219 | 0 | List<RuleTemplateOption.Builder> options = new ArrayList<RuleTemplateOption.Builder>(); |
220 | 0 | for (RuleTemplateOptionContract option : contract.getRuleTemplateOptions()) { |
221 | 0 | options.add(RuleTemplateOption.Builder.create(option)); |
222 | |
} |
223 | 0 | builder.setRuleTemplateOptions(options); |
224 | 0 | } else { |
225 | 0 | builder.setRuleTemplateOptions(Collections.<RuleTemplateOption.Builder>emptyList()); |
226 | |
} |
227 | 0 | builder.setId(contract.getId()); |
228 | 0 | builder.setVersionNumber(contract.getVersionNumber()); |
229 | 0 | builder.setObjectId(contract.getObjectId()); |
230 | 0 | return builder; |
231 | |
} |
232 | |
|
233 | |
public RuleTemplate build() { |
234 | 0 | return new RuleTemplate(this); |
235 | |
} |
236 | |
|
237 | |
@Override |
238 | |
public String getName() { |
239 | 0 | return this.name; |
240 | |
} |
241 | |
|
242 | |
@Override |
243 | |
public String getDescription() { |
244 | 0 | return this.description; |
245 | |
} |
246 | |
|
247 | |
@Override |
248 | |
public RuleTemplate.Builder getDelegationTemplate() { |
249 | 0 | return this.delegationTemplate; |
250 | |
} |
251 | |
|
252 | |
@Override |
253 | |
public List<RuleTemplateAttribute.Builder> getRuleTemplateAttributes() { |
254 | 0 | return this.ruleTemplateAttributes; |
255 | |
} |
256 | |
|
257 | |
@Override |
258 | |
public List<RuleTemplateOption.Builder> getRuleTemplateOptions() { |
259 | 0 | return this.ruleTemplateOptions; |
260 | |
} |
261 | |
|
262 | |
@Override |
263 | |
public String getId() { |
264 | 0 | return this.id; |
265 | |
} |
266 | |
|
267 | |
@Override |
268 | |
public Long getVersionNumber() { |
269 | 0 | return this.versionNumber; |
270 | |
} |
271 | |
|
272 | |
@Override |
273 | |
public String getObjectId() { |
274 | 0 | return this.objectId; |
275 | |
} |
276 | |
|
277 | |
public void setName(String name) { |
278 | 0 | if (StringUtils.isBlank(name)) { |
279 | 0 | throw new IllegalArgumentException("name is null or blank"); |
280 | |
} |
281 | 0 | this.name = name; |
282 | 0 | } |
283 | |
|
284 | |
public void setDescription(String description) { |
285 | 0 | this.description = description; |
286 | 0 | } |
287 | |
|
288 | |
public void setDelegationTemplate(RuleTemplate.Builder delegationTemplate) { |
289 | 0 | this.delegationTemplate = delegationTemplate; |
290 | 0 | } |
291 | |
|
292 | |
public void setRuleTemplateAttributes(List<RuleTemplateAttribute.Builder> ruleTemplateAttributes) { |
293 | 0 | this.ruleTemplateAttributes = Collections.unmodifiableList(ruleTemplateAttributes); |
294 | 0 | } |
295 | |
|
296 | |
public void setRuleTemplateOptions(List<RuleTemplateOption.Builder> ruleTemplateOptions) { |
297 | 0 | this.ruleTemplateOptions = Collections.unmodifiableList(ruleTemplateOptions); |
298 | 0 | } |
299 | |
|
300 | |
public void setId(String id) { |
301 | 0 | if (StringUtils.isWhitespace(id)) { |
302 | 0 | throw new IllegalArgumentException("id was whitespace"); |
303 | |
} |
304 | 0 | this.id = id; |
305 | 0 | } |
306 | |
|
307 | |
public void setVersionNumber(Long versionNumber) { |
308 | 0 | this.versionNumber = versionNumber; |
309 | 0 | } |
310 | |
|
311 | |
public void setObjectId(String objectId) { |
312 | 0 | this.objectId = objectId; |
313 | 0 | } |
314 | |
|
315 | |
} |
316 | |
|
317 | |
|
318 | |
|
319 | |
|
320 | |
|
321 | |
|
322 | 0 | static class Constants { |
323 | |
|
324 | |
final static String ROOT_ELEMENT_NAME = "ruleTemplate"; |
325 | |
final static String TYPE_NAME = "RuleTemplateType"; |
326 | |
|
327 | |
} |
328 | |
|
329 | |
|
330 | |
|
331 | |
|
332 | |
|
333 | |
|
334 | 0 | static class Elements { |
335 | |
|
336 | |
final static String NAME = "name"; |
337 | |
final static String DESCRIPTION = "description"; |
338 | |
final static String DELEGATION_TEMPLATE = "delegationTemplate"; |
339 | |
final static String RULE_TEMPLATE_ATTRIBUTES = "ruleTemplateAttributes"; |
340 | |
final static String RULE_TEMPLATE_OPTIONS = "ruleTemplateOptions"; |
341 | |
final static String ID = "id"; |
342 | |
|
343 | |
} |
344 | |
|
345 | 0 | public static class Cache { |
346 | |
public static final String NAME = KewApiConstants.Namespaces.KEW_NAMESPACE_2_0 + "/" + RuleTemplate.Constants.TYPE_NAME; |
347 | |
} |
348 | |
} |