001 /**
002 * Copyright 2005-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kew.api.action;
017
018 import java.io.Serializable;
019 import java.util.ArrayList;
020 import java.util.Collection;
021 import java.util.List;
022
023 import javax.xml.bind.annotation.XmlAccessType;
024 import javax.xml.bind.annotation.XmlAccessorType;
025 import javax.xml.bind.annotation.XmlAnyElement;
026 import javax.xml.bind.annotation.XmlElement;
027 import javax.xml.bind.annotation.XmlRootElement;
028 import javax.xml.bind.annotation.XmlType;
029
030 import org.kuali.rice.core.api.CoreConstants;
031 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
032 import org.kuali.rice.core.api.mo.ModelBuilder;
033 import org.kuali.rice.kew.api.KewApiConstants;
034 import org.kuali.rice.kew.api.actionlist.DisplayParameters;
035 import org.w3c.dom.Element;
036
037
038 /**
039 * Specifies a set of Action codes.
040 *
041 * @author Kuali Rice Team (rice.collab@kuali.org)
042 */
043 @XmlRootElement(name = ActionSet.Constants.ROOT_ELEMENT_NAME)
044 @XmlAccessorType(XmlAccessType.NONE)
045 @XmlType(name = ActionSet.Constants.TYPE_NAME, propOrder = {
046 ActionSet.Elements.ACTION_SET_LIST,
047 CoreConstants.CommonElements.FUTURE_ELEMENTS
048 })
049 public final class ActionSet extends AbstractDataTransferObject implements ActionSetContract {
050
051 private static final long serialVersionUID = 7857749268529671300L;
052
053 @XmlElement(name = Elements.ACTION_SET_LIST, required = false)
054 private List<String> actionSetList;
055
056 @SuppressWarnings("unused")
057 @XmlAnyElement
058 private final Collection<Element> _futureElements = null;
059
060 /**
061 * Private constructor used only by JAXB.
062 *
063 */
064 private ActionSet() {
065 this.actionSetList = null;
066 }
067
068 /**
069 * Constructs an ActionSet from the given builder. This constructor is private and should only
070 * ever be invoked from the builder.
071 *
072 * @param builder the Builder from which to construct the ActionSet
073 */
074 private ActionSet(Builder builder) {
075 this.actionSetList = builder.getActionSet();
076 }
077
078 @Override
079 public boolean hasAction(String actionCode) {
080 return actionSetList != null && actionSetList.contains(actionCode);
081 }
082
083 /**
084 *
085 * @deprecated As of release 2.1.2 addAction should be performed using { @link ActionSet.Builder#addAction }
086 *
087 * @param actionCode
088 * @return
089 */
090 @Override
091 @Deprecated public boolean addAction(String actionCode) {
092 if (!actionSetList.contains(actionCode)) {
093 actionSetList.add(actionCode);
094 return true;
095 }
096 return false;
097 }
098
099 /**
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 }