コード例 #1
0
  public void moveToHistory(Step step) {
    List currentSteps =
        (List) SerializableCache.getInstance().currentStepsCache.get(new Long(step.getEntryId()));

    List historySteps =
        (List) SerializableCache.getInstance().historyStepsCache.get(new Long(step.getEntryId()));

    if (historySteps == null) {
      historySteps = new ArrayList();
      SerializableCache.getInstance()
          .historyStepsCache
          .put(new Long(step.getEntryId()), historySteps);
    }

    SimpleStep simpleStep = (SimpleStep) step;

    for (Iterator iterator = currentSteps.iterator(); iterator.hasNext(); ) {
      Step currentStep = (Step) iterator.next();

      if (simpleStep.getId() == currentStep.getId()) {
        iterator.remove();
        historySteps.add(simpleStep);

        break;
      }
    }

    SerializableCache.store();
  }
コード例 #2
0
  public Step markFinished(Step step, int actionId, Date finishDate, String status, String caller) {
    List currentSteps =
        (List) SerializableCache.getInstance().currentStepsCache.get(new Long(step.getEntryId()));

    for (Iterator iterator = currentSteps.iterator(); iterator.hasNext(); ) {
      SimpleStep theStep = (SimpleStep) iterator.next();

      if (theStep.getId() == step.getId()) {
        theStep.setStatus(status);
        theStep.setActionId(actionId);
        theStep.setFinishDate(finishDate);
        theStep.setCaller(caller);

        return theStep;
      }
    }

    SerializableCache.store();

    return null;
  }
コード例 #3
0
  public static void main(String args[]) {
    try {
      DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();

      // Define a bean and register it
      beanFactory.registerSingleton("args", Arrays.asList(args));
      GenericApplicationContext cmdArgCxt = new GenericApplicationContext(beanFactory);
      // Must call refresh to initialize context
      cmdArgCxt.refresh();

      String configs[] = {"/META-INF/spring/app-config.xml"};
      AbstractApplicationContext context = new ClassPathXmlApplicationContext(configs, cmdArgCxt);
      context.registerShutdownHook();
      Workflow workflow = (Workflow) context.getBean("workflow");
      System.out.println("Workflow names:");
      int i = 1;
      for (String name : workflow.getWorkflowNames()) {
        System.out.format("%02d) %s%n", i++, name);
      }

      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

      System.out.print("User: "******"caller", username);

      String command;
      do {
        try {
          System.out.print("Enter command: ");
          command = in.readLine();

          if (command == null || "q".equals(command) || "quit".equals(command)) break;

          if ("log".equals(command)) {
            System.out.print("User: "******"caller", username);
          }
          if ("init".equals(command)) {
            System.out.print("Workflow name: ");
            String workflowName = in.readLine();

            long id = workflow.initialize(workflowName, 1, inputs);
            System.out.println("Workflow initialized with id: " + id);
          } else if ("desc".equals(command)) {
            System.out.print("Workflow ID: ");
            long id = Long.parseLong(in.readLine());

            String workflowName = workflow.getWorkflowName(id);
            WorkflowDescriptor descriptor = workflow.getWorkflowDescriptor(workflowName);

            System.out.print("Workflow state: ");
            switch (workflow.getEntryState(id)) {
              case WorkflowEntry.CREATED:
                System.out.println("CREATED");
                break;
              case WorkflowEntry.ACTIVATED:
                System.out.println("ACTIVATED");
                break;
              case WorkflowEntry.SUSPENDED:
                System.out.println("SUSPENDED");
                break;
              case WorkflowEntry.KILLED:
                System.out.println("KILLED");
                break;
              case WorkflowEntry.COMPLETED:
                System.out.println("COMPLETED");
                break;
              default:
                System.out.println("UNKNOWN");
            }

            List<Step> currentSteps = workflow.getCurrentSteps(id);
            System.out.println("Current steps:");
            int j = 0;
            for (Step step : currentSteps) {
              ++j;
              StepDescriptor stepDesc = descriptor.getStep(step.getStepId());
              System.out.println("Meta attributes:");
              System.out.format("\t%s%n", stepDesc.getMetaAttributes().toString());
              System.out.format(
                  "%02d) %s (%s - %s)%n",
                  step.getStepId(), stepDesc.getName(), step.getStatus(), step.getOwner());
            }

            int[] availableActions = workflow.getAvailableActions(id, inputs);
            System.out.println("Available actions:");
            for (j = 0; j < availableActions.length; j++) {
              ActionDescriptor action = descriptor.getAction(availableActions[j]);
              System.out.println(String.format("%02d) %s", availableActions[j], action.getName()));
            }
          } else if ("exec".equals(command)) {
            System.out.print("Workflow ID: ");
            long id = Long.parseLong(in.readLine());
            System.out.print("Action ID: ");
            int actionId = Integer.parseInt(in.readLine());

            workflow.doAction(id, actionId, inputs);
          } else if ("query".equals(command)) {
            Set<WorkflowNameAndStep> stepInfos = new LinkedHashSet<WorkflowNameAndStep>();
            stepInfos.add(new WorkflowNameAndStep(1, "example"));
            stepInfos.add(new WorkflowNameAndStep(2, "sp3-moderation"));
            List ids = workflow.getWorkflowsByNamesAndSteps(stepInfos);
            System.out.println("Found ids are: " + ids);
          }
        } catch (Exception e) {
          e.printStackTrace();
        }

        System.out.println("-------------------------------------");
      } while (true);

      System.out.println("Exiting");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }