1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.api.peopleflow;
17
18 import org.apache.commons.collections.CollectionUtils;
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.core.api.CoreConstants;
21 import org.kuali.rice.core.api.membership.MemberType;
22 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
23 import org.kuali.rice.core.api.mo.ModelBuilder;
24 import org.kuali.rice.core.api.mo.ModelObjectUtils;
25 import org.kuali.rice.kew.api.action.ActionRequestPolicy;
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.XmlElementWrapper;
33 import javax.xml.bind.annotation.XmlRootElement;
34 import javax.xml.bind.annotation.XmlType;
35 import java.io.Serializable;
36 import java.util.ArrayList;
37 import java.util.Collection;
38 import java.util.List;
39
40 @XmlRootElement(name = PeopleFlowMember.Constants.ROOT_ELEMENT_NAME)
41 @XmlAccessorType(XmlAccessType.NONE)
42 @XmlType(name = PeopleFlowMember.Constants.TYPE_NAME, propOrder = {
43 PeopleFlowMember.Elements.MEMBER_ID,
44 PeopleFlowMember.Elements.MEMBER_TYPE,
45 PeopleFlowMember.Elements.ACTION_REQUEST_POLICY,
46 PeopleFlowMember.Elements.RESPONSIBILITY_ID,
47 PeopleFlowMember.Elements.PRIORITY,
48 PeopleFlowMember.Elements.DELEGATES,
49 PeopleFlowMember.Elements.FORCE_ACTION,
50 CoreConstants.CommonElements.FUTURE_ELEMENTS
51 })
52 public final class PeopleFlowMember extends AbstractDataTransferObject implements PeopleFlowMemberContract {
53
54 private static final int STARTING_PRIORITY = 1;
55
56 @XmlElement(name = Elements.MEMBER_ID, required = true)
57 private final String memberId;
58
59 @XmlElement(name = Elements.MEMBER_TYPE, required = true)
60 private final MemberType memberType;
61
62 @XmlElement(name = Elements.ACTION_REQUEST_POLICY, required = false)
63 private final ActionRequestPolicy actionRequestPolicy;
64
65 @XmlElement(name = Elements.RESPONSIBILITY_ID, required = false)
66 private final String responsibilityId;
67
68 @XmlElement(name = Elements.PRIORITY, required = true)
69 private final int priority;
70
71 @XmlElementWrapper(name = Elements.DELEGATES, required = false)
72 @XmlElement(name = Elements.DELEGATE, required = false)
73 private final List<PeopleFlowDelegate> delegates;
74
75 @XmlElement(name = Elements.FORCE_ACTION, required = false)
76 private Boolean forceAction;
77
78 @SuppressWarnings("unused")
79 @XmlAnyElement
80 private final Collection<Element> _futureElements = null;
81
82
83
84
85 private PeopleFlowMember() {
86 this.memberId = null;
87 this.memberType = null;
88 this.actionRequestPolicy = null;
89 this.responsibilityId = null;
90 this.priority = STARTING_PRIORITY;
91 this.delegates = null;
92 this.forceAction = true;
93 }
94
95 private PeopleFlowMember(Builder builder) {
96 this.memberId = builder.getMemberId();
97 this.memberType = builder.getMemberType();
98 this.actionRequestPolicy = builder.getActionRequestPolicy();
99 this.responsibilityId = builder.getResponsibilityId();
100 this.priority = builder.getPriority();
101 this.delegates = ModelObjectUtils.buildImmutableCopy(builder.getDelegates());
102 this.forceAction = builder.getForceAction();
103 }
104
105 @Override
106 public String getMemberId() {
107 return this.memberId;
108 }
109
110 @Override
111 public MemberType getMemberType() {
112 return this.memberType;
113 }
114
115 @Override
116 public ActionRequestPolicy getActionRequestPolicy() {
117 return this.actionRequestPolicy;
118 }
119
120 @Override
121 public String getResponsibilityId() {
122 return this.responsibilityId;
123 }
124
125 @Override
126 public int getPriority() {
127 return this.priority;
128 }
129
130 @Override
131 public List<PeopleFlowDelegate> getDelegates() {
132 return this.delegates;
133 }
134
135 @Override
136 public Boolean getForceAction() {
137 return forceAction;
138 }
139
140
141
142
143
144 public final static class Builder implements Serializable, ModelBuilder, PeopleFlowMemberContract {
145
146 private String memberId;
147 private MemberType memberType;
148 private ActionRequestPolicy actionRequestPolicy;
149 private String responsibilityId;
150 private int priority;
151 private List<PeopleFlowDelegate.Builder> delegates;
152 private Boolean forceAction = true;
153
154 private Builder(String memberId, MemberType memberType) {
155 setMemberId(memberId);
156 setMemberType(memberType);
157 setPriority(STARTING_PRIORITY);
158 setDelegates(new ArrayList<PeopleFlowDelegate.Builder>());
159 }
160
161 public static Builder create(String memberId, MemberType memberType) {
162 return new Builder(memberId, memberType);
163 }
164
165 public static Builder create(PeopleFlowMemberContract contract) {
166 Builder builder = createCopy(contract);
167
168 builder.setResponsibilityId(contract.getResponsibilityId());
169 return builder;
170 }
171
172 public static Builder createCopy(PeopleFlowMemberContract contract) {
173 if (contract == null) {
174 throw new IllegalArgumentException("contract was null");
175 }
176
177 Builder builder = create(contract.getMemberId(), contract.getMemberType());
178 builder.setActionRequestPolicy(contract.getActionRequestPolicy());
179 builder.setPriority(contract.getPriority());
180
181 if (CollectionUtils.isNotEmpty(contract.getDelegates())) {
182 for (PeopleFlowDelegateContract delegate : contract.getDelegates()) {
183 builder.getDelegates().add(PeopleFlowDelegate.Builder.create(delegate));
184 }
185 }
186
187 builder.setForceAction(contract.getForceAction());
188
189 return builder;
190 }
191
192 public PeopleFlowMember build() {
193 return new PeopleFlowMember(this);
194 }
195
196 @Override
197 public String getMemberId() {
198 return this.memberId;
199 }
200
201 @Override
202 public MemberType getMemberType() {
203 return this.memberType;
204 }
205
206 @Override
207 public ActionRequestPolicy getActionRequestPolicy() {
208 return this.actionRequestPolicy;
209 }
210
211 @Override
212 public String getResponsibilityId() {
213 return this.responsibilityId;
214 }
215
216 @Override
217 public int getPriority() {
218 return this.priority;
219 }
220
221 @Override
222 public List<PeopleFlowDelegate.Builder> getDelegates() {
223 return delegates;
224 }
225
226 @Override
227 public Boolean getForceAction() { return forceAction; }
228
229 public void setMemberId(String memberId) {
230 if (StringUtils.isBlank(memberId)) {
231 throw new IllegalArgumentException("memberId was null or blank");
232 }
233 this.memberId = memberId;
234 }
235
236 public void setMemberType(MemberType memberType) {
237 if (memberType == null) {
238 throw new IllegalArgumentException("memberType was null");
239 }
240 this.memberType = memberType;
241 }
242
243 public void setActionRequestPolicy(ActionRequestPolicy actionRequestPolicy) {
244 if (this.memberType.equals(MemberType.ROLE)) {
245 if (actionRequestPolicy == null) {
246 throw new IllegalArgumentException("actionRequestPolicy was null");
247 }
248 this.actionRequestPolicy = actionRequestPolicy;
249 }
250 }
251
252 public void setResponsibilityId(String responsibilityId) {
253 this.responsibilityId = responsibilityId;
254 }
255
256 public void setPriority(int priority) {
257 if (priority < STARTING_PRIORITY) {
258 throw new IllegalArgumentException("Given priority was smaller than the minimum prior value of " + STARTING_PRIORITY);
259 }
260 this.priority = priority;
261 }
262
263 public void setDelegates(List<PeopleFlowDelegate.Builder> delegates) {
264 this.delegates = delegates;
265 }
266
267 public void setForceAction(Boolean forceAction) {
268 this.forceAction = forceAction;
269
270 if (forceAction == null) {
271 forceAction = true;
272 }
273 }
274 }
275
276
277
278
279 static class Constants {
280 final static String ROOT_ELEMENT_NAME = "peopleFlowMember";
281 final static String TYPE_NAME = "PeopleFlowMemberType";
282 }
283
284
285
286
287 static class Elements {
288 final static String MEMBER_ID = "memberId";
289 final static String MEMBER_TYPE = "memberType";
290 final static String ACTION_REQUEST_POLICY = "actionRequestPolicy";
291 final static String RESPONSIBILITY_ID = "responsibilityId";
292 final static String PRIORITY = "priority";
293 final static String DELEGATES = "delegates";
294 final static String DELEGATE = "delegate";
295 final static String FORCE_ACTION = "forceAction";
296 }
297
298 }