ProcessDetailsAction.java :  » Workflow-Engines » xflow1.2 » xflow » action » Java Open Source

Java Open Source » Workflow Engines » xflow1.2 
xflow1.2 » xflow » action » ProcessDetailsAction.java
package xflow.action;

import java.io.IOException;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.struts.action.*;
import org.apache.struts.Globals;

import xflow.client.*;
import xflow.security.*;
import xflow.common.*;
import xflow.forms.*;


public class ProcessDetailsAction extends Action {


  public ActionForward execute(ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException {


    // Default target to success
    String target = new String("success");

    try {

    //get the workflow Id
    WorkflowId workflowId = new WorkflowId(Integer.parseInt(request.getParameter("workflowId")));
    String processName = request.getParameter("processName");
    User user = new User("foo", "bar");

    //get workflow details for the workflow Id.
    WorkflowState workflowState = null;
    workflowState = WorkflowManager.getWorkflowState(workflowId, user);


    WorkflowProcess workflowProcess = new WorkflowProcess(workflowState.getWorkflowName(),
                                workflowState.getWorkflowVersion(),
                                  processName, null, user);


    // get the details for request process
    Vector activeProcesses = workflowState.getActiveProcesses();
    int numberOfActiveProcesses = activeProcesses.size();
    ProcessState requiredProcessState = null;

    for (int i = 0 ; i < numberOfActiveProcesses; i++) {
      ProcessState processState = (ProcessState) activeProcesses.elementAt(i);
      if (processName.equalsIgnoreCase(processState.getProcessName())) {
        requiredProcessState = processState;
        i = numberOfActiveProcesses + 1;
      }
    }


    // get the workItem for requested process
    WorkItem workItem = workflowProcess.getWorkItem(requiredProcessState.getWorkItemId());


    request.setAttribute("processState", requiredProcessState);
    request.setAttribute("workItem", workItem);

    /*request.setAttribute("processState", getDummyProcessState(processName, workflowId));
    request.setAttribute("workItem", getDummyWorkItem());*/


  } catch (Exception e) {
    e.printStackTrace();
    target = "failure";
  }

    // Forward to the appropriate View
    return (mapping.findForward(target));
  }



  private ProcessState getDummyProcessState(String processName, WorkflowId wId) {
    ProcessState p = new ProcessState();
    p.setProcessName(processName);
      p.setTimeStarted(new Date());
      p.setWorkflowId(wId);
      p.setWorkItemId(new WorkItemId(4));

      return p;

  }


  private WorkItem getDummyWorkItem() {
    WorkItem w = new WorkItem();
     w.setId(new WorkItemId(4)) ;
     w.setPayload("some payload") ;
     w.setPayloadType("xMl");

     HashMap h = new HashMap();
     h.put("name1", "value1");
     h.put("name2", "value2");
     h.put("name3", "value3");
     h.put("name4", "value4");
     h.put("name5", "value5");

     w.setProperties(h);


      return w;


  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.