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.lang.reflect.Type;
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.List;
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
31 import org.apache.commons.collections.CollectionUtils;
32 import org.apache.commons.lang.ObjectUtils;
33 import org.apache.commons.lang.StringUtils;
34 import org.apache.commons.lang.math.NumberUtils;
35 import org.kuali.rice.core.api.CoreConstants;
36 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
37 import org.kuali.rice.core.api.mo.ModelBuilder;
38 import org.kuali.rice.kew.api.KewApiConstants;
39 import org.w3c.dom.Element;
40
41 @XmlRootElement(name = RuleResponsibility.Constants.ROOT_ELEMENT_NAME)
42 @XmlAccessorType(XmlAccessType.NONE)
43 @XmlType(name = RuleResponsibility.Constants.TYPE_NAME, propOrder = {
44 RuleResponsibility.Elements.ID,
45 RuleResponsibility.Elements.PRIORITY,
46 RuleResponsibility.Elements.RESPONSIBILITY_ID,
47 RuleResponsibility.Elements.ACTION_REQUESTED_CD,
48 RuleResponsibility.Elements.APPROVE_POLICY,
49 RuleResponsibility.Elements.PRINCIPAL_ID,
50 RuleResponsibility.Elements.GROUP_ID,
51 RuleResponsibility.Elements.ROLE_NAME,
52 RuleResponsibility.Elements.DELEGATION_RULES,
53 RuleResponsibility.Elements.USING_ROLE,
54 RuleResponsibility.Elements.USING_GROUP,
55 RuleResponsibility.Elements.USING_PRINCIPAL,
56 CoreConstants.CommonElements.VERSION_NUMBER,
57 CoreConstants.CommonElements.OBJECT_ID,
58 CoreConstants.CommonElements.FUTURE_ELEMENTS
59 })
60 public final class RuleResponsibility
61 extends AbstractDataTransferObject
62 implements RuleResponsibilityContract
63 {
64 @XmlElement(name = Elements.ID, required = false)
65 private final String id;
66 @XmlElement(name = Elements.PRIORITY, required = false)
67 private final Integer priority;
68 @XmlElement(name = Elements.RESPONSIBILITY_ID, required = true)
69 private final String responsibilityId;
70 @XmlElement(name = Elements.ACTION_REQUESTED_CD, required = false)
71 private final String actionRequestedCd;
72 @XmlElement(name = Elements.APPROVE_POLICY, required = false)
73 private final String approvePolicy;
74 @XmlElement(name = Elements.PRINCIPAL_ID, required = false)
75 private final String principalId;
76 @XmlElement(name = Elements.GROUP_ID, required = false)
77 private final String groupId;
78 @XmlElement(name = Elements.ROLE_NAME, required = false)
79 private final String roleName;
80 @XmlElement(name = Elements.DELEGATION_RULES, required = false)
81 private final List<RuleDelegation> delegationRules;
82 @XmlElement(name = Elements.USING_ROLE, required = false)
83 private final boolean usingRole;
84 @XmlElement(name = Elements.USING_PRINCIPAL, required = false)
85 private final boolean usingPrincipal;
86 @XmlElement(name = Elements.USING_GROUP, required = false)
87 private final boolean usingGroup;
88 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
89 private final Long versionNumber;
90 @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
91 private final String objectId;
92 @SuppressWarnings("unused")
93 @XmlAnyElement
94 private final Collection<Element> _futureElements = null;
95
96
97
98
99
100 private RuleResponsibility() {
101 this.id = null;
102 this.priority = null;
103 this.responsibilityId = null;
104 this.actionRequestedCd = null;
105 this.approvePolicy = null;
106 this.principalId = null;
107 this.groupId = null;
108 this.roleName = null;
109 this.delegationRules = null;
110 this.usingGroup = false;
111 this.usingPrincipal = false;
112 this.usingRole = false;
113 this.versionNumber = null;
114 this.objectId = null;
115 }
116
117 private RuleResponsibility(Builder builder) {
118 this.id = builder.getId();
119 this.priority = builder.getPriority();
120 this.responsibilityId = builder.getResponsibilityId();
121 this.actionRequestedCd = builder.getActionRequestedCd();
122 this.approvePolicy = builder.getApprovePolicy();
123 this.principalId = builder.getPrincipalId();
124 this.groupId = builder.getGroupId();
125 this.roleName = builder.getRoleName();
126 if (CollectionUtils.isNotEmpty(builder.getDelegationRules())) {
127 List<RuleDelegation> delegationList = new ArrayList<RuleDelegation>();
128 for (RuleDelegation.Builder b : builder.getDelegationRules()) {
129 delegationList.add(b.build());
130 }
131 this.delegationRules = delegationList;
132 } else {
133 this.delegationRules = Collections.emptyList();
134 }
135 this.usingGroup = builder.isUsingGroup();
136 this.usingPrincipal = builder.isUsingPrincipal();
137 this.usingRole = builder.isUsingRole();
138 versionNumber = builder.getVersionNumber();
139 objectId = builder.getObjectId();
140 }
141
142 @Override
143 public String getId() {
144 return this.id;
145 }
146
147 @Override
148 public Integer getPriority() {
149 return this.priority;
150 }
151
152 @Override
153 public String getResponsibilityId() {
154 return this.responsibilityId;
155 }
156
157 @Override
158 public String getActionRequestedCd() {
159 return this.actionRequestedCd;
160 }
161
162 @Override
163 public String getApprovePolicy() {
164 return this.approvePolicy;
165 }
166
167 @Override
168 public String getPrincipalId() {
169 return this.principalId;
170 }
171
172 @Override
173 public String getGroupId() {
174 return this.groupId;
175 }
176
177 @Override
178 public String getRoleName() {
179 return this.roleName;
180 }
181
182 @Override
183 public List<RuleDelegation> getDelegationRules() {
184 return this.delegationRules;
185 }
186
187 @Override
188 public boolean isUsingRole() {
189 return this.usingRole;
190 }
191
192 @Override
193 public boolean isUsingPrincipal() {
194 return this.usingPrincipal;
195 }
196
197 @Override
198 public boolean isUsingGroup() {
199 return this.usingGroup;
200 }
201
202 @Override
203 public Long getVersionNumber() {
204 return versionNumber;
205 }
206
207 @Override
208 public String getObjectId() {
209 return objectId;
210 }
211
212 public String getRoleAttributeName() {
213 return getRoleName().substring(0, getRoleName().indexOf("!"));
214 }
215
216 public String getResolvedRoleName() {
217 if (isUsingRole()) {
218 return getRoleName().substring(getRoleName().indexOf("!") + 1, getRoleName().length());
219 }
220 return null;
221 }
222
223
224
225
226
227 public final static class Builder
228 implements Serializable, ModelBuilder, RuleResponsibilityContract
229 {
230 private String id;
231 private Integer priority;
232 private String responsibilityId;
233 private String actionRequestedCd;
234 private String approvePolicy;
235 private String principalId;
236 private String groupId;
237 private String roleName;
238 private List<RuleDelegation.Builder> delegationRules;
239 private boolean usingRole = false;
240 private boolean usingPrincipal = false;
241 private boolean usingGroup = false;
242 private Long versionNumber;
243 private String objectId;
244
245 private Builder() {
246 }
247
248 public static Builder create() {
249 return new Builder();
250 }
251
252 public static Builder create(RuleResponsibilityContract contract) {
253 if (contract == null) {
254 throw new IllegalArgumentException("contract was null");
255 }
256 Builder builder = create();
257 builder.setId(contract.getId());
258 builder.setPriority(contract.getPriority());
259 builder.setResponsibilityId(contract.getResponsibilityId());
260 builder.setActionRequestedCd(contract.getActionRequestedCd());
261 builder.setApprovePolicy(contract.getApprovePolicy());
262 builder.setPrincipalId(contract.getPrincipalId());
263 builder.setGroupId(contract.getGroupId());
264 builder.setRoleName(contract.getRoleName());
265 if (CollectionUtils.isNotEmpty(contract.getDelegationRules())) {
266 List<RuleDelegation.Builder> builders = new ArrayList<RuleDelegation.Builder>();
267 for (RuleDelegationContract delegationContract : contract.getDelegationRules()) {
268 builders.add(RuleDelegation.Builder.create(delegationContract));
269 }
270 builder.setDelegationRules(builders);
271 } else {
272 builder.setDelegationRules(Collections.<RuleDelegation.Builder>emptyList());
273 }
274 builder.setUsingGroup(contract.isUsingGroup());
275 builder.setUsingPrincipal(contract.isUsingPrincipal());
276 builder.setUsingRole(contract.isUsingRole());
277 builder.setVersionNumber(contract.getVersionNumber());
278 builder.setObjectId(contract.getObjectId());
279 return builder;
280 }
281
282 public RuleResponsibility build() {
283 return new RuleResponsibility(this);
284 }
285
286 @Override
287 public String getId() {
288 return this.id;
289 }
290
291 @Override
292 public Integer getPriority() {
293 return this.priority;
294 }
295
296 @Override
297 public String getResponsibilityId() {
298 return this.responsibilityId;
299 }
300
301 @Override
302 public String getActionRequestedCd() {
303 return this.actionRequestedCd;
304 }
305
306 @Override
307 public String getApprovePolicy() {
308 return this.approvePolicy;
309 }
310
311 @Override
312 public String getPrincipalId() {
313 return this.principalId;
314 }
315
316 @Override
317 public String getGroupId() {
318 return this.groupId;
319 }
320
321 @Override
322 public String getRoleName() {
323 return this.roleName;
324 }
325
326 @Override
327 public List<RuleDelegation.Builder> getDelegationRules() {
328 return this.delegationRules;
329 }
330
331 @Override
332 public boolean isUsingRole() {
333 return this.usingRole;
334 }
335
336 @Override
337 public boolean isUsingPrincipal() {
338 return this.usingPrincipal;
339 }
340
341 @Override
342 public boolean isUsingGroup() {
343 return this.usingGroup;
344 }
345
346 @Override
347 public Long getVersionNumber() {
348 return versionNumber;
349 }
350
351 @Override
352 public String getObjectId() {
353 return objectId;
354 }
355
356 public void setId(String id) {
357 if (StringUtils.isWhitespace(id)) {
358 throw new IllegalArgumentException("id is whitespace");
359 }
360 this.id = id;
361 }
362 public void setPriority(Integer priority) {
363 this.priority = priority;
364 }
365
366 public void setResponsibilityId(String responsibilityId) {
367 this.responsibilityId = responsibilityId;
368 }
369
370 public void setActionRequestedCd(String actionRequestedCd) {
371 this.actionRequestedCd = actionRequestedCd;
372 }
373
374 public void setApprovePolicy(String approvePolicy) {
375 this.approvePolicy = approvePolicy;
376 }
377
378 public void setPrincipalId(String principalId) {
379 this.principalId = principalId;
380 }
381
382 public void setGroupId(String groupId) {
383 this.groupId = groupId;
384 }
385
386 public void setRoleName(String roleName) {
387 this.roleName = roleName;
388 }
389
390 public void setDelegationRules(List<RuleDelegation.Builder> delegationRules) {
391 this.delegationRules = delegationRules;
392 }
393
394 private void setUsingRole(boolean usingRole) {
395 this.usingRole = usingRole;
396 }
397
398 private void setUsingPrincipal(boolean usingPrincipal) {
399 this.usingPrincipal = usingPrincipal;
400 }
401
402 private void setUsingGroup(boolean usingGroup) {
403 this.usingGroup = usingGroup;
404 }
405
406 public void setVersionNumber(Long versionNumber) {
407 this.versionNumber = versionNumber;
408 }
409
410 public void setObjectId(String objectId) {
411 this.objectId = objectId;
412 }
413
414
415 }
416
417 @Override
418 public boolean equals(Object o) {
419 if (o == null) { return false; }
420 if (!(o instanceof RuleResponsibilityContract)) { return false; }
421 RuleResponsibilityContract resp = (RuleResponsibilityContract) o;
422 return StringUtils.equals(getPrincipalId(), resp.getPrincipalId()) &&
423 StringUtils.equals(getRoleName(), resp.getRoleName()) &&
424 StringUtils.equals(getGroupId(), resp.getGroupId()) &&
425 StringUtils.equals(getActionRequestedCd(), resp.getActionRequestedCd()) &&
426 ObjectUtils.equals(getPriority(), resp.getPriority()) &&
427 StringUtils.equals(getApprovePolicy(), resp.getApprovePolicy());
428 }
429
430
431
432
433
434 static class Constants {
435
436 final static String ROOT_ELEMENT_NAME = "ruleResponsibility";
437 final static String TYPE_NAME = "RuleResponsibilityType";
438
439 }
440
441
442
443
444
445
446 static class Elements {
447 final static String ID = "id";
448 final static String PRIORITY = "priority";
449 final static String RESPONSIBILITY_ID = "responsibilityId";
450 final static String ACTION_REQUESTED_CD = "actionRequestedCd";
451 final static String APPROVE_POLICY = "approvePolicy";
452 final static String PRINCIPAL_ID = "principalId";
453 final static String GROUP_ID = "groupId";
454 final static String ROLE_NAME = "roleName";
455 final static String DELEGATION_RULES = "delegationRules";
456 final static String USING_ROLE = "usingRole";
457 final static String USING_PRINCIPAL = "usingPrincipal";
458 final static String USING_GROUP = "usingGroup";
459 }
460
461 public static class Cache {
462 public static final String NAME = KewApiConstants.Namespaces.KEW_NAMESPACE_2_0 + "/" + RuleResponsibility.Constants.TYPE_NAME;
463 }
464 }