001 /**
002 * Copyright 2005-2012 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.ModelBuilder;
032 import org.kuali.rice.kew.api.KewApiConstants;
033 import org.kuali.rice.kew.api.actionlist.DisplayParameters;
034 import org.w3c.dom.Element;
035
036
037 /**
038 * Specifies a set of Action codes.
039 *
040 * @author Kuali Rice Team (rice.collab@kuali.org)
041 */
042 @XmlRootElement(name = ActionSet.Constants.ROOT_ELEMENT_NAME)
043 @XmlAccessorType(XmlAccessType.NONE)
044 @XmlType(name = ActionSet.Constants.TYPE_NAME, propOrder = {
045 ActionSet.Elements.ACTION_SET_LIST,
046 CoreConstants.CommonElements.FUTURE_ELEMENTS
047 })
048 public final class ActionSet implements Serializable, ActionSetContract {
049
050 private static final long serialVersionUID = 7857749268529671300L;
051
052 @XmlElement(name = Elements.ACTION_SET_LIST, required = false)
053 private List<String> actionSetList;
054
055 @SuppressWarnings("unused")
056 @XmlAnyElement
057 private final Collection<Element> _futureElements = null;
058
059 /**
060 * Private constructor used only by JAXB.
061 *
062 */
063 private ActionSet() {
064 this.actionSetList = null;
065 }
066
067 /**
068 * Constructs an ActionSet from the given builder. This constructor is private and should only
069 * ever be invoked from the builder.
070 *
071 * @param builder the Builder from which to construct the ActionSet
072 */
073 private ActionSet(Builder builder) {
074 this.actionSetList = builder.getActionSet();
075 }
076
077 @Override
078 public boolean hasAction(String actionCode) {
079 return actionSetList.contains(actionCode);
080 }
081
082 @Override
083 public boolean addAction(String actionCode) {
084 if (!actionSetList.contains(actionCode)) {
085 actionSetList.add(actionCode);
086 return true;
087 }
088 return false;
089 }
090
091 @Override
092 public boolean removeAction(String actionCode) {
093 return actionSetList.remove(actionCode);
094 }
095
096 // some convienance methods for common actions
097 @Override
098 public boolean hasApprove() {
099 return hasAction(KewApiConstants.ACTION_TAKEN_APPROVED_CD);
100 }
101
102 @Override
103 public boolean hasComplete() {
104 return hasAction(KewApiConstants.ACTION_TAKEN_COMPLETED_CD);
105 }
106
107 @Override
108 public boolean hasAcknowledge() {
109 return hasAction(KewApiConstants.ACTION_TAKEN_ACKNOWLEDGED_CD);
110 }
111
112 @Override
113 public boolean hasFyi() {
114 return hasAction(KewApiConstants.ACTION_TAKEN_FYI_CD);
115 }
116
117 @Override
118 public boolean hasDisapprove() {
119 return hasAction(KewApiConstants.ACTION_TAKEN_DENIED_CD);
120 }
121
122 @Override
123 public boolean hasCancel() {
124 return hasAction(KewApiConstants.ACTION_TAKEN_CANCELED_CD);
125 }
126
127 @Override
128 public boolean hasRouted() {
129 return hasAction(KewApiConstants.ACTION_TAKEN_ROUTED_CD);
130 }
131
132 @Override
133 public boolean addApprove() {
134 return addAction(KewApiConstants.ACTION_TAKEN_APPROVED_CD);
135 }
136
137 @Override
138 public boolean addComplete() {
139 return addAction(KewApiConstants.ACTION_TAKEN_COMPLETED_CD);
140 }
141
142 @Override
143 public boolean addAcknowledge() {
144 return addAction(KewApiConstants.ACTION_TAKEN_ACKNOWLEDGED_CD);
145 }
146
147 @Override
148 public boolean addFyi() {
149 return addAction(KewApiConstants.ACTION_TAKEN_FYI_CD);
150 }
151
152 @Override
153 public boolean addDisapprove() {
154 return addAction(KewApiConstants.ACTION_TAKEN_DENIED_CD);
155 }
156
157 @Override
158 public boolean addCancel() {
159 return addAction(KewApiConstants.ACTION_TAKEN_CANCELED_CD);
160 }
161
162 @Override
163 public boolean addRouted() {
164 return addAction(KewApiConstants.ACTION_TAKEN_ROUTED_CD);
165 }
166
167 /**
168 * A builder which can be used to construct {@link DisplayParameters} instances. Enforces the constraints of the {@link DocumentContentContract}.
169 */
170 public final static class Builder implements Serializable, ModelBuilder, ActionSetContract {
171
172 private List<String> actionSet;
173
174 /**
175 * Private constructor for creating a builder with all of it's required attributes.
176 */
177 private Builder(List<String> actionSet) {
178 setActionSetList(actionSet);
179 }
180
181 public static Builder create() {
182 return new Builder(new ArrayList<String>());
183 }
184
185 /**
186 * Creates a builder by populating it with data from the given {@linkActionSet}.
187 *
188 * @param contract the contract from which to populate this builder
189 * @return an instance of the builder populated with data from the contract
190 */
191 public static Builder create(ActionSetContract contract) {
192 if (contract == null) {
193 throw new IllegalArgumentException("contract was null");
194 }
195 Builder builder = create();
196 return builder;
197 }
198
199 public ActionSet build() {
200 return new ActionSet(this);
201 }
202 public List<String> getActionSet() {
203 return this.actionSet;
204 }
205 public void setActionSetList(List<String> actionSet) {
206 this.actionSet = actionSet;
207 }
208
209 @Override
210 public boolean hasAction(String actionCode) {
211 return actionSet.contains(actionCode);
212 }
213
214 @Override
215 public boolean addAction(String actionCode) {
216 if (!actionSet.contains(actionCode)) {
217 actionSet.add(actionCode);
218 return true;
219 }
220 return false;
221 }
222
223 @Override
224 public boolean removeAction(String actionCode) {
225 return actionSet.remove(actionCode);
226 }
227
228 @Override
229 public boolean hasApprove() {
230 return hasAction(KewApiConstants.ACTION_TAKEN_APPROVED_CD);
231 }
232
233 @Override
234 public boolean hasComplete() {
235 return hasAction(KewApiConstants.ACTION_TAKEN_COMPLETED_CD);
236 }
237
238 @Override
239 public boolean hasAcknowledge() {
240 return hasAction(KewApiConstants.ACTION_TAKEN_ACKNOWLEDGED_CD);
241 }
242
243 @Override
244 public boolean hasFyi() {
245 return hasAction(KewApiConstants.ACTION_TAKEN_FYI_CD);
246 }
247
248 @Override
249 public boolean hasDisapprove() {
250 return hasAction(KewApiConstants.ACTION_TAKEN_DENIED_CD);
251 }
252
253 @Override
254 public boolean hasCancel() {
255 return hasAction(KewApiConstants.ACTION_TAKEN_CANCELED_CD);
256 }
257
258 @Override
259 public boolean hasRouted() {
260 return hasAction(KewApiConstants.ACTION_TAKEN_ROUTED_CD);
261 }
262
263 @Override
264 public boolean addApprove() {
265 return addAction(KewApiConstants.ACTION_TAKEN_APPROVED_CD);
266 }
267
268 @Override
269 public boolean addComplete() {
270 return addAction(KewApiConstants.ACTION_TAKEN_COMPLETED_CD);
271 }
272
273 /**
274 * This overridden method ...
275 *
276 * @see org.kuali.rice.kew.api.action.ActionSetContract#addAcknowledge()
277 */
278 @Override
279 public boolean addAcknowledge() {
280 return addAction(KewApiConstants.ACTION_TAKEN_ACKNOWLEDGED_CD);
281 }
282
283 @Override
284 public boolean addFyi() {
285 return addAction(KewApiConstants.ACTION_TAKEN_FYI_CD);
286 }
287
288 @Override
289 public boolean addDisapprove() {
290 return addAction(KewApiConstants.ACTION_TAKEN_DENIED_CD);
291 }
292
293 @Override
294 public boolean addCancel() {
295 return addAction(KewApiConstants.ACTION_TAKEN_CANCELED_CD);
296 }
297
298 @Override
299 public boolean addRouted() {
300 return addAction(KewApiConstants.ACTION_TAKEN_ROUTED_CD);
301 }
302 }
303
304 /**
305 * Defines some internal constants used on this class.
306 *
307 */
308 static class Constants {
309
310 final static String ROOT_ELEMENT_NAME = "actionSet";
311 final static String TYPE_NAME = "ActionSetType";
312 }
313
314 /**
315 * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
316 *
317 */
318 static class Elements {
319
320 final static String ACTION_SET_LIST = "actionSetList";
321 }
322 }