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