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 | 0 | 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 | 0 | @SuppressWarnings("unused") |
93 | |
@XmlAnyElement |
94 | |
private final Collection<Element> _futureElements = null; |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | 0 | private RuleResponsibility() { |
101 | 0 | this.id = null; |
102 | 0 | this.priority = null; |
103 | 0 | this.responsibilityId = null; |
104 | 0 | this.actionRequestedCd = null; |
105 | 0 | this.approvePolicy = null; |
106 | 0 | this.principalId = null; |
107 | 0 | this.groupId = null; |
108 | 0 | this.roleName = null; |
109 | 0 | this.delegationRules = null; |
110 | 0 | this.usingGroup = false; |
111 | 0 | this.usingPrincipal = false; |
112 | 0 | this.usingRole = false; |
113 | 0 | this.versionNumber = null; |
114 | 0 | this.objectId = null; |
115 | 0 | } |
116 | |
|
117 | 0 | private RuleResponsibility(Builder builder) { |
118 | 0 | this.id = builder.getId(); |
119 | 0 | this.priority = builder.getPriority(); |
120 | 0 | this.responsibilityId = builder.getResponsibilityId(); |
121 | 0 | this.actionRequestedCd = builder.getActionRequestedCd(); |
122 | 0 | this.approvePolicy = builder.getApprovePolicy(); |
123 | 0 | this.principalId = builder.getPrincipalId(); |
124 | 0 | this.groupId = builder.getGroupId(); |
125 | 0 | this.roleName = builder.getRoleName(); |
126 | 0 | if (CollectionUtils.isNotEmpty(builder.getDelegationRules())) { |
127 | 0 | List<RuleDelegation> delegationList = new ArrayList<RuleDelegation>(); |
128 | 0 | for (RuleDelegation.Builder b : builder.getDelegationRules()) { |
129 | 0 | delegationList.add(b.build()); |
130 | |
} |
131 | 0 | this.delegationRules = delegationList; |
132 | 0 | } else { |
133 | 0 | this.delegationRules = Collections.emptyList(); |
134 | |
} |
135 | 0 | this.usingGroup = builder.isUsingGroup(); |
136 | 0 | this.usingPrincipal = builder.isUsingPrincipal(); |
137 | 0 | this.usingRole = builder.isUsingRole(); |
138 | 0 | versionNumber = builder.getVersionNumber(); |
139 | 0 | objectId = builder.getObjectId(); |
140 | 0 | } |
141 | |
|
142 | |
@Override |
143 | |
public String getId() { |
144 | 0 | return this.id; |
145 | |
} |
146 | |
|
147 | |
@Override |
148 | |
public Integer getPriority() { |
149 | 0 | return this.priority; |
150 | |
} |
151 | |
|
152 | |
@Override |
153 | |
public String getResponsibilityId() { |
154 | 0 | return this.responsibilityId; |
155 | |
} |
156 | |
|
157 | |
@Override |
158 | |
public String getActionRequestedCd() { |
159 | 0 | return this.actionRequestedCd; |
160 | |
} |
161 | |
|
162 | |
@Override |
163 | |
public String getApprovePolicy() { |
164 | 0 | return this.approvePolicy; |
165 | |
} |
166 | |
|
167 | |
@Override |
168 | |
public String getPrincipalId() { |
169 | 0 | return this.principalId; |
170 | |
} |
171 | |
|
172 | |
@Override |
173 | |
public String getGroupId() { |
174 | 0 | return this.groupId; |
175 | |
} |
176 | |
|
177 | |
@Override |
178 | |
public String getRoleName() { |
179 | 0 | return this.roleName; |
180 | |
} |
181 | |
|
182 | |
@Override |
183 | |
public List<RuleDelegation> getDelegationRules() { |
184 | 0 | return this.delegationRules; |
185 | |
} |
186 | |
|
187 | |
@Override |
188 | |
public boolean isUsingRole() { |
189 | 0 | return this.usingRole; |
190 | |
} |
191 | |
|
192 | |
@Override |
193 | |
public boolean isUsingPrincipal() { |
194 | 0 | return this.usingPrincipal; |
195 | |
} |
196 | |
|
197 | |
@Override |
198 | |
public boolean isUsingGroup() { |
199 | 0 | return this.usingGroup; |
200 | |
} |
201 | |
|
202 | |
@Override |
203 | |
public Long getVersionNumber() { |
204 | 0 | return versionNumber; |
205 | |
} |
206 | |
|
207 | |
@Override |
208 | |
public String getObjectId() { |
209 | 0 | return objectId; |
210 | |
} |
211 | |
|
212 | |
public String getRoleAttributeName() { |
213 | 0 | return getRoleName().substring(0, getRoleName().indexOf("!")); |
214 | |
} |
215 | |
|
216 | |
public String getResolvedRoleName() { |
217 | 0 | if (isUsingRole()) { |
218 | 0 | return getRoleName().substring(getRoleName().indexOf("!") + 1, getRoleName().length()); |
219 | |
} |
220 | 0 | return null; |
221 | |
} |
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | 0 | 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 | 0 | private boolean usingRole = false; |
240 | 0 | private boolean usingPrincipal = false; |
241 | 0 | private boolean usingGroup = false; |
242 | |
private Long versionNumber; |
243 | |
private String objectId; |
244 | |
|
245 | 0 | private Builder() { |
246 | 0 | } |
247 | |
|
248 | |
public static Builder create() { |
249 | 0 | return new Builder(); |
250 | |
} |
251 | |
|
252 | |
public static Builder create(RuleResponsibilityContract contract) { |
253 | 0 | if (contract == null) { |
254 | 0 | throw new IllegalArgumentException("contract was null"); |
255 | |
} |
256 | 0 | Builder builder = create(); |
257 | 0 | builder.setId(contract.getId()); |
258 | 0 | builder.setPriority(contract.getPriority()); |
259 | 0 | builder.setResponsibilityId(contract.getResponsibilityId()); |
260 | 0 | builder.setActionRequestedCd(contract.getActionRequestedCd()); |
261 | 0 | builder.setApprovePolicy(contract.getApprovePolicy()); |
262 | 0 | builder.setPrincipalId(contract.getPrincipalId()); |
263 | 0 | builder.setGroupId(contract.getGroupId()); |
264 | 0 | builder.setRoleName(contract.getRoleName()); |
265 | 0 | if (CollectionUtils.isNotEmpty(contract.getDelegationRules())) { |
266 | 0 | List<RuleDelegation.Builder> builders = new ArrayList<RuleDelegation.Builder>(); |
267 | 0 | for (RuleDelegationContract delegationContract : contract.getDelegationRules()) { |
268 | 0 | builders.add(RuleDelegation.Builder.create(delegationContract)); |
269 | |
} |
270 | 0 | builder.setDelegationRules(builders); |
271 | 0 | } else { |
272 | 0 | builder.setDelegationRules(Collections.<RuleDelegation.Builder>emptyList()); |
273 | |
} |
274 | 0 | builder.setUsingGroup(contract.isUsingGroup()); |
275 | 0 | builder.setUsingPrincipal(contract.isUsingPrincipal()); |
276 | 0 | builder.setUsingRole(contract.isUsingRole()); |
277 | 0 | builder.setVersionNumber(contract.getVersionNumber()); |
278 | 0 | builder.setObjectId(contract.getObjectId()); |
279 | 0 | return builder; |
280 | |
} |
281 | |
|
282 | |
public RuleResponsibility build() { |
283 | 0 | return new RuleResponsibility(this); |
284 | |
} |
285 | |
|
286 | |
@Override |
287 | |
public String getId() { |
288 | 0 | return this.id; |
289 | |
} |
290 | |
|
291 | |
@Override |
292 | |
public Integer getPriority() { |
293 | 0 | return this.priority; |
294 | |
} |
295 | |
|
296 | |
@Override |
297 | |
public String getResponsibilityId() { |
298 | 0 | return this.responsibilityId; |
299 | |
} |
300 | |
|
301 | |
@Override |
302 | |
public String getActionRequestedCd() { |
303 | 0 | return this.actionRequestedCd; |
304 | |
} |
305 | |
|
306 | |
@Override |
307 | |
public String getApprovePolicy() { |
308 | 0 | return this.approvePolicy; |
309 | |
} |
310 | |
|
311 | |
@Override |
312 | |
public String getPrincipalId() { |
313 | 0 | return this.principalId; |
314 | |
} |
315 | |
|
316 | |
@Override |
317 | |
public String getGroupId() { |
318 | 0 | return this.groupId; |
319 | |
} |
320 | |
|
321 | |
@Override |
322 | |
public String getRoleName() { |
323 | 0 | return this.roleName; |
324 | |
} |
325 | |
|
326 | |
@Override |
327 | |
public List<RuleDelegation.Builder> getDelegationRules() { |
328 | 0 | return this.delegationRules; |
329 | |
} |
330 | |
|
331 | |
@Override |
332 | |
public boolean isUsingRole() { |
333 | 0 | return this.usingRole; |
334 | |
} |
335 | |
|
336 | |
@Override |
337 | |
public boolean isUsingPrincipal() { |
338 | 0 | return this.usingPrincipal; |
339 | |
} |
340 | |
|
341 | |
@Override |
342 | |
public boolean isUsingGroup() { |
343 | 0 | return this.usingGroup; |
344 | |
} |
345 | |
|
346 | |
@Override |
347 | |
public Long getVersionNumber() { |
348 | 0 | return versionNumber; |
349 | |
} |
350 | |
|
351 | |
@Override |
352 | |
public String getObjectId() { |
353 | 0 | return objectId; |
354 | |
} |
355 | |
|
356 | |
public void setId(String id) { |
357 | 0 | if (StringUtils.isWhitespace(id)) { |
358 | 0 | throw new IllegalArgumentException("id is whitespace"); |
359 | |
} |
360 | 0 | this.id = id; |
361 | 0 | } |
362 | |
public void setPriority(Integer priority) { |
363 | 0 | this.priority = priority; |
364 | 0 | } |
365 | |
|
366 | |
public void setResponsibilityId(String responsibilityId) { |
367 | 0 | this.responsibilityId = responsibilityId; |
368 | 0 | } |
369 | |
|
370 | |
public void setActionRequestedCd(String actionRequestedCd) { |
371 | 0 | this.actionRequestedCd = actionRequestedCd; |
372 | 0 | } |
373 | |
|
374 | |
public void setApprovePolicy(String approvePolicy) { |
375 | 0 | this.approvePolicy = approvePolicy; |
376 | 0 | } |
377 | |
|
378 | |
public void setPrincipalId(String principalId) { |
379 | 0 | this.principalId = principalId; |
380 | 0 | } |
381 | |
|
382 | |
public void setGroupId(String groupId) { |
383 | 0 | this.groupId = groupId; |
384 | 0 | } |
385 | |
|
386 | |
public void setRoleName(String roleName) { |
387 | 0 | this.roleName = roleName; |
388 | 0 | } |
389 | |
|
390 | |
public void setDelegationRules(List<RuleDelegation.Builder> delegationRules) { |
391 | 0 | this.delegationRules = delegationRules; |
392 | 0 | } |
393 | |
|
394 | |
private void setUsingRole(boolean usingRole) { |
395 | 0 | this.usingRole = usingRole; |
396 | 0 | } |
397 | |
|
398 | |
private void setUsingPrincipal(boolean usingPrincipal) { |
399 | 0 | this.usingPrincipal = usingPrincipal; |
400 | 0 | } |
401 | |
|
402 | |
private void setUsingGroup(boolean usingGroup) { |
403 | 0 | this.usingGroup = usingGroup; |
404 | 0 | } |
405 | |
|
406 | |
public void setVersionNumber(Long versionNumber) { |
407 | 0 | this.versionNumber = versionNumber; |
408 | 0 | } |
409 | |
|
410 | |
public void setObjectId(String objectId) { |
411 | 0 | this.objectId = objectId; |
412 | 0 | } |
413 | |
|
414 | |
|
415 | |
} |
416 | |
|
417 | |
@Override |
418 | |
public boolean equals(Object o) { |
419 | 0 | if (o == null) { return false; } |
420 | 0 | if (!(o instanceof RuleResponsibilityContract)) { return false; } |
421 | 0 | RuleResponsibilityContract resp = (RuleResponsibilityContract) o; |
422 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | public static class Cache { |
462 | |
public static final String NAME = KewApiConstants.Namespaces.KEW_NAMESPACE_2_0 + "/" + RuleResponsibility.Constants.TYPE_NAME; |
463 | |
} |
464 | |
} |