Пример #1
0
 public void transactionEnteringState(State stateVal, WorkflowTransactionPhase phase)
     throws WorkflowException {
   try {
     // flip the phase to active.
     phase.setStatus(ContractsUtils.getWorkflowStatusCommand().getActiveStatus().getId());
     ContractsUtils.getTransactionPhaseCommand().updateTransactionPhase(phase);
   } catch (ApplicationException ae) {
     LOG.log(Level.SEVERE, "An error occurred while updating phase " + phase.getId(), ae);
     throw new WorkflowException(
         "The transaction failed while entering state "
             + stateVal.getId()
             + ".  The root cause is: "
             + ae.getMessage());
   }
 }
Пример #2
0
  public ArrayList computeTransitions(State stateVal, String outcome) throws WorkflowException {
    if (LOG.isLoggable(Level.FINE)) {
      LOG.entering(State.class.getName(), "computeTransitions", outcome);
    }

    ArrayList results = new ArrayList();
    Transition[] transitions = null;

    try {
      transitions =
          ContractsUtils.getTransitionCommand().getTransitionsByFromStateId(stateVal.getId());

      for (int i = 0; i < transitions.length; i++) {
        Transition tran = transitions[i];
        if (tran.match(outcome)) {
          results.add(tran);
          break;
        }
      }
      // look for Workflow global transitions in the PROP_SET for the workflow
      Workflow wf = ContractsUtils.getWorkflowCommand().getWorkflowById(stateVal.getWorkflowId());
      GenericPropertySet gps = wf.getPropertySet();
      if (gps != null) {
        Iterator it = gps.keys();
        while (it.hasNext()) {
          String name = (String) it.next();
          if (name.startsWith("global.transition_")) {
            String tranName = gps.getProperty(name);
            if (tranName != null) {
              String tranOutcome = gps.getProperty("transition." + tranName + ".outcome");
              if ((tranOutcome == null && outcome == null) || tranOutcome.equals(outcome)) {
                Transition globalTran =
                    ContractsUtils.getTransitionCommand()
                        .getTransitionObjectByImplId(
                            new Integer(gps.getProperty("transition." + tranName + ".implId"))
                                .intValue());
                globalTran.setId(-1);
                globalTran.setFromStateId(stateVal.getId());
                String toState = gps.getProperty("transition." + tranName + ".toState");
                if (toState != null) {
                  if (toState.equals("_#fromState")) {
                    globalTran.setToStateId(stateVal.getId());
                  } else {
                    globalTran.setToStateId(
                        new Integer(
                                ServiceLocator.getInstance()
                                    .getLocal(StateCommandLocal.class)
                                    .getStateByNameAndWorkflowId(toState, wf.getId())
                                    .getId())
                            .intValue());
                  }
                  results.add(globalTran);
                } else {
                  LOG.log(
                      Level.SEVERE,
                      "Global transition " + tranName + " does not specify a toState");
                }
              }
            } else {
              LOG.log(
                  Level.SEVERE,
                  "Global transition key " + name + " does not specify a transition name");
            }
          }
        }
      }
      if (results.size() == 0) {
        Transition defTran =
            ContractsUtils.getTransitionCommand()
                .getTransitionById(stateVal.getDefaultTransitionId());
        if (defTran != null) results.add(defTran);
        else
          throw new WorkflowException(
              "No Transitions exist for this State ["
                  + stateVal.getId()
                  + "] for outcome: ["
                  + outcome
                  + "]!");
      }

    } catch (ApplicationException ae) {
      LOG.log(
          Level.SEVERE,
          "An error occurred while processing transitions from state " + stateVal.getId(),
          ae);
      throw new WorkflowException(
          "An unexpected error occurred while processing the workflow transition: "
              + ae.getMessage());
    } catch (Exception e) {
      LOG.log(
          Level.SEVERE,
          "An error occurred while processing transitions from state " + stateVal.getId(),
          e);
      throw new WorkflowException(
          "An unexpected error occurred while processing the workflow transition: "
              + e.getMessage());
    }

    if (LOG.isLoggable(Level.FINE)) {
      LOG.exiting(State.class.getName(), "computeTransitions", String.valueOf(results.size()));
    }
    return results;
  }