001: package org.jbpm.command;
002:
003: import java.util.Iterator;
004: import java.util.List;
005: import java.util.Map;
006:
007: import org.jbpm.JbpmContext;
008: import org.jbpm.context.exe.VariableContainer;
009: import org.jbpm.graph.exe.ProcessInstance;
010: import org.jbpm.taskmgmt.exe.TaskInstance;
011:
012: /**
013: * This command can retrieve a task instance (for client) with the given task-id
014: * or the token-id (then, the first task for the token is searched)
015: *
016: * @author Bernd Ruecker (bernd.ruecker@camunda.com)
017: */
018: public class GetTaskInstanceCommand extends
019: AbstractGetObjectBaseCommand {
020:
021: private static final long serialVersionUID = -8436697080972165601L;
022:
023: private long taskInstanceId;
024:
025: /**
026: * if given, all tasks for this token are searched and a List of
027: * TaskInstances is given
028: */
029: private long tokenId;
030:
031: /**
032: * if given, all tasks for this process are searched and a List of
033: * TaskInstances is given
034: */
035: private long processInstanceId;
036:
037: /**
038: * NOT YET USED! JUST TO DOCUMENT THE IDEA...
039: *
040: * result of the Command: a gui element, configured via the TaskController.
041: * Can be used to identify a Swing-Class, JSF-Site, ...
042: */
043: private String configuredGuiElement;
044:
045: public GetTaskInstanceCommand() {
046: }
047:
048: public GetTaskInstanceCommand(long taskInstanceId) {
049: this .taskInstanceId = taskInstanceId;
050: }
051:
052: public GetTaskInstanceCommand(long taskInstanceId,
053: boolean includeVariables, boolean includeLogs) {
054: super (includeVariables, includeLogs);
055: this .taskInstanceId = taskInstanceId;
056: }
057:
058: public GetTaskInstanceCommand(long taskInstanceId,
059: String[] variablesToInclude) {
060: super (variablesToInclude);
061: this .taskInstanceId = taskInstanceId;
062: }
063:
064: public Object execute(JbpmContext jbpmContext) throws Exception {
065:
066: if (taskInstanceId > 0) {
067: TaskInstance taskInstance = jbpmContext
068: .getTaskInstance(taskInstanceId);
069: if (taskInstance != null) {
070: retrieveTaskInstanceDetails(taskInstance);
071: }
072:
073: return taskInstance;
074: } else if (tokenId > 0) {
075: List result = jbpmContext.getTaskMgmtSession()
076: .findTaskInstancesByToken(tokenId);
077: for (Iterator iter = result.iterator(); iter.hasNext();) {
078: TaskInstance ti = (TaskInstance) iter.next();
079: retrieveTaskInstanceDetails(ti);
080: }
081: return result;
082: } else if (processInstanceId > 0) {
083: List result = jbpmContext
084: .getTaskMgmtSession()
085: .findTaskInstancesByProcessInstance(
086: jbpmContext
087: .getProcessInstance(processInstanceId));
088: for (Iterator iter = result.iterator(); iter.hasNext();) {
089: TaskInstance ti = (TaskInstance) iter.next();
090: retrieveTaskInstanceDetails(ti);
091: }
092: return result;
093: } else
094: return null;
095: }
096:
097: public long getTaskInstanceId() {
098: return taskInstanceId;
099: }
100:
101: public void setTaskInstanceId(long taskInstanceId) {
102: this .taskInstanceId = taskInstanceId;
103: }
104:
105: public long getTokenId() {
106: return tokenId;
107: }
108:
109: public void setTokenId(long tokenId) {
110: this .tokenId = tokenId;
111: }
112:
113: public long getProcessInstanceId() {
114: return processInstanceId;
115: }
116:
117: public void setProcessInstanceId(long processInstanceId) {
118: this.processInstanceId = processInstanceId;
119: }
120:
121: }
|