001: package xflow.action;
002:
003: import java.io.IOException;
004: import java.util.*;
005: import javax.servlet.*;
006: import javax.servlet.http.*;
007:
008: import org.apache.struts.action.*;
009: import org.apache.struts.Globals;
010:
011: import xflow.client.*;
012: import xflow.security.*;
013: import xflow.common.*;
014: import xflow.forms.*;
015:
016: public class ProcessDetailsAction extends Action {
017:
018: public ActionForward execute(ActionMapping mapping,
019: ActionForm form, HttpServletRequest request,
020: HttpServletResponse response) throws IOException,
021: ServletException {
022:
023: // Default target to success
024: String target = new String("success");
025:
026: try {
027:
028: //get the workflow Id
029: WorkflowId workflowId = new WorkflowId(Integer
030: .parseInt(request.getParameter("workflowId")));
031: String processName = request.getParameter("processName");
032: User user = new User("foo", "bar");
033:
034: //get workflow details for the workflow Id.
035: WorkflowState workflowState = null;
036: workflowState = WorkflowManager.getWorkflowState(
037: workflowId, user);
038:
039: WorkflowProcess workflowProcess = new WorkflowProcess(
040: workflowState.getWorkflowName(), workflowState
041: .getWorkflowVersion(), processName, null,
042: user);
043:
044: // get the details for request process
045: Vector activeProcesses = workflowState.getActiveProcesses();
046: int numberOfActiveProcesses = activeProcesses.size();
047: ProcessState requiredProcessState = null;
048:
049: for (int i = 0; i < numberOfActiveProcesses; i++) {
050: ProcessState processState = (ProcessState) activeProcesses
051: .elementAt(i);
052: if (processName.equalsIgnoreCase(processState
053: .getProcessName())) {
054: requiredProcessState = processState;
055: i = numberOfActiveProcesses + 1;
056: }
057: }
058:
059: // get the workItem for requested process
060: WorkItem workItem = workflowProcess
061: .getWorkItem(requiredProcessState.getWorkItemId());
062:
063: request.setAttribute("processState", requiredProcessState);
064: request.setAttribute("workItem", workItem);
065:
066: /*request.setAttribute("processState", getDummyProcessState(processName, workflowId));
067: request.setAttribute("workItem", getDummyWorkItem());*/
068:
069: } catch (Exception e) {
070: e.printStackTrace();
071: target = "failure";
072: }
073:
074: // Forward to the appropriate View
075: return (mapping.findForward(target));
076: }
077:
078: private ProcessState getDummyProcessState(String processName,
079: WorkflowId wId) {
080: ProcessState p = new ProcessState();
081: p.setProcessName(processName);
082: p.setTimeStarted(new Date());
083: p.setWorkflowId(wId);
084: p.setWorkItemId(new WorkItemId(4));
085:
086: return p;
087:
088: }
089:
090: private WorkItem getDummyWorkItem() {
091: WorkItem w = new WorkItem();
092: w.setId(new WorkItemId(4));
093: w.setPayload("some payload");
094: w.setPayloadType("xMl");
095:
096: HashMap h = new HashMap();
097: h.put("name1", "value1");
098: h.put("name2", "value2");
099: h.put("name3", "value3");
100: h.put("name4", "value4");
101: h.put("name5", "value5");
102:
103: w.setProperties(h);
104:
105: return w;
106:
107: }
108: }
|