1 package org.apache.fulcrum.osworkflow;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import java.util.Iterator;
24 import java.util.List;
25
26 import org.apache.avalon.framework.activity.Disposable;
27 import org.apache.avalon.framework.activity.Initializable;
28 import org.apache.avalon.framework.configuration.Configurable;
29 import org.apache.avalon.framework.configuration.Configuration;
30 import org.apache.avalon.framework.configuration.ConfigurationException;
31 import org.apache.avalon.framework.logger.AbstractLogEnabled;
32 import org.apache.avalon.framework.thread.ThreadSafe;
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35
36 import com.opensymphony.workflow.Workflow;
37 import com.opensymphony.workflow.WorkflowException;
38 import com.opensymphony.workflow.basic.BasicWorkflow;
39 import com.opensymphony.workflow.query.WorkflowQuery;
40
41 /***
42 * This service provides a simple interface to the
43 * OSWorkflow Engine. You can also directly access
44 * the OSWorkflow engine.
45 *
46 * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
47 * @version $Id: DefaultWorkflowService.java 535465 2007-05-05 06:58:06Z tv $
48 */
49 public class DefaultWorkflowService
50 extends AbstractLogEnabled
51 implements WorkflowService, Configurable, Initializable, Disposable, ThreadSafe
52 {
53
54 /*** The log. */
55 private static Log log = LogFactory.getLog(DefaultWorkflowService.class);
56 /***
57 * For a specific caller and status, return all the workflows.
58 *
59 * @param caller The name of the caller.
60 * @param status The status of the workflows to retreive. Definied by the workflow.xml file
61 * @return An array of long's for the workflow ID's.
62 */
63 public long[] retrieveWorkflows(String caller, String status)
64 throws WorkflowException
65 {
66 Workflow wf = retrieveWorkflow(caller);
67 WorkflowQuery queryLeft =
68 new WorkflowQuery(
69 WorkflowQuery.OWNER,
70 WorkflowQuery.CURRENT,
71 WorkflowQuery.EQUALS,
72 caller);
73 WorkflowQuery queryRight =
74 new WorkflowQuery(
75 WorkflowQuery.STATUS,
76 WorkflowQuery.CURRENT,
77 WorkflowQuery.EQUALS,
78 status);
79 WorkflowQuery query =
80 new WorkflowQuery(queryLeft, WorkflowQuery.AND, queryRight);
81 List workflows = wf.query(query);
82 long workflowIds[] = new long[workflows.size()];
83 int counter = 0;
84 for (Iterator i = workflows.iterator(); i.hasNext(); counter++)
85 {
86 Long workflowId = (Long) i.next();
87 workflowIds[counter] = workflowId.longValue();
88 }
89 return workflowIds;
90 }
91 /***
92 * Retrives a workflow based on the caller
93 *
94 * @param caller The workflow for this caller.
95 */
96 public Workflow retrieveWorkflow(String caller)
97 {
98 return new BasicWorkflow(caller);
99 }
100
101
102 /***
103 * Avalon component configure lifecycle method
104 */
105 public void configure(Configuration conf) throws ConfigurationException
106 {
107 }
108 /***
109 * Avalon component initialize lifecycle method
110 */
111 public void initialize() throws Exception
112 {
113 WorkflowServiceFacade.setWorkflowService(this);
114 if (log.isInfoEnabled())
115 {
116 log.info("OSWorkflow Service is Initialized now..");
117 }
118 }
119
120 /***
121 * Avalon component disposelifecycle method
122 */
123 public void dispose()
124 {
125 }
126 }