Java Code Examples for org.camunda.bpm.engine.impl.util.IoUtil#readInputStream()

The following examples show how to use org.camunda.bpm.engine.impl.util.IoUtil#readInputStream() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskServiceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetTaskAttachmentContentByTaskIdAndAttachmentId() {
  int historyLevel = processEngineConfiguration.getHistoryLevel().getId();
  if (historyLevel> ProcessEngineConfigurationImpl.HISTORYLEVEL_NONE) {
    // create and save task
    Task task = taskService.newTask();
    taskService.saveTask(task);
    String taskId = task.getId();

    // Fetch the task again and update
    // add attachment
    Attachment attachment = taskService.createAttachment("web page", taskId, "someprocessinstanceid", "weatherforcast", "temperatures and more", new ByteArrayInputStream("someContent".getBytes()));
    String attachmentId = attachment.getId();

    // get attachment for taskId and attachmentId
    InputStream taskAttachmentContent = taskService.getTaskAttachmentContent(taskId, attachmentId);
    assertNotNull(taskAttachmentContent);

    byte[] byteContent = IoUtil.readInputStream(taskAttachmentContent, "weatherforcast");
    assertEquals("someContent", new String(byteContent));

    taskService.deleteTask(taskId, true);
  }
}
 
Example 2
Source File: CaseDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testCaseDiagramRetrieval() throws FileNotFoundException, URISyntaxException {
  // setup additional mock behavior
  File file = getFile("/processes/todo-process.png");
  when(repositoryServiceMock.getCaseDiagram(MockProvider.EXAMPLE_CASE_DEFINITION_ID))
      .thenReturn(new FileInputStream(file));

  // call method
  byte[] actual = given().pathParam("id", MockProvider.EXAMPLE_CASE_DEFINITION_ID)
      .expect()
        .statusCode(Status.OK.getStatusCode())
        .contentType("image/png")
        .header("Content-Disposition", "attachment; filename=\"" +
            MockProvider.EXAMPLE_CASE_DEFINITION_DIAGRAM_RESOURCE_NAME + "\"")
      .when().get(DIAGRAM_DEFINITION_URL).getBody().asByteArray();

  // verify service interaction
  verify(repositoryServiceMock).getCaseDefinition(MockProvider.EXAMPLE_CASE_DEFINITION_ID);
  verify(repositoryServiceMock).getCaseDiagram(MockProvider.EXAMPLE_CASE_DEFINITION_ID);

  // compare input stream with response body bytes
  byte[] expected = IoUtil.readInputStream(new FileInputStream(file), "case diagram");
  Assert.assertArrayEquals(expected, actual);
}
 
Example 3
Source File: DecisionDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testDecisionDiagramNullFilename() throws FileNotFoundException, URISyntaxException {
  // setup additional mock behavior
  File file = getFile("/processes/todo-process.png");
  when(repositoryServiceMock.getDecisionDefinition(MockProvider.EXAMPLE_DECISION_DEFINITION_ID).getDiagramResourceName())
    .thenReturn(null);
  when(repositoryServiceMock.getDecisionDiagram(MockProvider.EXAMPLE_DECISION_DEFINITION_ID))
      .thenReturn(new FileInputStream(file));

  // call method
  byte[] actual = given().pathParam("id", MockProvider.EXAMPLE_DECISION_DEFINITION_ID)
    .expect()
    .statusCode(Status.OK.getStatusCode())
    .contentType("application/octet-stream")
    .header("Content-Disposition", "attachment; filename=\"" + null + "\"")
    .when().get(DIAGRAM_DEFINITION_URL).getBody().asByteArray();

  // verify service interaction
  verify(repositoryServiceMock).getDecisionDiagram(MockProvider.EXAMPLE_DECISION_DEFINITION_ID);

  // compare input stream with response body bytes
  byte[] expected = IoUtil.readInputStream(new FileInputStream(file), "decision diagram");
  Assert.assertArrayEquals(expected, actual);
}
 
Example 4
Source File: DecisionDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testDecisionDiagramRetrieval() throws FileNotFoundException, URISyntaxException {
  // setup additional mock behavior
  File file = getFile("/processes/todo-process.png");
  when(repositoryServiceMock.getDecisionDiagram(MockProvider.EXAMPLE_DECISION_DEFINITION_ID))
      .thenReturn(new FileInputStream(file));

  // call method
  byte[] actual = given().pathParam("id", MockProvider.EXAMPLE_DECISION_DEFINITION_ID)
      .expect()
        .statusCode(Status.OK.getStatusCode())
        .contentType("image/png")
        .header("Content-Disposition", "attachment; filename=\"" +
            MockProvider.EXAMPLE_DECISION_DEFINITION_DIAGRAM_RESOURCE_NAME + "\"")
      .when().get(DIAGRAM_DEFINITION_URL).getBody().asByteArray();

  // verify service interaction
  verify(repositoryServiceMock).getDecisionDefinition(MockProvider.EXAMPLE_DECISION_DEFINITION_ID);
  verify(repositoryServiceMock).getDecisionDiagram(MockProvider.EXAMPLE_DECISION_DEFINITION_ID);

  // compare input stream with response body bytes
  byte[] expected = IoUtil.readInputStream(new FileInputStream(file), "decision diagram");
  Assert.assertArrayEquals(expected, actual);
}
 
Example 5
Source File: DecisionRequirementsDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void decisionRequirementsDiagramRetrieval() throws FileNotFoundException, URISyntaxException {
  byte[] actual = given().pathParam("id", MockProvider.EXAMPLE_DECISION_REQUIREMENTS_DEFINITION_ID)
    .expect()
      .statusCode(Status.OK.getStatusCode())
      .contentType("image/png")
      .header("Content-Disposition", "attachment; filename=\"" +
          MockProvider.EXAMPLE_DECISION_DEFINITION_DIAGRAM_RESOURCE_NAME + "\"")
    .when().get(DIAGRAM_DEFINITION_URL).getBody().asByteArray();

  verify(repositoryServiceMock).getDecisionRequirementsDefinition(MockProvider.EXAMPLE_DECISION_REQUIREMENTS_DEFINITION_ID);
  verify(repositoryServiceMock).getDecisionRequirementsDiagram(MockProvider.EXAMPLE_DECISION_REQUIREMENTS_DEFINITION_ID);

  byte[] expected = IoUtil.readInputStream(new FileInputStream(getFile()), "decision requirements diagram");
  Assert.assertArrayEquals(expected, actual);
}
 
Example 6
Source File: ProcessDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessDiagramRetrieval() throws FileNotFoundException, URISyntaxException {
  // setup additional mock behavior
  File file = getFile("/processes/todo-process.png");
  when(repositoryServiceMock.getProcessDiagram(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID))
      .thenReturn(new FileInputStream(file));

  // call method
  byte[] actual = given().pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)
      .expect()
        .statusCode(Status.OK.getStatusCode())
        .contentType("image/png")
        .header("Content-Disposition", "attachment; filename=\"" +
            MockProvider.EXAMPLE_PROCESS_DEFINITION_DIAGRAM_RESOURCE_NAME + "\"")
      .when().get(DIAGRAM_DEFINITION_URL).getBody().asByteArray();

  // verify service interaction
  verify(repositoryServiceMock).getProcessDefinition(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID);
  verify(repositoryServiceMock).getProcessDiagram(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID);

  // compare input stream with response body bytes
  byte[] expected = IoUtil.readInputStream(new FileInputStream(file), "process diagram");
  Assert.assertArrayEquals(expected, actual);
}
 
Example 7
Source File: CmmnDeployerTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/camunda/bpm/engine/test/cmmn/deployment/CmmnDeploymentTest.testCaseDiagramResource.cmmn",
    "org/camunda/bpm/engine/test/cmmn/deployment/CmmnDeploymentTest.testCaseDiagramResource.png" })
public void testCaseDiagramResource() {
  final CaseDefinition caseDefinition = repositoryService.createCaseDefinitionQuery().singleResult();

  assertEquals("org/camunda/bpm/engine/test/cmmn/deployment/CmmnDeploymentTest.testCaseDiagramResource.cmmn", caseDefinition.getResourceName());
  assertEquals("Case_1", caseDefinition.getKey());

  final String diagramResourceName = caseDefinition.getDiagramResourceName();
  assertEquals("org/camunda/bpm/engine/test/cmmn/deployment/CmmnDeploymentTest.testCaseDiagramResource.png", diagramResourceName);

  final InputStream diagramStream = repositoryService.getResourceAsStream(deploymentId,
      "org/camunda/bpm/engine/test/cmmn/deployment/CmmnDeploymentTest.testCaseDiagramResource.png");
  final byte[] diagramBytes = IoUtil.readInputStream(diagramStream, "diagram stream");
  assertEquals(2540, diagramBytes.length);
}
 
Example 8
Source File: ProcessDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessDiagramNullFilename() throws FileNotFoundException, URISyntaxException {
  // setup additional mock behavior
  File file = getFile("/processes/todo-process.png");
  when(repositoryServiceMock.getProcessDefinition(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID).getDiagramResourceName())
    .thenReturn(null);
  when(repositoryServiceMock.getProcessDiagram(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID))
    .thenReturn(new FileInputStream(file));

  // call method
  byte[] actual = given().pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)
    .expect()
    .statusCode(Status.OK.getStatusCode())
    .contentType("application/octet-stream")
    .header("Content-Disposition", "attachment; filename=\"" + null + "\"")
    .when().get(DIAGRAM_DEFINITION_URL).getBody().asByteArray();

  // verify service interaction
  verify(repositoryServiceMock).getProcessDiagram(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID);

  // compare input stream with response body bytes
  byte[] expected = IoUtil.readInputStream(new FileInputStream(file), "process diagram");
  Assert.assertArrayEquals(expected, actual);
}
 
Example 9
Source File: RepositoryServiceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/camunda/bpm/engine/test/repository/drg.dmn" })
public void testGetDecisionRequirementsModel() throws Exception {
  DecisionRequirementsDefinitionQuery query = repositoryService.createDecisionRequirementsDefinitionQuery();

  DecisionRequirementsDefinition decisionRequirementsDefinition = query.singleResult();
  String decisionRequirementsDefinitionId = decisionRequirementsDefinition.getId();

  InputStream decisionRequirementsModel = repositoryService.getDecisionRequirementsModel(decisionRequirementsDefinitionId);

  assertNotNull(decisionRequirementsModel);

  byte[] readInputStream = IoUtil.readInputStream(decisionRequirementsModel, "decisionRequirementsModel");
  String model = new String(readInputStream, "UTF-8");

  assertTrue(model.contains("<definitions id=\"dish\" name=\"Dish\" namespace=\"test-drg\""));
  IoUtil.closeSilently(decisionRequirementsModel);
}
 
Example 10
Source File: CaseDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testCaseDiagramNullFilename() throws FileNotFoundException, URISyntaxException {
  // setup additional mock behavior
  File file = getFile("/processes/todo-process.png");
  when(repositoryServiceMock.getCaseDefinition(MockProvider.EXAMPLE_CASE_DEFINITION_ID).getDiagramResourceName())
    .thenReturn(null);
  when(repositoryServiceMock.getCaseDiagram(MockProvider.EXAMPLE_CASE_DEFINITION_ID))
      .thenReturn(new FileInputStream(file));

  // call method
  byte[] actual = given().pathParam("id", MockProvider.EXAMPLE_CASE_DEFINITION_ID)
    .expect()
    .statusCode(Status.OK.getStatusCode())
    .contentType("application/octet-stream")
    .header("Content-Disposition", "attachment; filename=\"" + null + "\"")
    .when().get(DIAGRAM_DEFINITION_URL).getBody().asByteArray();

  // verify service interaction
  verify(repositoryServiceMock).getCaseDiagram(MockProvider.EXAMPLE_CASE_DEFINITION_ID);

  // compare input stream with response body bytes
  byte[] expected = IoUtil.readInputStream(new FileInputStream(file), "case diagram");
  Assert.assertArrayEquals(expected, actual);
}
 
Example 11
Source File: TaskRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetSingleTaskAttachmentContent() {
  Response response = given()
    .pathParam("id", MockProvider.EXAMPLE_TASK_ID)
    .pathParam("attachmentId", MockProvider.EXAMPLE_TASK_ATTACHMENT_ID)
  .then().expect()
    .statusCode(Status.OK.getStatusCode())
  .when().get(SINGLE_TASK_SINGLE_ATTACHMENT_DATA_URL);

  byte[] responseContent = IoUtil.readInputStream(response.asInputStream(), "attachmentContent");
  assertEquals("someContent", new String(responseContent));
}
 
Example 12
Source File: JobPrioritizationFailureJavaSerializationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected static byte[] readByteArrayFromClasspath(String path) {
  try {
    InputStream inStream = JobPrioritizationFailureJavaSerializationTest.class.getClassLoader().getResourceAsStream(path);
    byte[] serializedValue = IoUtil.readInputStream(inStream, "");
    inStream.close();
    return serializedValue;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example 13
Source File: VfsProcessApplicationScanner.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private void addResource(VirtualFile virtualFile, VirtualFile processArchiveRoot, Map<String, byte[]> resources) {
  String resourceName = virtualFile.getPathNameRelativeTo(processArchiveRoot);
  try {
    InputStream inputStream = virtualFile.openStream();
    byte[] bytes = IoUtil.readInputStream(inputStream, resourceName);
    IoUtil.closeSilently(inputStream);
    resources.put(resourceName, bytes);
  }
  catch (IOException e) {
    LOG.cannotReadInputStreamForFile(resourceName, processArchiveRoot, e);
  }
}
 
Example 14
Source File: TestHelper.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static void assertDiagramIsDeployed(boolean deployed, Class<?> clazz, String expectedDiagramResource, String processDefinitionKey) throws IOException {
  ProcessEngine processEngine = ProgrammaticBeanLookup.lookup(ProcessEngine.class);
  Assert.assertNotNull(processEngine);
  RepositoryService repositoryService = processEngine.getRepositoryService();
  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
    .processDefinitionKey(processDefinitionKey)
    .singleResult();
  assertNotNull(processDefinition);

  InputStream actualStream = null;
  InputStream expectedStream = null;
  try {
    actualStream = repositoryService.getProcessDiagram(processDefinition.getId());

    if (deployed) {
      byte[] actualDiagram = IoUtil.readInputStream(actualStream, "actualStream");
      assertNotNull(actualDiagram);
      assertTrue(actualDiagram.length > 0);

      expectedStream = clazz.getResourceAsStream(expectedDiagramResource);
      byte[] expectedDiagram = IoUtil.readInputStream(expectedStream, "expectedSteam");
      assertNotNull(expectedDiagram);

      assertTrue(isEqual(expectedStream, actualStream));
    } else {
      assertNull(actualStream);
    }
  } finally {
    IoUtil.closeSilently(actualStream);
    IoUtil.closeSilently(expectedStream);
  }
}
 
Example 15
Source File: ByteArrayValueSerializer.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public BytesValue convertToTypedValue(UntypedValueImpl untypedValue) {
  Object value = untypedValue.getValue();
  if (value instanceof byte[]) {
    return Variables.byteArrayValue((byte[]) value, untypedValue.isTransient());
  } else {
    byte[] data = IoUtil.readInputStream((InputStream) value, null);
    return Variables.byteArrayValue(data, untypedValue.isTransient());
  }
}
 
Example 16
Source File: RepositoryServiceTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Deployment(resources = { "org/camunda/bpm/engine/test/repository/one.dmn" })
public void testGetDecisionModel() throws Exception {
  DecisionDefinitionQuery query = repositoryService.createDecisionDefinitionQuery();

  DecisionDefinition decisionDefinition = query.singleResult();
  String decisionDefinitionId = decisionDefinition.getId();

  InputStream decisionModel = repositoryService.getDecisionModel(decisionDefinitionId);

  assertNotNull(decisionModel);

  byte[] readInputStream = IoUtil.readInputStream(decisionModel, "decisionModel");
  String model = new String(readInputStream, "UTF-8");

  assertTrue(model.contains("<decision id=\"one\" name=\"One\">"));

  IoUtil.closeSilently(decisionModel);
}
 
Example 17
Source File: DeployProcessArchiveStep.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Override
public void performOperationStep(DeploymentOperation operationContext) {

  final PlatformServiceContainer serviceContainer = operationContext.getServiceContainer();
  final AbstractProcessApplication processApplication = operationContext.getAttachment(Attachments.PROCESS_APPLICATION);
  final ClassLoader processApplicationClassloader = processApplication.getProcessApplicationClassloader();

  ProcessEngine processEngine = getProcessEngine(serviceContainer, processApplication.getDefaultDeployToEngineName());

  // start building deployment map
  Map<String, byte[]> deploymentMap = new HashMap<String, byte[]>();

  // add all processes listed in the processes.xml
  List<String> listedProcessResources = processArchive.getProcessResourceNames();
  for (String processResource : listedProcessResources) {
    InputStream resourceAsStream = null;
    try {
      resourceAsStream = processApplicationClassloader.getResourceAsStream(processResource);
      byte[] bytes = IoUtil.readInputStream(resourceAsStream, processResource);
      deploymentMap.put(processResource, bytes);
    } finally {
      IoUtil.closeSilently(resourceAsStream);
    }
  }

  // scan for additional process definitions if not turned off
  if(PropertyHelper.getBooleanProperty(processArchive.getProperties(), ProcessArchiveXml.PROP_IS_SCAN_FOR_PROCESS_DEFINITIONS, true)) {
    String paResourceRoot = processArchive.getProperties().get(ProcessArchiveXml.PROP_RESOURCE_ROOT_PATH);
    String[] additionalResourceSuffixes = StringUtil.split(processArchive.getProperties().get(ProcessArchiveXml.PROP_ADDITIONAL_RESOURCE_SUFFIXES), ProcessArchiveXml.PROP_ADDITIONAL_RESOURCE_SUFFIXES_SEPARATOR);
    deploymentMap.putAll(findResources(processApplicationClassloader, paResourceRoot, additionalResourceSuffixes));
  }

  // perform process engine deployment
  RepositoryService repositoryService = processEngine.getRepositoryService();
  ProcessApplicationDeploymentBuilder deploymentBuilder = repositoryService.createDeployment(processApplication.getReference());

  // set the name for the deployment
  String deploymentName = processArchive.getName();
  if(deploymentName == null || deploymentName.isEmpty()) {
    deploymentName = processApplication.getName();
  }
  deploymentBuilder.name(deploymentName);

  // set the tenant id for the deployment
  String tenantId = processArchive.getTenantId();
  if(tenantId != null && !tenantId.isEmpty()) {
    deploymentBuilder.tenantId(tenantId);
  }

  // enable duplicate filtering
  deploymentBuilder.enableDuplicateFiltering(PropertyHelper.getBooleanProperty(processArchive.getProperties(), ProcessArchiveXml.PROP_IS_DEPLOY_CHANGED_ONLY, false));

  if (PropertyHelper.getBooleanProperty(processArchive.getProperties(), ProcessArchiveXml.PROP_IS_RESUME_PREVIOUS_VERSIONS, true)) {
    enableResumingOfPreviousVersions(deploymentBuilder);
  }

  // add all resources obtained through the processes.xml and through scanning
  for (Entry<String, byte[]> deploymentResource : deploymentMap.entrySet()) {
    deploymentBuilder.addInputStream(deploymentResource.getKey(), new ByteArrayInputStream(deploymentResource.getValue()));
  }

  // allow the process application to add additional resources to the deployment
  processApplication.createDeployment(processArchive.getName(), deploymentBuilder);

  Collection<String> deploymentResourceNames = deploymentBuilder.getResourceNames();
  if(!deploymentResourceNames.isEmpty()) {

    LOG.deploymentSummary(deploymentResourceNames, deploymentName);

    // perform the process engine deployment
    deployment = deploymentBuilder.deploy();

    // add attachment
    Map<String, DeployedProcessArchive> processArchiveDeploymentMap = operationContext.getAttachment(Attachments.PROCESS_ARCHIVE_DEPLOYMENT_MAP);
    if(processArchiveDeploymentMap == null) {
      processArchiveDeploymentMap = new HashMap<String, DeployedProcessArchive>();
      operationContext.addAttachment(Attachments.PROCESS_ARCHIVE_DEPLOYMENT_MAP, processArchiveDeploymentMap);
    }
    processArchiveDeploymentMap.put(processArchive.getName(), new DeployedProcessArchive(deployment));

  }
  else {
    LOG.notCreatingPaDeployment(processApplication.getName());
  }
}
 
Example 18
Source File: MultipartFormData.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected byte[] readBinaryContent(FileItemStream stream) {
  InputStream inputStream = getInputStream(stream);
  return IoUtil.readInputStream(inputStream, stream.getFieldName());
}
 
Example 19
Source File: CreateAttachmentCmd.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Override
public Attachment execute(CommandContext commandContext) {
  if (taskId != null) {
    task = commandContext
        .getTaskManager()
        .findTaskById(taskId);
  } else {
    ensureNotNull("taskId or processInstanceId has to be provided", this.processInstanceId);
    List<ExecutionEntity> executionsByProcessInstanceId = commandContext.getExecutionManager().findExecutionsByProcessInstanceId(processInstanceId);
    processInstance = executionsByProcessInstanceId.get(0);
  }

  AttachmentEntity attachment = new AttachmentEntity();
  attachment.setName(attachmentName);
  attachment.setDescription(attachmentDescription);
  attachment.setType(attachmentType);
  attachment.setTaskId(taskId);
  attachment.setProcessInstanceId(processInstanceId);
  attachment.setUrl(url);
  attachment.setCreateTime(ClockUtil.getCurrentTime());

  if (task != null) {
    ExecutionEntity execution = task.getExecution();
    if (execution != null) {
      attachment.setRootProcessInstanceId(execution.getRootProcessInstanceId());
    }
  } else if (processInstance != null) {
    attachment.setRootProcessInstanceId(processInstance.getRootProcessInstanceId());
  }

  if (isHistoryRemovalTimeStrategyStart()) {
    provideRemovalTime(attachment);
  }

  DbEntityManager dbEntityManger = commandContext.getDbEntityManager();
  dbEntityManger.insert(attachment);

  if (content != null) {
    byte[] bytes = IoUtil.readInputStream(content, attachmentName);
    ByteArrayEntity byteArray = new ByteArrayEntity(bytes, ResourceTypes.HISTORY);

    byteArray.setRootProcessInstanceId(attachment.getRootProcessInstanceId());
    byteArray.setRemovalTime(attachment.getRemovalTime());

    commandContext.getByteArrayManager().insertByteArray(byteArray);
    attachment.setContentId(byteArray.getId());
  }

  PropertyChange propertyChange = new PropertyChange("name", null, attachmentName);

  if (task != null) {
    commandContext.getOperationLogManager()
        .logAttachmentOperation(UserOperationLogEntry.OPERATION_TYPE_ADD_ATTACHMENT, task, propertyChange);
    task.triggerUpdateEvent();
  } else if (processInstance != null) {
    commandContext.getOperationLogManager()
        .logAttachmentOperation(UserOperationLogEntry.OPERATION_TYPE_ADD_ATTACHMENT, processInstance, propertyChange);
  }

  return attachment;
}
 
Example 20
Source File: DeploymentBuilderImpl.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public DeploymentBuilder addInputStream(String resourceName, InputStream inputStream) {
  ensureNotNull("inputStream for resource '" + resourceName + "' is null", "inputStream", inputStream);
  byte[] bytes = IoUtil.readInputStream(inputStream, resourceName);

  return addBytes(resourceName, bytes);
}