View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.api.action;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.joda.time.DateTime;
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.DateTimeAdapter;
24  import org.w3c.dom.Element;
25  
26  import javax.xml.bind.annotation.XmlAccessType;
27  import javax.xml.bind.annotation.XmlAccessorType;
28  import javax.xml.bind.annotation.XmlAnyElement;
29  import javax.xml.bind.annotation.XmlElement;
30  import javax.xml.bind.annotation.XmlRootElement;
31  import javax.xml.bind.annotation.XmlType;
32  import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
33  import java.io.Serializable;
34  import java.util.Collection;
35  
36  @XmlRootElement(name = ActionTaken.Constants.ROOT_ELEMENT_NAME)
37  @XmlAccessorType(XmlAccessType.NONE)
38  @XmlType(name = ActionTaken.Constants.TYPE_NAME, propOrder = {
39      ActionTaken.Elements.ID,
40      ActionTaken.Elements.DOCUMENT_ID,
41      ActionTaken.Elements.PRINCIPAL_ID,
42      ActionTaken.Elements.DELEGATOR_PRINCIPAL_ID,
43      ActionTaken.Elements.DELEGATOR_GROUP_ID,
44      ActionTaken.Elements.ACTION_TAKEN_CODE,
45      ActionTaken.Elements.ACTION_DATE,
46      ActionTaken.Elements.ANNOTATION,
47      ActionTaken.Elements.CURRENT,
48      CoreConstants.CommonElements.FUTURE_ELEMENTS
49  })
50  public final class ActionTaken extends AbstractDataTransferObject implements ActionTakenContract {
51  
52  	private static final long serialVersionUID = 8411150332911080837L;
53  
54  	@XmlElement(name = Elements.ID, required = true)
55      private final String id;
56      
57      @XmlElement(name = Elements.DOCUMENT_ID, required = true)
58      private final String documentId;
59      
60      @XmlElement(name = Elements.PRINCIPAL_ID, required = true)
61      private final String principalId;
62      
63      @XmlElement(name = Elements.DELEGATOR_PRINCIPAL_ID, required = false)
64      private final String delegatorPrincipalId;
65      
66      @XmlElement(name = Elements.DELEGATOR_GROUP_ID, required = false)
67      private final String delegatorGroupId;
68      
69      @XmlElement(name = Elements.ACTION_TAKEN_CODE, required = true)
70      private final String actionTakenCode;
71      
72      @XmlElement(name = Elements.ACTION_DATE, required = true)
73      @XmlJavaTypeAdapter(DateTimeAdapter.class)
74      private final DateTime actionDate;
75  
76      @XmlElement(name = Elements.ANNOTATION, required = false)
77      private final String annotation;
78  
79      @XmlElement(name = Elements.CURRENT, required = true)
80      private final boolean current;    
81      
82      @SuppressWarnings("unused")
83      @XmlAnyElement
84      private final Collection<Element> _futureElements = null;
85  
86      /**
87       * Private constructor used only by JAXB.
88       * 
89       */
90      private ActionTaken() {
91          this.id = null;
92          this.documentId = null;
93          this.principalId = null;
94          this.delegatorPrincipalId = null;
95          this.delegatorGroupId = null;
96          this.actionTakenCode = null;
97          this.actionDate = null;
98          this.annotation = null;
99          this.current = false;
100     }
101 
102     private ActionTaken(Builder builder) {
103         this.annotation = builder.getAnnotation();
104         this.id = builder.getId();
105         this.documentId = builder.getDocumentId();
106         this.principalId = builder.getPrincipalId();
107         this.delegatorPrincipalId = builder.getDelegatorPrincipalId();
108         this.delegatorGroupId = builder.getDelegatorGroupId();
109         this.actionTakenCode = builder.getActionTaken().getCode();
110         this.actionDate = builder.getActionDate();
111         this.current = builder.isCurrent();
112     }
113 
114     @Override
115     public String getId() {
116         return this.id;
117     }
118 
119     @Override
120     public String getDocumentId() {
121         return this.documentId;
122     }
123 
124     @Override
125     public String getPrincipalId() {
126         return this.principalId;
127     }
128 
129     @Override
130     public String getDelegatorPrincipalId() {
131         return this.delegatorPrincipalId;
132     }
133 
134     @Override
135     public String getDelegatorGroupId() {
136         return this.delegatorGroupId;
137     }
138 
139     @Override
140     public ActionType getActionTaken() {
141         return ActionType.fromCode(actionTakenCode);
142     }
143 
144     @Override
145     public DateTime getActionDate() {
146         return this.actionDate;
147     }
148     
149     @Override
150     public String getAnnotation() {
151         return this.annotation;
152     }
153 
154     @Override
155     public boolean isCurrent() {
156         return this.current;
157     }
158 
159     /**
160      * A builder which can be used to construct {@link ActionTaken} instances.  Enforces the constraints of the {@link ActionTakenContract}.
161      */
162     public final static class Builder implements Serializable, ModelBuilder, ActionTakenContract {
163 
164 		private static final long serialVersionUID = -1226075070994810756L;
165 
166 		private String id;
167         private String documentId;
168         private String principalId;
169         private String delegatorPrincipalId;
170         private String delegatorGroupId;
171         private ActionType actionTaken;
172         private DateTime actionDate;
173         private String annotation;
174         private boolean current;
175 
176         private Builder(String id, String documentId, String principalId, ActionType actionTaken) {
177         	setId(id);
178         	setDocumentId(documentId);
179         	setPrincipalId(principalId);
180         	setActionTaken(actionTaken);
181             setActionDate(new DateTime());
182         	setCurrent(true);
183         }
184 
185         public static Builder create(String id, String documentId, String principalId, ActionType actionTaken) {
186             return new Builder(id, documentId, principalId, actionTaken);
187         }
188 
189         public static Builder create(ActionTakenContract contract) {
190             if (contract == null) {
191                 throw new IllegalArgumentException("contract was null");
192             }
193             Builder builder = create(contract.getId(), contract.getDocumentId(), contract.getPrincipalId(), contract.getActionTaken());
194             builder.setDelegatorPrincipalId(contract.getDelegatorPrincipalId());
195             builder.setDelegatorGroupId(contract.getDelegatorGroupId());
196             builder.setActionDate(contract.getActionDate());
197             builder.setAnnotation(contract.getAnnotation());
198             builder.setCurrent(contract.isCurrent());
199             return builder;
200         }
201 
202         public ActionTaken build() {
203             return new ActionTaken(this);
204         }
205 
206         @Override
207         public String getId() {
208             return this.id;
209         }
210 
211         @Override
212         public String getDocumentId() {
213             return this.documentId;
214         }
215 
216         @Override
217         public String getPrincipalId() {
218             return this.principalId;
219         }
220 
221         @Override
222         public String getDelegatorPrincipalId() {
223             return this.delegatorPrincipalId;
224         }
225 
226         @Override
227         public String getDelegatorGroupId() {
228             return this.delegatorGroupId;
229         }
230 
231         @Override
232         public ActionType getActionTaken() {
233             return this.actionTaken;
234         }
235 
236         @Override
237         public DateTime getActionDate() {
238             return this.actionDate;
239         }
240         
241         @Override
242         public String getAnnotation() {
243             return this.annotation;
244         }
245 
246         @Override
247         public boolean isCurrent() {
248             return this.current;
249         }
250 
251         public void setId(String id) {
252             if (StringUtils.isWhitespace(id)) {
253             	throw new IllegalArgumentException("id was blank");
254             }
255             this.id = id;
256         }
257 
258         public void setDocumentId(String documentId) {
259         	if (StringUtils.isBlank(documentId)) {
260             	throw new IllegalArgumentException("documentId was null or blank");
261             }
262             this.documentId = documentId;
263         }
264 
265         public void setPrincipalId(String principalId) {
266         	if (StringUtils.isBlank(principalId)) {
267             	throw new IllegalArgumentException("principalId was null or blank");
268             }
269             this.principalId = principalId;
270         }
271 
272         public void setDelegatorPrincipalId(String delegatorPrincipalId) {
273             this.delegatorPrincipalId = delegatorPrincipalId;
274         }
275 
276         public void setDelegatorGroupId(String delegatorGroupId) {
277             this.delegatorGroupId = delegatorGroupId;
278         }
279 
280         public void setActionTaken(ActionType actionTaken) {
281         	if (actionTaken == null) {
282             	throw new IllegalArgumentException("actionTaken was null");
283             }
284             this.actionTaken = actionTaken;
285         }
286 
287         public void setActionDate(DateTime actionDate) {
288             if (actionDate == null) {
289             	throw new IllegalArgumentException("actionDate was null");
290             }
291             this.actionDate = actionDate;
292         }
293 
294         public void setAnnotation(String annotation) {
295             this.annotation = annotation;
296         }
297         
298         public void setCurrent(boolean current) {
299             this.current = current;
300         }
301 
302     }
303 
304     /**
305      * Defines some internal constants used on this class.
306      */
307     static class Constants {
308         final static String ROOT_ELEMENT_NAME = "actionTaken";
309         final static String TYPE_NAME = "ActionTakenType";
310     }
311 
312 
313     /**
314      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
315      */
316     static class Elements {
317         final static String ID = "id";
318         final static String DOCUMENT_ID = "documentId";
319         final static String PRINCIPAL_ID = "principalId";
320         final static String DELEGATOR_PRINCIPAL_ID = "delegatorPrincipalId";
321         final static String DELEGATOR_GROUP_ID = "delegatorGroupId";
322         final static String ACTION_TAKEN_CODE = "actionTakenCode";
323         final static String ACTION_DATE = "actionDate";
324         final static String ANNOTATION = "annotation";
325         final static String CURRENT = "current";
326     }
327 
328 }