View Javadoc
1   /**
2    * Copyright 2005-2016 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 java.io.Serializable;
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.List;
22  
23  import javax.xml.bind.annotation.XmlAccessType;
24  import javax.xml.bind.annotation.XmlAccessorType;
25  import javax.xml.bind.annotation.XmlAnyElement;
26  import javax.xml.bind.annotation.XmlElement;
27  import javax.xml.bind.annotation.XmlRootElement;
28  import javax.xml.bind.annotation.XmlType;
29  
30  import org.kuali.rice.core.api.CoreConstants;
31  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
32  import org.kuali.rice.core.api.mo.ModelBuilder;
33  import org.kuali.rice.kew.api.KewApiConstants;
34  import org.kuali.rice.kew.api.actionlist.DisplayParameters;
35  import org.w3c.dom.Element;
36  
37  
38  /**
39   * Specifies a set of Action codes.
40   * 
41   * @author Kuali Rice Team (rice.collab@kuali.org)
42   */
43  @XmlRootElement(name = ActionSet.Constants.ROOT_ELEMENT_NAME)
44  @XmlAccessorType(XmlAccessType.NONE)
45  @XmlType(name = ActionSet.Constants.TYPE_NAME, propOrder = {
46      ActionSet.Elements.ACTION_SET_LIST,
47      CoreConstants.CommonElements.FUTURE_ELEMENTS
48  })
49  public final class ActionSet extends AbstractDataTransferObject implements ActionSetContract {
50  
51  	private static final long serialVersionUID = 7857749268529671300L;
52  	
53  	@XmlElement(name = Elements.ACTION_SET_LIST, required = false)
54  	private List<String> actionSetList;
55  	
56  	@SuppressWarnings("unused")
57      @XmlAnyElement
58      private final Collection<Element> _futureElements = null;
59  	
60  	/**
61       * Private constructor used only by JAXB.
62       * 
63       */
64  	private ActionSet() {
65  	    this.actionSetList = null;
66  	}
67  	
68  	/**
69       * Constructs an ActionSet from the given builder.  This constructor is private and should only
70       * ever be invoked from the builder.
71       * 
72       * @param builder the Builder from which to construct the ActionSet
73       */
74  	private ActionSet(Builder builder) {
75  	    this.actionSetList = builder.getActionSet();
76  	}
77  	
78  	@Override
79  	public boolean hasAction(String actionCode) {
80  		return actionSetList != null && actionSetList.contains(actionCode);
81  	}
82  
83      /**
84       * 
85       * @deprecated  As of release 2.1.2 addAction should be performed using { @link ActionSet.Builder#addAction }
86       * 
87       * @param actionCode
88       * @return
89       */
90      @Override
91  	@Deprecated public boolean addAction(String actionCode) {
92  		if (!actionSetList.contains(actionCode)) {
93  			actionSetList.add(actionCode);
94  			return true;
95  		}
96  		return false;
97  	}
98  
99      /**
100      *
101      * @deprecated  As of release 2.1.2 removeAction should be performed using { @link ActionSet.Builder#removeAction }
102      *
103      * @param actionCode
104      * @return
105      */
106     @Override
107     @Deprecated public boolean removeAction(String actionCode) {
108 		return actionSetList.remove(actionCode);
109 	}
110 	
111 	// some convienance methods for common actions
112 	@Override
113 	public boolean hasApprove() {
114 		return hasAction(KewApiConstants.ACTION_TAKEN_APPROVED_CD);
115 	}
116 	
117 	@Override
118 	public boolean hasComplete() {
119 		return hasAction(KewApiConstants.ACTION_TAKEN_COMPLETED_CD);
120 	}
121 	
122 	@Override
123 	public boolean hasAcknowledge() {
124 		return hasAction(KewApiConstants.ACTION_TAKEN_ACKNOWLEDGED_CD);
125 	}
126 	
127 	@Override
128 	public boolean hasFyi() {
129 		return hasAction(KewApiConstants.ACTION_TAKEN_FYI_CD);
130 	}
131 	
132 	@Override
133 	public boolean hasDisapprove() {
134 		return hasAction(KewApiConstants.ACTION_TAKEN_DENIED_CD);
135 	}
136 	
137 	@Override
138 	public boolean hasCancel() {
139 		return hasAction(KewApiConstants.ACTION_TAKEN_CANCELED_CD);
140 	}
141 
142 	@Override
143     public boolean hasRouted() {
144         return hasAction(KewApiConstants.ACTION_TAKEN_ROUTED_CD);
145     }
146 
147     /**
148      *
149      * @deprecated  As of release 2.1.2 addApprove should be performed using { @link ActionSet.Builder#addApprove }
150      *
151      * @return
152      */
153 	@Override
154     @Deprecated public boolean addApprove() {
155 		return addAction(KewApiConstants.ACTION_TAKEN_APPROVED_CD);
156 	}
157 
158     /**
159      *
160      * @deprecated  As of release 2.1.2 addComplete should be performed using { @link ActionSet.Builder#addComplete }
161      *
162      * @return
163      */
164 	@Override
165     @Deprecated public boolean addComplete() {
166 		return addAction(KewApiConstants.ACTION_TAKEN_COMPLETED_CD);
167 	}
168 
169     /**
170      *
171      * @deprecated  As of release 2.1.2 addAcknowledge should be performed using { @link ActionSet.Builder#addAcknowledge }
172      *
173      * @return
174      */
175 	@Override
176     @Deprecated public boolean addAcknowledge() {
177 		return addAction(KewApiConstants.ACTION_TAKEN_ACKNOWLEDGED_CD);
178 	}
179 
180     /**
181      *
182      * @deprecated  As of release 2.1.2 addFyi should be performed using { @link ActionSet.Builder#addFyi }
183      *
184      * @return
185      */
186 	@Override
187     @Deprecated public boolean addFyi() {
188 		return addAction(KewApiConstants.ACTION_TAKEN_FYI_CD);
189 	}
190 
191     /**
192      *
193      * @deprecated  As of release 2.1.2 addDisapprove should be performed using { @link ActionSet.Builder#addDisapprove }
194      *
195      * @return
196      */
197 	@Override
198     @Deprecated public boolean addDisapprove() {
199 		return addAction(KewApiConstants.ACTION_TAKEN_DENIED_CD);
200 	}
201 
202     /**
203      *
204      * @deprecated  As of release 2.1.2 addCancel should be performed using { @link ActionSet.Builder#addCancel }
205      *
206      * @return
207      */
208 	@Override
209     @Deprecated public boolean addCancel() {
210 		return addAction(KewApiConstants.ACTION_TAKEN_CANCELED_CD);
211 	}
212 
213     /**
214      *
215      * @deprecated  As of release 2.1.2 addRouted should be performed using { @link ActionSet.Builder#addRouted }
216      *
217      * @return
218      */
219 	@Override
220     @Deprecated public boolean addRouted() {
221         return addAction(KewApiConstants.ACTION_TAKEN_ROUTED_CD);
222     }
223     
224 	/**
225      * A builder which can be used to construct {@link ActionSet} instances.  Enforces the constraints of the {@link ActionSetContract}.
226      */
227 	public final static class Builder implements Serializable, ModelBuilder, ActionSetContract {
228 	    
229 	    private List<String> actionSet;
230 	    
231 	    /**
232          * Private constructor for creating a builder with all of it's required attributes.
233          */
234 	    private Builder(List<String> actionSet) {
235 	        setActionSetList(actionSet);
236 	    }
237 	    
238 	    public static Builder create() {
239 	        return new Builder(new ArrayList<String>());
240 	    }
241 	    
242 	    /**
243          * Creates a builder by populating it with data from the given {@linkActionSet}.
244          * 
245          * @param contract the contract from which to populate this builder
246          * @return an instance of the builder populated with data from the contract
247          */
248 	    public static Builder create(ActionSetContract contract) {
249 	        if (contract == null) {
250                 throw new IllegalArgumentException("contract was null");
251             }
252             Builder builder = create();
253             return builder;
254 	    }
255 	   
256 	    public ActionSet build() {
257 	        return new ActionSet(this);
258 	    }
259 	    public List<String> getActionSet() {
260 	        return this.actionSet;
261 	    }
262 	    public void setActionSetList(List<String> actionSet) {
263 	        this.actionSet = actionSet;
264 	    }
265 
266         @Override
267         public boolean hasAction(String actionCode) {
268             return actionSet.contains(actionCode);
269         }
270 
271         @Override
272         public boolean addAction(String actionCode) {
273             if (!actionSet.contains(actionCode)) {
274                 actionSet.add(actionCode);
275                 return true;
276             }
277             return false;
278         }
279 
280         @Override
281         public boolean removeAction(String actionCode) {
282             return actionSet.remove(actionCode);
283         }
284 
285         @Override
286         public boolean hasApprove() {
287             return hasAction(KewApiConstants.ACTION_TAKEN_APPROVED_CD);
288         }
289 
290         @Override
291         public boolean hasComplete() {
292             return hasAction(KewApiConstants.ACTION_TAKEN_COMPLETED_CD);
293         }
294 
295         @Override
296         public boolean hasAcknowledge() {
297             return hasAction(KewApiConstants.ACTION_TAKEN_ACKNOWLEDGED_CD);
298         }
299 
300         @Override
301         public boolean hasFyi() {
302             return hasAction(KewApiConstants.ACTION_TAKEN_FYI_CD);
303         }
304 
305         @Override
306         public boolean hasDisapprove() {
307             return hasAction(KewApiConstants.ACTION_TAKEN_DENIED_CD);
308         }
309 
310         @Override
311         public boolean hasCancel() {
312             return hasAction(KewApiConstants.ACTION_TAKEN_CANCELED_CD);
313         }
314 
315         @Override
316         public boolean hasRouted() {
317             return hasAction(KewApiConstants.ACTION_TAKEN_ROUTED_CD);
318         }
319 
320         @Override
321         public boolean addApprove() {
322             return addAction(KewApiConstants.ACTION_TAKEN_APPROVED_CD);
323         }
324 
325         @Override
326         public boolean addComplete() {
327             return addAction(KewApiConstants.ACTION_TAKEN_COMPLETED_CD);
328         }
329 
330         /**
331          * This overridden method ...
332          * 
333          * @see org.kuali.rice.kew.api.action.ActionSetContract#addAcknowledge()
334          */
335         @Override
336         public boolean addAcknowledge() {
337             return addAction(KewApiConstants.ACTION_TAKEN_ACKNOWLEDGED_CD);
338         }
339 
340         @Override
341         public boolean addFyi() {
342             return addAction(KewApiConstants.ACTION_TAKEN_FYI_CD);
343         }
344 
345         @Override
346         public boolean addDisapprove() {
347             return addAction(KewApiConstants.ACTION_TAKEN_DENIED_CD);
348         }
349 
350         @Override
351         public boolean addCancel() {
352             return addAction(KewApiConstants.ACTION_TAKEN_CANCELED_CD);
353         }
354 
355         @Override
356         public boolean addRouted() {
357             return addAction(KewApiConstants.ACTION_TAKEN_ROUTED_CD);
358         }	        
359 	}
360 	
361     /**
362      * Defines some internal constants used on this class.
363      * 
364      */
365     static class Constants {
366 
367         final static String ROOT_ELEMENT_NAME = "actionSet";
368         final static String TYPE_NAME = "ActionSetType";
369     }
370 
371     /**
372      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
373      * 
374      */
375     static class Elements {
376 
377         final static String ACTION_SET_LIST = "actionSetList";
378     }
379 }