1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.api.responsibility;
17
18 import com.google.common.collect.Maps;
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.core.api.CoreConstants;
21 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
22 import org.kuali.rice.core.api.mo.ModelBuilder;
23 import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter;
24 import org.kuali.rice.kim.api.common.delegate.DelegateType;
25 import org.kuali.rice.kim.api.common.delegate.DelegateTypeContract;
26 import org.w3c.dom.Element;
27
28 import javax.xml.bind.annotation.XmlAccessType;
29 import javax.xml.bind.annotation.XmlAccessorType;
30 import javax.xml.bind.annotation.XmlAnyElement;
31 import javax.xml.bind.annotation.XmlElement;
32 import javax.xml.bind.annotation.XmlRootElement;
33 import javax.xml.bind.annotation.XmlType;
34 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
35 import java.io.Serializable;
36 import java.util.ArrayList;
37 import java.util.Collection;
38 import java.util.Collections;
39 import java.util.List;
40 import java.util.Map;
41
42 @XmlRootElement(name = ResponsibilityAction.Constants.ROOT_ELEMENT_NAME)
43 @XmlAccessorType(XmlAccessType.NONE)
44 @XmlType(name = ResponsibilityAction.Constants.TYPE_NAME, propOrder = {
45 ResponsibilityAction.Elements.PRINCIPAL_ID,
46 ResponsibilityAction.Elements.ROLE_RESPONSIBILITY_ACTION_ID,
47 ResponsibilityAction.Elements.PARALLEL_ROUTING_GROUPING_CODE,
48 ResponsibilityAction.Elements.ACTION_TYPE_CODE,
49 ResponsibilityAction.Elements.ACTION_POLICY_CODE,
50 ResponsibilityAction.Elements.PRIORITY_NUMBER,
51 ResponsibilityAction.Elements.GROUP_ID,
52 ResponsibilityAction.Elements.MEMBER_ROLE_ID,
53 ResponsibilityAction.Elements.RESPONSIBILITY_NAME,
54 ResponsibilityAction.Elements.RESPONSIBILITY_ID,
55 ResponsibilityAction.Elements.RESPONSIBILITY_NAMESPACE_CODE,
56 ResponsibilityAction.Elements.FORCE_ACTION,
57 ResponsibilityAction.Elements.QUALIFIER,
58 ResponsibilityAction.Elements.DELEGATES,
59 ResponsibilityAction.Elements.ROLE_ID,
60 CoreConstants.CommonElements.FUTURE_ELEMENTS
61 })
62 public final class ResponsibilityAction extends AbstractDataTransferObject
63 implements ResponsibilityActionContract {
64
65 @XmlElement(name = Elements.PRINCIPAL_ID, required = false)
66 private final String principalId;
67 @XmlElement(name = Elements.ROLE_RESPONSIBILITY_ACTION_ID, required = false)
68 private final String roleResponsibilityActionId;
69 @XmlElement(name = Elements.PARALLEL_ROUTING_GROUPING_CODE, required = false)
70 private final String parallelRoutingGroupingCode;
71 @XmlElement(name = Elements.ACTION_TYPE_CODE, required = false)
72 private final String actionTypeCode;
73 @XmlElement(name = Elements.ACTION_POLICY_CODE, required = false)
74 private final String actionPolicyCode;
75 @XmlElement(name = Elements.PRIORITY_NUMBER, required = false)
76 private final Integer priorityNumber;
77 @XmlElement(name = Elements.GROUP_ID, required = true)
78 private final String groupId;
79 @XmlElement(name = Elements.MEMBER_ROLE_ID, required = true)
80 private final String memberRoleId;
81 @XmlElement(name = Elements.RESPONSIBILITY_NAME, required = true)
82 private final String responsibilityName;
83 @XmlElement(name = Elements.RESPONSIBILITY_ID, required = true)
84 private final String responsibilityId;
85 @XmlElement(name = Elements.RESPONSIBILITY_NAMESPACE_CODE, required = true)
86 private final String responsibilityNamespaceCode;
87 @XmlElement(name = Elements.FORCE_ACTION, required = true)
88 private final boolean forceAction;
89 @XmlElement(name = Elements.QUALIFIER, required = true)
90 @XmlJavaTypeAdapter(value = MapStringStringAdapter.class)
91 private final Map<String, String> qualifier;
92 @XmlElement(name = Elements.DELEGATES, required = true)
93 private final List<DelegateType> delegates;
94 @XmlElement(name = Elements.ROLE_ID, required = true)
95 private final String roleId;
96 @SuppressWarnings("unused")
97 @XmlAnyElement
98 private final Collection<Element> _futureElements = null;
99
100
101
102
103 private ResponsibilityAction() {
104 this.principalId = null;
105 this.roleResponsibilityActionId = null;
106 this.parallelRoutingGroupingCode = null;
107 this.actionTypeCode = null;
108 this.actionPolicyCode = null;
109 this.priorityNumber = null;
110 this.groupId = null;
111 this.memberRoleId = null;
112 this.responsibilityName = null;
113 this.responsibilityId = null;
114 this.responsibilityNamespaceCode = null;
115 this.forceAction = false;
116 this.qualifier = null;
117 this.delegates = null;
118 this.roleId = null;
119 }
120
121 private ResponsibilityAction(Builder builder) {
122 this.principalId = builder.getPrincipalId();
123 this.roleResponsibilityActionId = builder.getRoleResponsibilityActionId();
124 this.parallelRoutingGroupingCode = builder.getParallelRoutingGroupingCode();
125 this.actionTypeCode = builder.getActionTypeCode();
126 this.actionPolicyCode = builder.getActionPolicyCode();
127 this.priorityNumber = builder.getPriorityNumber();
128 this.groupId = builder.getGroupId();
129 this.memberRoleId = builder.getMemberRoleId();
130 this.responsibilityName = builder.getResponsibilityName();
131 this.responsibilityId = builder.getResponsibilityId();
132 this.responsibilityNamespaceCode = builder.getResponsibilityNamespaceCode();
133 this.forceAction = builder.isForceAction();
134 this.qualifier = builder.getQualifier();
135 final List<DelegateType> ds = new ArrayList<DelegateType>();
136 for (DelegateType.Builder d : builder.getDelegates()) {
137 if (d != null) {
138 ds.add(d.build());
139 }
140 }
141 this.delegates = ds;
142 this.roleId = builder.getRoleId();
143 }
144
145 @Override
146 public String getPrincipalId() {
147 return this.principalId;
148 }
149
150 @Override
151 public String getRoleResponsibilityActionId() {
152 return this.roleResponsibilityActionId;
153 }
154
155 @Override
156 public String getParallelRoutingGroupingCode() {
157 return this.parallelRoutingGroupingCode;
158 }
159
160 @Override
161 public String getActionTypeCode() {
162 return this.actionTypeCode;
163 }
164
165 @Override
166 public String getActionPolicyCode() {
167 return this.actionPolicyCode;
168 }
169
170 @Override
171 public Integer getPriorityNumber() {
172 return this.priorityNumber;
173 }
174
175 @Override
176 public String getGroupId() {
177 return this.groupId;
178 }
179
180 @Override
181 public String getMemberRoleId() {
182 return this.memberRoleId;
183 }
184
185 @Override
186 public String getResponsibilityName() {
187 return this.responsibilityName;
188 }
189
190 @Override
191 public String getResponsibilityId() {
192 return this.responsibilityId;
193 }
194
195 @Override
196 public String getResponsibilityNamespaceCode() {
197 return this.responsibilityNamespaceCode;
198 }
199
200 @Override
201 public boolean isForceAction() {
202 return this.forceAction;
203 }
204
205 @Override
206 public Map<String, String> getQualifier() {
207 return this.qualifier;
208 }
209
210 @Override
211 public List<DelegateType> getDelegates() {
212 return Collections.unmodifiableList(this.delegates);
213 }
214
215 @Override
216 public String getRoleId() {
217 return this.roleId;
218 }
219
220
221
222
223
224 public final static class Builder
225 implements Serializable, ModelBuilder, ResponsibilityActionContract {
226
227 private String principalId;
228 private String roleResponsibilityActionId;
229 private String parallelRoutingGroupingCode;
230 private String actionTypeCode;
231 private String actionPolicyCode;
232 private Integer priorityNumber;
233 private String groupId;
234 private String memberRoleId;
235 private String responsibilityName;
236 private String responsibilityId;
237 private String responsibilityNamespaceCode;
238 private boolean forceAction;
239 private Map<String, String> qualifier;
240 private List<DelegateType.Builder> delegates;
241 private String roleId;
242
243 private Builder() {
244 }
245
246
247
248
249
250
251
252 public static Builder create() {
253
254 return new Builder();
255 }
256
257 public static Builder create(ResponsibilityActionContract contract) {
258 if (contract == null) {
259 throw new IllegalArgumentException("contract was null");
260 }
261 Builder builder = create();
262 builder.setPrincipalId(contract.getPrincipalId());
263 builder.setRoleResponsibilityActionId(contract.getRoleResponsibilityActionId());
264 builder.setParallelRoutingGroupingCode(contract.getParallelRoutingGroupingCode());
265 builder.setActionTypeCode(contract.getActionTypeCode());
266 builder.setActionPolicyCode(contract.getActionPolicyCode());
267 builder.setPriorityNumber(contract.getPriorityNumber());
268 builder.setGroupId(contract.getGroupId());
269 builder.setMemberRoleId(contract.getMemberRoleId());
270 builder.setResponsibilityName(contract.getResponsibilityName());
271 builder.setResponsibilityId(contract.getResponsibilityId());
272 builder.setResponsibilityNamespaceCode(contract.getResponsibilityNamespaceCode());
273 builder.setForceAction(contract.isForceAction());
274 builder.setQualifier(contract.getQualifier());
275 final List<DelegateType.Builder> dbs = new ArrayList<DelegateType.Builder>();
276 for (DelegateTypeContract d : contract.getDelegates()) {
277 if (d != null) {
278 dbs.add(DelegateType.Builder.create(d));
279 }
280 }
281 builder.setDelegates(dbs);
282 builder.setRoleId(contract.getRoleId());
283 return builder;
284 }
285
286 public ResponsibilityAction build() {
287
288 final boolean requiredSet = (groupId != null ^ principalId != null) &&
289 memberRoleId != null &&
290 responsibilityName != null &&
291 responsibilityId != null &&
292 responsibilityNamespaceCode != null &&
293 qualifier != null &&
294 delegates != null &&
295 roleId != null;
296
297 if (!requiredSet) {
298 throw new IllegalStateException("all the required fields are not set");
299 }
300 return new ResponsibilityAction(this);
301 }
302
303 @Override
304 public String getPrincipalId() {
305 return this.principalId;
306 }
307
308 @Override
309 public String getRoleResponsibilityActionId() {
310 return this.roleResponsibilityActionId;
311 }
312
313 @Override
314 public String getParallelRoutingGroupingCode() {
315 return this.parallelRoutingGroupingCode;
316 }
317
318 @Override
319 public String getActionTypeCode() {
320 return this.actionTypeCode;
321 }
322
323 @Override
324 public String getActionPolicyCode() {
325 return this.actionPolicyCode;
326 }
327
328 @Override
329 public Integer getPriorityNumber() {
330 return this.priorityNumber;
331 }
332
333 @Override
334 public String getGroupId() {
335 return this.groupId;
336 }
337
338 @Override
339 public String getMemberRoleId() {
340 return this.memberRoleId;
341 }
342
343 @Override
344 public String getResponsibilityName() {
345 return this.responsibilityName;
346 }
347
348 @Override
349 public String getResponsibilityId() {
350 return this.responsibilityId;
351 }
352
353 @Override
354 public String getResponsibilityNamespaceCode() {
355 return this.responsibilityNamespaceCode;
356 }
357
358 @Override
359 public boolean isForceAction() {
360 return this.forceAction;
361 }
362
363 @Override
364 public Map<String, String> getQualifier() {
365 return this.qualifier;
366 }
367
368 @Override
369 public List<DelegateType.Builder> getDelegates() {
370 return Collections.unmodifiableList(this.delegates);
371 }
372
373 @Override
374 public String getRoleId() {
375 return this.roleId;
376 }
377
378 public void setPrincipalId(String principalId) {
379 this.principalId = principalId;
380 }
381
382 public void setRoleResponsibilityActionId(String roleResponsibilityActionId) {
383 this.roleResponsibilityActionId = roleResponsibilityActionId;
384 }
385
386 public void setParallelRoutingGroupingCode(String parallelRoutingGroupingCode) {
387 this.parallelRoutingGroupingCode = parallelRoutingGroupingCode;
388 }
389
390 public void setActionTypeCode(String actionTypeCode) {
391 this.actionTypeCode = actionTypeCode;
392 }
393
394 public void setActionPolicyCode(String actionPolicyCode) {
395 this.actionPolicyCode = actionPolicyCode;
396 }
397
398 public void setPriorityNumber(Integer priorityNumber) {
399 this.priorityNumber = priorityNumber;
400 }
401
402 public void setGroupId(String groupId) {
403 this.groupId = groupId;
404 }
405
406 public void setMemberRoleId(String memberRoleId) {
407 if (StringUtils.isBlank(memberRoleId)) {
408 throw new IllegalArgumentException("memberRoleId is blank");
409 }
410
411 this.memberRoleId = memberRoleId;
412 }
413
414 public void setResponsibilityName(String responsibilityName) {
415 if (StringUtils.isBlank(responsibilityName)) {
416 throw new IllegalArgumentException("responsibilityName is blank");
417 }
418
419 this.responsibilityName = responsibilityName;
420 }
421
422 public void setResponsibilityId(String responsibilityId) {
423 if (StringUtils.isBlank(responsibilityId)) {
424 throw new IllegalArgumentException("responsibilityId is blank");
425 }
426
427 this.responsibilityId = responsibilityId;
428 }
429
430 public void setResponsibilityNamespaceCode(String responsibilityNamespaceCode) {
431 if (StringUtils.isBlank(responsibilityNamespaceCode)) {
432 throw new IllegalArgumentException("responsibilityNamespaceCode is blank");
433 }
434 this.responsibilityNamespaceCode = responsibilityNamespaceCode;
435 }
436
437 public void setForceAction(boolean forceAction) {
438 this.forceAction = forceAction;
439 }
440
441 public void setQualifier(Map<String, String> qualifier) {
442 if (qualifier == null) {
443 throw new IllegalArgumentException("qualifier is null");
444 }
445 this.qualifier = Collections.unmodifiableMap(Maps.newHashMap(qualifier));
446 }
447
448 public void setDelegates(List<DelegateType.Builder> delegates) {
449 if (delegates == null) {
450 throw new IllegalArgumentException("delegates is null");
451 }
452 this.delegates = new ArrayList<DelegateType.Builder>(delegates);
453 }
454
455 public void setRoleId(String roleId) {
456 if (StringUtils.isBlank(roleId)) {
457 throw new IllegalArgumentException("roleId is blank");
458 }
459 this.roleId = roleId;
460 }
461
462 }
463
464
465
466
467
468 static class Constants {
469
470 final static String ROOT_ELEMENT_NAME = "responsibilityAction";
471 final static String TYPE_NAME = "ResponsibilityActionType";
472 }
473
474
475
476
477
478 static class Elements {
479
480 final static String PRINCIPAL_ID = "principalId";
481 final static String ROLE_RESPONSIBILITY_ACTION_ID = "roleResponsibilityActionId";
482 final static String PARALLEL_ROUTING_GROUPING_CODE = "parallelRoutingGroupingCode";
483 final static String ACTION_TYPE_CODE = "actionTypeCode";
484 final static String ACTION_POLICY_CODE = "actionPolicyCode";
485 final static String PRIORITY_NUMBER = "priorityNumber";
486 final static String GROUP_ID = "groupId";
487 final static String MEMBER_ROLE_ID = "memberRoleId";
488 final static String RESPONSIBILITY_NAME = "responsibilityName";
489 final static String RESPONSIBILITY_ID = "responsibilityId";
490 final static String RESPONSIBILITY_NAMESPACE_CODE = "responsibilityNamespaceCode";
491 final static String FORCE_ACTION = "forceAction";
492 final static String QUALIFIER = "qualifier";
493 final static String DELEGATES = "delegates";
494 final static String ROLE_ID = "roleId";
495
496 }
497
498 }