コード例 #1
0
  /**
   * Invokes an action on a workflow for a given user and request
   *
   * @param principal the user principal
   * @param workflowId the ID of the desired workflow
   * @param actionId the ID of the desired action
   * @param inputs the inputs to the workflow
   * @return a WorkflowVO representing the current state of the workflow identified by workflowId
   * @throws WorkflowException if a workflow error occurs
   */
  public WorkflowVO invokeAction(
      InfoGluePrincipal principal, long workflowId, int actionId, Map inputs)
      throws WorkflowException {
    WorkflowVO workflowVO = null;

    Session session = null;
    net.sf.hibernate.Transaction tx = null;

    try {
      session = hibernateSessionFactory.openSession();

      tx = session.beginTransaction();

      WorkflowFacade wf =
          new WorkflowFacade(principal, workflowId, hibernateSessionFactory, session);
      wf.doAction(actionId, inputs);

      session.flush();

      tx.commit();
    } catch (Exception e) {
      logger.error(
          "An error occurred when we tries to execute invokeAction():" + e.getMessage(), e);
      try {
        tx.rollback();
      } catch (HibernateException he) {
        logger.error(
            "An error occurred when we tries to rollback transaction:" + he.getMessage(), he);
      }
      restoreSessionFactory(e);
    } finally {
      try {
        session.close();
      } catch (HibernateException e) {
        logger.error("An error occurred when we tries to close session:" + e.getMessage(), e);
      }
    }

    try {
      session = hibernateSessionFactory.openSession();

      tx = session.beginTransaction();

      WorkflowFacade wf =
          new WorkflowFacade(principal, workflowId, hibernateSessionFactory, session);

      workflowVO = wf.createWorkflowVO();

      session.flush();

      tx.commit();
    } catch (Exception e) {
      logger.error(
          "An error occurred when we tries to execute invokeAction():" + e.getMessage(), e);
      try {
        tx.rollback();
      } catch (HibernateException he) {
        logger.error(
            "An error occurred when we tries to rollback transaction:" + he.getMessage(), he);
      }
      restoreSessionFactory(e);
    } finally {
      try {
        session.close();
      } catch (HibernateException e) {
        logger.error("An error occurred when we tries to close session:" + e.getMessage(), e);
      }
    }

    return workflowVO;
  }