01: package org.jbpm.command;
02:
03: import java.util.ArrayList;
04: import java.util.Arrays;
05: import java.util.Iterator;
06: import java.util.List;
07:
08: import org.apache.commons.logging.Log;
09: import org.apache.commons.logging.LogFactory;
10: import org.jbpm.JbpmContext;
11: import org.jbpm.taskmgmt.exe.TaskInstance;
12:
13: /**
14: * return a {@link java.util.List} of {@link org.jbpm.taskmgmt.exe.TaskInstance}s
15: * for the given actor(s).
16: *
17: * if no actor is used, the current authenticated user is taken as actor.
18: *
19: * for all actors it is checked, if they are pooled or assigned actor!
20: *
21: * @author Bernd Ruecker (bernd.ruecker@camunda.com)
22: */
23: public class GetTaskListCommand extends AbstractGetObjectBaseCommand
24: implements Command {
25:
26: private static final long serialVersionUID = -1627380259541998349L;
27:
28: static final Log log = LogFactory.getLog(GetTaskListCommand.class);
29:
30: private String[] actor;
31:
32: public GetTaskListCommand(String[] actor) {
33: setActor(actor);
34: }
35:
36: public GetTaskListCommand(String actor, boolean includeVariables) {
37: super (includeVariables, false);
38: setActor(actor);
39: }
40:
41: public GetTaskListCommand(String actor, String[] variablesToInclude) {
42: super (variablesToInclude);
43: setActor(actor);
44: }
45:
46: public Object execute(JbpmContext jbpmContext) throws Exception {
47: setJbpmContext(jbpmContext);
48: List result = null;
49: if (actor == null || actor.length == 0)
50: result = jbpmContext.getTaskList();
51: else {
52: result = new ArrayList();
53: for (int i = 0; i < actor.length; i++) {
54: result.addAll(jbpmContext.getTaskList(actor[i]));
55: }
56: result.addAll(jbpmContext.getGroupTaskList(Arrays
57: .asList(actor)));
58: }
59:
60: return retrieveTaskInstanceDetails(result);
61: }
62:
63: /**
64: * access everything on all TaskInstance objects, which is not in the
65: * default fetch group from hibernate, but needs to be accesible from the
66: * client
67: *
68: * overwrite this, if you need more details in your client
69: */
70: public List retrieveTaskInstanceDetails(List taskInstanceList) {
71: for (Iterator iter = taskInstanceList.iterator(); iter
72: .hasNext();) {
73: retrieveTaskInstanceDetails((TaskInstance) iter.next());
74: }
75: return taskInstanceList;
76: }
77:
78: public String[] getActor() {
79: return actor;
80: }
81:
82: public void setActor(String actor) {
83: this .actor = new String[] { actor };
84: }
85:
86: public void setActor(String[] actor) {
87: this.actor = actor;
88: }
89: }
|