KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > entities > mydesktop > WorkflowVO


1 /* ===============================================================================
2 *
3 * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4 *
5 * ===============================================================================
6 *
7 * Copyright (C) Mattias Bogeblad
8 *
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 2, as published by the
11 * Free Software Foundation. See the file LICENSE.html for more information.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19 * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20 *
21 * ===============================================================================
22 */

23
24 package org.infoglue.cms.entities.mydesktop;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.infoglue.cms.entities.kernel.BaseEntityVO;
31 import org.infoglue.cms.util.ConstraintExceptionBuffer;
32 import org.infoglue.cms.util.workflow.StepFilter;
33
34 /**
35  * This is the general action description object. Can be used by any workflow engine hopefully.
36  *
37  * @author Mattias Bogeblad
38  */

39
40 public class WorkflowVO implements BaseEntityVO
41 {
42     private static final long serialVersionUID = 1L;
43
44     public static final int STATUS_OK = 0;
45     public static final int STATUS_NOT_OK = 1;
46     
47     private Long JavaDoc workflowId;
48     private String JavaDoc name; // the name of the workflow
49
private String JavaDoc title; // the name of the workflow instance
50
private List JavaDoc declaredSteps = new ArrayList JavaDoc();
51     private List JavaDoc currentSteps = new ArrayList JavaDoc();
52     private List JavaDoc historySteps = new ArrayList JavaDoc();
53     private List JavaDoc initialActions = new ArrayList JavaDoc();
54     private List JavaDoc globalActions = new ArrayList JavaDoc();
55
56     private int status = STATUS_OK;
57     private String JavaDoc statusMessage = "";
58
59     public WorkflowVO() {}
60
61     public WorkflowVO(Long JavaDoc workflowId, String JavaDoc name)
62     {
63         setWorkflowId(workflowId);
64         setName(name);
65     }
66
67     public Integer JavaDoc getId()
68     {
69         return new Integer JavaDoc(workflowId.intValue());
70     }
71
72     public void setId(Integer JavaDoc id)
73     {
74         setWorkflowId(new Long JavaDoc(id.longValue()));
75     }
76
77     public long getIdAsPrimitive()
78     {
79         return (workflowId == null) ? 0 : workflowId.longValue();
80     }
81
82     public Long JavaDoc getWorkflowId()
83     {
84         return workflowId;
85     }
86
87     public void setWorkflowId(Long JavaDoc workflowId)
88     {
89         this.workflowId = workflowId;
90     }
91
92     public String JavaDoc getName()
93     {
94         return name;
95     }
96
97     public void setName(String JavaDoc name)
98     {
99         this.name = name;
100     }
101
102     public String JavaDoc getTitle()
103     {
104         return title;
105     }
106     
107     public void setTitle(final String JavaDoc title)
108     {
109         this.title = title;
110     }
111     
112     public List JavaDoc getDeclaredSteps()
113     {
114         return declaredSteps;
115     }
116
117     public void setDeclaredSteps(List JavaDoc steps)
118     {
119         declaredSteps = (steps == null) ? new ArrayList JavaDoc() : steps;
120     }
121
122     public List JavaDoc getCurrentSteps()
123     {
124         return currentSteps;
125     }
126
127     /**
128      * Returns all the current steps allowed by the given filter. Useful to restrict the current steps for display, e.g.
129      * return only the steps owned by the current user.
130      * @param filter a StepFilter
131      * @return the current steps allowed by filter
132      */

133     public List JavaDoc getCurrentSteps(StepFilter filter)
134     {
135         List JavaDoc filteredSteps = new ArrayList JavaDoc();
136         for (Iterator JavaDoc steps = currentSteps.iterator(); steps.hasNext();)
137         {
138             WorkflowStepVO step = (WorkflowStepVO)steps.next();
139             if (filter.isAllowed(step))
140                 filteredSteps.add(step);
141         }
142
143         return filteredSteps;
144     }
145
146     public void setCurrentSteps(List JavaDoc steps)
147     {
148         currentSteps = (steps == null) ? new ArrayList JavaDoc() : steps;
149     }
150
151     public List JavaDoc getHistorySteps()
152     {
153         return historySteps;
154     }
155
156     public void setHistorySteps(List JavaDoc steps)
157     {
158         historySteps = (steps == null) ? new ArrayList JavaDoc() : steps;
159     }
160
161     public List JavaDoc getInitialActions()
162     {
163         return initialActions;
164     }
165
166     public void setInitialActions(List JavaDoc actions)
167     {
168         initialActions = (actions == null) ? new ArrayList JavaDoc() : actions;
169     }
170
171     public List JavaDoc getGlobalActions()
172     {
173         return globalActions;
174     }
175
176     public void setGlobalActions(List JavaDoc actions)
177     {
178         globalActions = (actions == null) ? new ArrayList JavaDoc() : actions;
179     }
180
181     /**
182      * Returns the current and history steps
183      * @return a list of WorkflowStepVOs representing all current and history steps for this workflow
184      */

185     public List JavaDoc getSteps()
186     {
187         List JavaDoc steps = new ArrayList JavaDoc();
188         steps.addAll(currentSteps);
189         steps.addAll(historySteps);
190         return steps;
191     }
192
193     /**
194      * Returns the available actions, i.e., the actions associated with the current steps.
195      * @return a list of WorkflowActionVOs representing the available actions in this workflow.
196      */

197     public List JavaDoc getAvailableActions()
198     {
199         return getAvailableActions(null);
200     }
201
202     /**
203      * Returns the actions associated with the current steps allowed by the given step filter
204      * @param filter a step filter that allows the desired steps to pass through
205      * @return a list of WorkflowActionVOs representing the actions associated with the current steps allowed by filter
206      * @see #getCurrentSteps(StepFilter)
207      */

208     public List JavaDoc getAvailableActions(StepFilter filter)
209     {
210         List JavaDoc steps = (filter == null) ? currentSteps : getCurrentSteps(filter);
211         List JavaDoc availableActions = new ArrayList JavaDoc();
212
213         for (Iterator JavaDoc i = steps.iterator(); i.hasNext();)
214             availableActions.addAll(((WorkflowStepVO)i.next()).getActions());
215
216         return availableActions;
217     }
218
219     /**
220      * Returns the initial action with the given ID. Since the number of initial actions expected to be small, an
221      * iterative match works fine here. We don't need to introduce the overhead of a map until we get more than 5
222      * initial actions, which seems far-fetched for a realistic workflow.
223      * @param id the id of the desired initial action
224      * @return the initial action with id
225      * @throws IllegalArgumentException if no initial action exists with id
226      * @throws NullPointerException if id is null.
227      */

228     public WorkflowActionVO getInitialAction(Integer JavaDoc id)
229     {
230         for (Iterator JavaDoc actions = initialActions.iterator(); actions.hasNext();)
231         {
232             WorkflowActionVO action = (WorkflowActionVO)actions.next();
233             if (id.equals(action.getId()))
234                 return action;
235         }
236
237         throw new IllegalArgumentException JavaDoc("Initial action " + id + " does not exist in workflow " + name);
238     }
239
240     public String JavaDoc toString()
241     {
242         return new StringBuffer JavaDoc(getClass().getName())
243                 .append(" name=").append(name)
244                 .append(" workflowId=").append(workflowId)
245                 .append(" declaredSteps=").append(declaredSteps.size())
246                 .append(" currentSteps=").append(currentSteps.size())
247                 .append(" historySteps=").append(historySteps.size())
248                 .append(" historySteps=").append(historySteps.size())
249                 .append(" globalActions=").append(globalActions.size()).toString();
250     }
251
252     public ConstraintExceptionBuffer validate()
253     {
254         return new ConstraintExceptionBuffer();
255     }
256
257     public String JavaDoc getStatusMessage()
258     {
259         return statusMessage;
260     }
261
262     public void setStatusMessage(String JavaDoc statusMessage)
263     {
264         this.statusMessage = statusMessage;
265     }
266
267     public int getStatus()
268     {
269         return status;
270     }
271
272     public void setStatus(int status)
273     {
274         this.status = status;
275     }
276 }
277
Popular Tags