コード例 #1
0
  @Test
  public void testGetDefinitionAttachmentFileName() throws Exception {
    ManagementAPI managementAPI = AccessorUtil.getManagementAPI();

    File attachmentFile = File.createTempFile("attachment-test", ".txt");
    FileOutputStream fileOutputStream = new FileOutputStream(attachmentFile);
    fileOutputStream.write("test".getBytes("UTF-8"));
    fileOutputStream.close();

    ProcessDefinition attachmentProcess =
        ProcessBuilder.createProcess("attachment_process", "1.0")
            .addAttachment("attachment", attachmentFile.getPath(), attachmentFile.getName())
            .addHuman("john")
            .addHumanTask("task1", "john")
            .addHumanTask("task2", "john")
            .addTransition("transition", "task1", "task2")
            .done();

    BusinessArchive businessArchive = BusinessArchiveFactory.getBusinessArchive(attachmentProcess);
    attachmentProcess = managementAPI.deploy(businessArchive);

    try {
      IFormWorkflowAPI api = FormAPIFactory.getFormWorkflowAPI();
      String fileName = api.getAttachmentFileName(attachmentProcess.getUUID(), "${attachment}");
      Assert.assertEquals(attachmentFile.getName(), fileName);
    } finally {
      AccessorUtil.getCommandAPI()
          .execute(new WebDeleteDocumentsOfProcessCommand(attachmentProcess.getUUID()));
      AccessorUtil.getCommandAPI()
          .execute(new WebDeleteProcessCommand(attachmentProcess.getUUID()));
    }
  }
コード例 #2
0
  @Test
  public void testGetActivityAttachmentFileName() throws Exception {
    RuntimeAPI runtimeAPI = AccessorUtil.getRuntimeAPI();
    ManagementAPI managementAPI = AccessorUtil.getManagementAPI();
    QueryRuntimeAPI queryRuntimeAPI = AccessorUtil.getQueryRuntimeAPI();

    File attachmentFile = File.createTempFile("attachment-test", ".txt");
    FileOutputStream fileOutputStream = new FileOutputStream(attachmentFile);
    fileOutputStream.write("test".getBytes("UTF-8"));
    fileOutputStream.close();

    ProcessDefinition attachmentProcess =
        ProcessBuilder.createProcess("attachment_process", "1.0")
            .addAttachment("attachment", attachmentFile.getPath(), attachmentFile.getName())
            .addHuman("john")
            .addHumanTask("task1", "john")
            .addHumanTask("task2", "john")
            .addTransition("transition", "task1", "task2")
            .done();

    BusinessArchive businessArchive = BusinessArchiveFactory.getBusinessArchive(attachmentProcess);
    attachmentProcess = managementAPI.deploy(businessArchive);

    ProcessInstanceUUID instanceUUID = runtimeAPI.instantiateProcess(attachmentProcess.getUUID());

    try {
      IFormWorkflowAPI api = FormAPIFactory.getFormWorkflowAPI();
      ActivityInstanceUUID activityInstanceUUID = null;
      Collection<TaskInstance> tasks =
          queryRuntimeAPI.getTaskList(instanceUUID, ActivityState.READY);
      for (TaskInstance activityInstance : tasks) {
        activityInstanceUUID = activityInstance.getUUID();
      }
      Assert.assertNotNull(activityInstanceUUID);
      String fileName = api.getAttachmentFileName(activityInstanceUUID, "${attachment}", true);
      Assert.assertEquals(attachmentFile.getName(), fileName);

      runtimeAPI.executeTask(activityInstanceUUID, true);
      fileName = api.getAttachmentFileName(activityInstanceUUID, "${attachment}", true);
      Assert.assertEquals(attachmentFile.getName(), fileName);

      File attachmentFile2 = File.createTempFile("new-attachment-test", ".txt");
      tasks = queryRuntimeAPI.getTaskList(instanceUUID, ActivityState.READY);
      for (TaskInstance activityInstance : tasks) {
        activityInstanceUUID = activityInstance.getUUID();
      }
      Assert.assertNotNull(activityInstanceUUID);
      runtimeAPI.addAttachment(
          instanceUUID, "attachment", attachmentFile2.getName(), "test".getBytes("UTF-8"));
      fileName = api.getAttachmentFileName(activityInstanceUUID, "${attachment}", true);
      Assert.assertEquals(attachmentFile2.getName(), fileName);
    } finally {
      AccessorUtil.getCommandAPI()
          .execute(new WebDeleteDocumentsOfProcessCommand(attachmentProcess.getUUID(), true));
      AccessorUtil.getRuntimeAPI().deleteProcessInstance(instanceUUID);
      AccessorUtil.getCommandAPI()
          .execute(new WebDeleteProcessCommand(attachmentProcess.getUUID()));
    }
  }