View Javadoc

1   package org.kuali.rice.kew.api.peopleflow;
2   
3   import org.apache.commons.collections.CollectionUtils;
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.mo.ModelObjectUtils;
9   import org.kuali.rice.kew.api.action.ActionRequestPolicy;
10  import org.kuali.rice.kew.api.action.DelegationType;
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.XmlElementWrapper;
18  import javax.xml.bind.annotation.XmlRootElement;
19  import javax.xml.bind.annotation.XmlType;
20  import java.io.Serializable;
21  import java.util.ArrayList;
22  import java.util.Collection;
23  import java.util.List;
24  
25  @XmlRootElement(name = PeopleFlowMember.Constants.ROOT_ELEMENT_NAME)
26  @XmlAccessorType(XmlAccessType.NONE)
27  @XmlType(name = PeopleFlowMember.Constants.TYPE_NAME, propOrder = {
28          PeopleFlowMember.Elements.MEMBER_ID,
29          PeopleFlowMember.Elements.MEMBER_TYPE,
30          PeopleFlowMember.Elements.ACTION_REQUEST_POLICY,
31          PeopleFlowMember.Elements.RESPONSIBILITY_ID,
32          PeopleFlowMember.Elements.PRIORITY,
33          PeopleFlowMember.Elements.DELEGATES,
34          CoreConstants.CommonElements.FUTURE_ELEMENTS
35  })
36  public final class PeopleFlowMember extends AbstractDataTransferObject implements PeopleFlowMemberContract {
37  
38      private static final int STARTING_PRIORITY = 1;
39  
40      @XmlElement(name = Elements.MEMBER_ID, required = true)
41      private final String memberId;
42  
43      @XmlElement(name = Elements.MEMBER_TYPE, required = true)
44      private final MemberType memberType;
45  
46      @XmlElement(name = Elements.ACTION_REQUEST_POLICY, required = false)
47      private final ActionRequestPolicy actionRequestPolicy;
48  
49      @XmlElement(name = Elements.RESPONSIBILITY_ID, required = false)
50      private final String responsibilityId;
51  
52      @XmlElement(name = Elements.PRIORITY, required = true)
53      private final int priority;
54  
55      @XmlElementWrapper(name = Elements.DELEGATES, required = false)
56      @XmlElement(name = Elements.DELEGATE, required = false)
57      private final List<PeopleFlowDelegate> delegates;
58  
59      @SuppressWarnings("unused")
60      @XmlAnyElement
61      private final Collection<Element> _futureElements = null;
62  
63      /**
64       * Private constructor used only by JAXB.
65       */
66      private PeopleFlowMember() {
67          this.memberId = null;
68          this.memberType = null;
69          this.actionRequestPolicy = null;
70          this.responsibilityId = null;
71          this.priority = STARTING_PRIORITY;
72          this.delegates = null;
73      }
74  
75      private PeopleFlowMember(Builder builder) {
76          this.memberId = builder.getMemberId();
77          this.memberType = builder.getMemberType();
78          this.actionRequestPolicy = builder.getActionRequestPolicy();
79          this.responsibilityId = builder.getResponsibilityId();
80          this.priority = builder.getPriority();
81          this.delegates = ModelObjectUtils.buildImmutableCopy(builder.getDelegates());
82      }
83  
84      @Override
85      public String getMemberId() {
86          return this.memberId;
87      }
88  
89      @Override
90      public MemberType getMemberType() {
91          return this.memberType;
92      }
93  
94      @Override
95      public ActionRequestPolicy getActionRequestPolicy() {
96          return this.actionRequestPolicy;
97      }
98  
99      @Override
100     public String getResponsibilityId() {
101         return this.responsibilityId;
102     }
103 
104     @Override
105     public int getPriority() {
106         return this.priority;
107     }
108 
109     @Override
110     public List<PeopleFlowDelegate> getDelegates() {
111         return this.delegates;
112     }
113 
114     /**
115      * A builder which can be used to construct {@link PeopleFlowMember} instances.  Enforces the constraints of the
116      * {@link PeopleFlowMemberContract}.
117      */
118     public final static class Builder implements Serializable, ModelBuilder, PeopleFlowMemberContract {
119 
120         private String memberId;
121         private MemberType memberType;
122         private ActionRequestPolicy actionRequestPolicy;
123         private String responsibilityId;
124         private int priority;
125         private List<PeopleFlowDelegate.Builder> delegates;
126 
127         private Builder(String memberId, MemberType memberType) {
128             setMemberId(memberId);
129             setMemberType(memberType);
130             setPriority(STARTING_PRIORITY);
131             setDelegates(new ArrayList<PeopleFlowDelegate.Builder>());
132         }
133 
134         public static Builder create(String memberId, MemberType memberType) {
135             return new Builder(memberId, memberType);
136         }
137 
138         public static Builder create(PeopleFlowMemberContract contract) {
139             if (contract == null) {
140                 throw new IllegalArgumentException("contract was null");
141             }
142             Builder builder = create(contract.getMemberId(), contract.getMemberType());
143             builder.setActionRequestPolicy(contract.getActionRequestPolicy());
144             builder.setResponsibilityId(contract.getResponsibilityId());
145             builder.setPriority(contract.getPriority());
146             if (CollectionUtils.isNotEmpty(contract.getDelegates())) {
147                 for (PeopleFlowDelegateContract delegate : contract.getDelegates()) {
148                     builder.getDelegates().add(PeopleFlowDelegate.Builder.create(delegate));
149                 }
150             }
151             return builder;
152         }
153 
154         public PeopleFlowMember build() {
155             return new PeopleFlowMember(this);
156         }
157 
158         @Override
159         public String getMemberId() {
160             return this.memberId;
161         }
162 
163         @Override
164         public MemberType getMemberType() {
165             return this.memberType;
166         }
167 
168         @Override
169         public ActionRequestPolicy getActionRequestPolicy() {
170             return this.actionRequestPolicy;
171         }
172 
173         @Override
174         public String getResponsibilityId() {
175             return this.responsibilityId;
176         }
177 
178         @Override
179         public int getPriority() {
180             return this.priority;
181         }
182 
183         @Override
184         public List<PeopleFlowDelegate.Builder> getDelegates() {
185             return delegates;
186         }
187 
188         public void setMemberId(String memberId) {
189             if (StringUtils.isBlank(memberId)) {
190                 throw new IllegalArgumentException("memberId was null or blank");
191             }
192             this.memberId = memberId;
193         }
194 
195         public void setMemberType(MemberType memberType) {
196             if (memberType == null) {
197                 throw new IllegalArgumentException("memberType was null");
198             }
199             this.memberType = memberType;
200         }
201 
202         public void setActionRequestPolicy(ActionRequestPolicy actionRequestPolicy) {
203             this.actionRequestPolicy = actionRequestPolicy;
204         }
205 
206         public void setResponsibilityId(String responsibilityId) {
207             this.responsibilityId = responsibilityId;
208         }
209 
210         public void setPriority(int priority) {
211             if (priority < STARTING_PRIORITY) {
212                 throw new IllegalArgumentException("Given priority was smaller than the minimum prior value of " + STARTING_PRIORITY);
213             }
214             this.priority = priority;
215         }
216 
217         public void setDelegates(List<PeopleFlowDelegate.Builder> delegates) {
218             this.delegates = delegates;
219         }
220     }
221 
222     /**
223      * Defines some internal constants used on this class.
224      */
225     static class Constants {
226         final static String ROOT_ELEMENT_NAME = "peopleFlowMember";
227         final static String TYPE_NAME = "PeopleFlowMemberType";
228     }
229 
230     /**
231      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
232      */
233     static class Elements {
234         final static String MEMBER_ID = "memberId";
235         final static String MEMBER_TYPE = "memberType";
236         final static String ACTION_REQUEST_POLICY = "actionRequestPolicy";
237         final static String RESPONSIBILITY_ID = "responsibilityId";
238         final static String PRIORITY = "priority";
239         final static String DELEGATES = "delegates";
240         final static String DELEGATE = "delegate";
241     }
242 
243 }