Beispiel #1
0
  public void testAddComments() throws BonitaException {
    ProcessDefinition definition =
        ProcessBuilder.createProcess("feed", "1.0")
            .addHuman(getLogin())
            .addHumanTask("sala", getLogin())
            .done();
    definition = getManagementAPI().deploy(getBusinessArchive(definition));
    final ProcessDefinitionUUID processUUID = definition.getUUID();
    final ProcessInstanceUUID instanceUUID = getRuntimeAPI().instantiateProcess(processUUID);

    Collection<ActivityInstance> acts =
        this.getQueryRuntimeAPI().getActivityInstances(instanceUUID, "sala");
    assertEquals(1, acts.size());
    ActivityInstance activityInst = acts.iterator().next();

    getRuntimeAPI().addComment(instanceUUID, "First comment", "john");
    getRuntimeAPI().addComment(activityInst.getUUID(), "Done", "joe");

    List<Comment> feed = this.getQueryRuntimeAPI().getCommentFeed(instanceUUID);
    assertEquals(2, feed.size());
    Comment c = new CommentImpl(feed.get(0));
    assertEquals("First comment", c.getMessage());
    assertEquals("john", c.getUserId());
    assertNotNull(c.getDate());
    assertNull(c.getActivityUUID());

    Comment c1 = new CommentImpl(feed.get(1));
    assertEquals("Done", c1.getMessage());
    assertEquals("joe", c1.getUserId());
    assertNotNull(c1.getDate());
    assertEquals(activityInst.getUUID(), c1.getActivityUUID());

    getManagementAPI().deleteProcess(processUUID);
  }
 public void execute(APIAccessor accessor, ActivityInstance<ActivityBody> activity)
     throws Exception {
   // Retrieve workflow session creator and set the instance property
   // "initiator" with it
   String user_Name =
       accessor
           .getQueryRuntimeAPI()
           .getProcessInstance(activity.getProcessInstanceUUID())
           .getStartedBy();
   accessor
       .getRuntimeAPI()
       .setProcessInstanceVariable(
           activity.getProcessInstanceUUID(), PROCESS_INITIATOR_USER_NAME, user_Name);
   accessor
       .getRuntimeAPI()
       .setActivityInstanceVariable(activity.getUUID(), CHOICE_PROPERTY_NAME, "enough");
 }
Beispiel #3
0
 public void execute(APIAccessor accessor, ActivityInstance activityInstance) throws Exception {
   RuntimeAPI runtimeAPI = accessor.getRuntimeAPI();
   runtimeAPI.setProcessInstanceVariable(activityInstance.getProcessInstanceUUID(), "cont", "0");
 }
Beispiel #4
0
  @Test
  public void testGetSubprocessLoopNextTask() throws Exception {
    RuntimeAPI runtimeAPI = AccessorUtil.getRuntimeAPI();
    ManagementAPI managementAPI = AccessorUtil.getManagementAPI();
    QueryRuntimeAPI queryRuntimeAPI = AccessorUtil.getQueryRuntimeAPI();
    IFormWorkflowAPI api = FormAPIFactory.getFormWorkflowAPI();

    ProcessDefinition childProcess =
        ProcessBuilder.createProcess("sub_process", "1.0")
            .addIntegerData("counter")
            .addHuman("john")
            .addHumanTask("task1", "john")
            .addHumanTask("task2", "john")
            .addConnector(Event.taskOnFinish, SetVarConnector.class.getName(), true)
            .addInputParameter("variableName", "counter")
            .addInputParameter("value", "${++counter}")
            .addTransition("transition1", "task1", "task2")
            .done();

    ProcessDefinition processWithSubProcess =
        ProcessBuilder.createProcess("parent_process", "1.0")
            .addHuman("john")
            .addIntegerData("counter", 0)
            .addSubProcess("subprocess", "sub_process")
            .addSubProcessInParameter("counter", "counter")
            .addSubProcessOutParameter("counter", "counter")
            .addLoop("counter < 10", false)
            .addHumanTask("task3", "john")
            .addTransition("transition2", "subprocess", "task3")
            .done();

    BusinessArchive childBusinessArchive = BusinessArchiveFactory.getBusinessArchive(childProcess);
    childProcess = managementAPI.deploy(childBusinessArchive);

    BusinessArchive parentBusinessArchive =
        BusinessArchiveFactory.getBusinessArchive(processWithSubProcess);
    processWithSubProcess = managementAPI.deploy(parentBusinessArchive);

    ProcessInstanceUUID processInstanceUUID =
        runtimeAPI.instantiateProcess(processWithSubProcess.getUUID());

    try {
      for (int i = 0; i < 10; i++) {
        Set<ActivityInstance> activityInstances =
            queryRuntimeAPI.getActivityInstances(processInstanceUUID);
        Assert.assertEquals(i + 1, activityInstances.size());
        for (ActivityInstance activityInstance : activityInstances) {
          Assert.assertEquals("subprocess", activityInstance.getActivityName());
        }

        ProcessInstance processInstance = queryRuntimeAPI.getProcessInstance(processInstanceUUID);
        Set<ProcessInstanceUUID> childrenInstanceUUID = processInstance.getChildrenInstanceUUID();
        for (ProcessInstanceUUID childInstanceUUID : childrenInstanceUUID) {
          ProcessInstance childInstance = queryRuntimeAPI.getProcessInstance(childInstanceUUID);
          if (InstanceState.STARTED.equals(childInstance.getInstanceState())) {
            Collection<TaskInstance> taskInstances =
                queryRuntimeAPI.getTaskList(childInstanceUUID, ActivityState.READY);
            Assert.assertEquals(1, taskInstances.size());
            TaskInstance childTaskInstance = taskInstances.iterator().next();
            Assert.assertEquals("task1", childTaskInstance.getActivityName());
            Assert.assertEquals(ActivityState.READY, childTaskInstance.getState());
            runtimeAPI.executeTask(childTaskInstance.getUUID(), true);

            taskInstances = queryRuntimeAPI.getTaskList(childInstanceUUID, ActivityState.READY);
            Assert.assertEquals(1, taskInstances.size());
            childTaskInstance = taskInstances.iterator().next();
            Assert.assertEquals("task2", childTaskInstance.getActivityName());
            Assert.assertEquals(ActivityState.READY, childTaskInstance.getState());
            runtimeAPI.executeTask(childTaskInstance.getUUID(), true);

            if (i < 9) {
              ActivityInstanceUUID activityInstanceUUID =
                  api.getRelatedProcessesNextTask(childInstance.getUUID());
              Assert.assertEquals("task1", activityInstanceUUID.getActivityName());
            }

            childInstance = queryRuntimeAPI.getProcessInstance(childInstanceUUID);
            Assert.assertEquals(InstanceState.FINISHED, childInstance.getInstanceState());
          }
        }
      }

      Collection<TaskInstance> taskInstances =
          queryRuntimeAPI.getTaskList(processInstanceUUID, ActivityState.READY);
      Assert.assertEquals(1, taskInstances.size());
      TaskInstance taskInstance = taskInstances.iterator().next();
      Assert.assertEquals("task3", taskInstance.getActivityName());
      Assert.assertEquals(ActivityState.READY, taskInstance.getState());
      runtimeAPI.executeTask(taskInstance.getUUID(), true);
    } finally {
      managementAPI.deleteProcess(processWithSubProcess.getUUID());
      managementAPI.deleteProcess(childProcess.getUUID());
    }
  }