org.camunda.bpm.engine.RepositoryService.getProcessDiagram()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(12.3k)|赞(0)|评价(0)|浏览(262)

本文整理了Java中org.camunda.bpm.engine.RepositoryService.getProcessDiagram方法的一些代码示例,展示了RepositoryService.getProcessDiagram的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RepositoryService.getProcessDiagram方法的具体详情如下:
包路径:org.camunda.bpm.engine.RepositoryService
类名称:RepositoryService
方法名:getProcessDiagram

RepositoryService.getProcessDiagram介绍

[英]Gives access to a deployed process diagram, e.g., a PNG image, through a stream of bytes.
[中]通过字节流访问已部署的流程图,例如PNG图像。

代码示例

代码示例来源:origin: camunda/camunda-bpm-platform

@Override
public Response getProcessDefinitionDiagram() {
 ProcessDefinition definition = engine.getRepositoryService().getProcessDefinition(processDefinitionId);
 InputStream processDiagram = engine.getRepositoryService().getProcessDiagram(processDefinitionId);
 if (processDiagram == null) {
  return Response.noContent().build();
 } else {
  String fileName = definition.getDiagramResourceName();
  return Response.ok(processDiagram)
    .header("Content-Disposition", "attachment; filename=" + fileName)
    .type(getMediaTypeForFileSuffix(fileName)).build();
 }
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Override
public Response getProcessDefinitionDiagram() {
 ProcessDefinition definition = engine.getRepositoryService().getProcessDefinition(processDefinitionId);
 InputStream processDiagram = engine.getRepositoryService().getProcessDiagram(processDefinitionId);
 if (processDiagram == null) {
  return Response.noContent().build();
 } else {
  String fileName = definition.getDiagramResourceName();
  return Response.ok(processDiagram)
    .header("Content-Disposition", "attachment; filename=" + fileName)
    .type(getMediaTypeForFileSuffix(fileName)).build();
 }
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void getProcessDiagramWithAuthenticatedTenant() {
 identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE));
 InputStream inputStream = repositoryService.getProcessDiagram(processDefinitionId);
 assertThat(inputStream, notNullValue());
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void testProcessDiagramNotExist() {
 // setup additional mock behavior
 when(repositoryServiceMock.getProcessDiagram(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)).thenReturn(null);
 // call method
 given().pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)
   .expect().statusCode(Status.NO_CONTENT.getStatusCode())
   .when().get(DIAGRAM_DEFINITION_URL);
 // verify service interaction
 verify(repositoryServiceMock).getProcessDefinition(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID);
 verify(repositoryServiceMock).getProcessDiagram(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID);
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void getProcessDiagramDisabledTenantCheck() {
 processEngineConfiguration.setTenantCheckEnabled(false);
 identityService.setAuthentication("user", null, null);
 InputStream inputStream = repositoryService.getProcessDiagram(processDefinitionId);
 assertThat(inputStream, notNullValue());
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void failToGetProcessDiagramNoAuthenticatedTenants() {
 identityService.setAuthentication("user", null, null);
 // declare expected exception
 thrown.expect(ProcessEngineException.class);
 thrown.expectMessage("Cannot get the process definition");
 repositoryService.getProcessDiagram(processDefinitionId);
}

代码示例来源:origin: camunda/camunda-bpm-platform

public void testGetProcessDiagram() {
 // given
 String processDefinitionId = selectProcessDefinitionByKey(ONE_TASK_PROCESS_KEY).getId();
 createGrantAuthorization(PROCESS_DEFINITION, ONE_TASK_PROCESS_KEY, userId, READ);
 // when
 InputStream stream = repositoryService.getProcessDiagram(processDefinitionId);
 // then
 // no process diagram deployed
 assertNull(stream);
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void testGetProcessDiagramThrowsAuthorizationException() {
 String message = "expected exception";
 when(repositoryServiceMock.getProcessDiagram(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)).thenThrow(new AuthorizationException(message));
 given()
  .pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)
 .then().expect()
  .statusCode(Status.FORBIDDEN.getStatusCode()).contentType(ContentType.JSON)
  .body("type", equalTo(AuthorizationException.class.getSimpleName()))
  .body("message", equalTo(message))
 .when()
  .get(DIAGRAM_DEFINITION_URL);
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void testGetProcessDiagramThrowsAuthorizationException_ByKey() {
 String message = "expected exception";
 when(repositoryServiceMock.getProcessDiagram(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)).thenThrow(new AuthorizationException(message));
 given()
  .pathParam("key", MockProvider.EXAMPLE_PROCESS_DEFINITION_KEY)
 .then().expect()
  .statusCode(Status.FORBIDDEN.getStatusCode()).contentType(ContentType.JSON)
  .body("type", equalTo(AuthorizationException.class.getSimpleName()))
  .body("message", equalTo(message))
 .when()
  .get(DIAGRAM_DEFINITION_KEY_URL);
}

代码示例来源:origin: camunda/camunda-bpm-platform

@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);
}

代码示例来源:origin: camunda/camunda-bpm-platform

@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);
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
  * Tests {@link RepositoryService#getProcessDiagram(String)}.
  */
 @Test
 public void testGetProcessDiagram() throws Exception {
  if (1 == processDefinitionQuery.count()) {
   ProcessDefinition processDefinition = processDefinitionQuery.singleResult();
   InputStream expectedStream = new FileInputStream("src/test/resources/org/camunda/bpm/engine/test/api/repository/diagram/" + imageFileName);
   InputStream actualStream = repositoryService.getProcessDiagram(processDefinition.getId());
//      writeToFile(repositoryService.getProcessDiagram(processDefinition.getId()),
//              new File("src/test/resources/org/camunda/bpm/engine/test/api/repository/diagram/" + imageFileName + ".actual.png"));
   assertTrue(isEqual(expectedStream, actualStream));
  } else {
   // some test diagrams do not contain executable processes
   // and are therefore ignored by the engine
  }
 }

代码示例来源:origin: camunda/camunda-bpm-platform

public void testGetProcessDiagramWithoutAuthorizations() {
 // given
 String processDefinitionId = selectProcessDefinitionByKey(ONE_TASK_PROCESS_KEY).getId();
 try {
  // when
  repositoryService.getProcessDiagram(processDefinitionId);
  fail("Exception expected: It should not be possible to get the process diagram");
 } catch (AuthorizationException e) {
  // then
  String message = e.getMessage();
  assertTextPresent(userId, message);
  assertTextPresent(READ.getName(), message);
  assertTextPresent(ONE_TASK_PROCESS_KEY, message);
  assertTextPresent(PROCESS_DEFINITION.resourceName(), message);
 }
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void testGetProcessDiagramAfterCacheWasCleaned() {
 if (1 == processDefinitionQuery.count()) {
  activitiRule.getProcessEngineConfiguration().getDeploymentCache().discardProcessDefinitionCache();
  // given
  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
  // when
  InputStream stream = repositoryService.getProcessDiagram(processDefinition.getId());
  // then
  assertNotNull(processDefinition.getDiagramResourceName());
  assertNotNull(stream);
 } else {
  // some test diagrams do not contain executable processes
  // and are therefore ignored by the engine
 }
}

代码示例来源:origin: org.camunda.bpm/camunda-engine-rest-jaxrs2

@Override
public Response getProcessDefinitionDiagram() {
 ProcessDefinition definition = engine.getRepositoryService().getProcessDefinition(processDefinitionId);
 InputStream processDiagram = engine.getRepositoryService().getProcessDiagram(processDefinitionId);
 if (processDiagram == null) {
  return Response.noContent().build();
 } else {
  String fileName = definition.getDiagramResourceName();
  return Response.ok(processDiagram)
    .header("Content-Disposition", "attachment; filename=" + fileName)
    .type(getMediaTypeForFileSuffix(fileName)).build();
 }
}

代码示例来源:origin: camunda/camunda-bpm-platform

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);
 }
}

代码示例来源:origin: org.camunda.bpm/camunda-engine

@Test
public void getProcessDiagramWithAuthenticatedTenant() {
 identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE));
 InputStream inputStream = repositoryService.getProcessDiagram(processDefinitionId);
 assertThat(inputStream, notNullValue());
}

代码示例来源:origin: org.camunda.bpm/camunda-engine

@Test
public void getProcessDiagramDisabledTenantCheck() {
 processEngineConfiguration.setTenantCheckEnabled(false);
 identityService.setAuthentication("user", null, null);
 InputStream inputStream = repositoryService.getProcessDiagram(processDefinitionId);
 assertThat(inputStream, notNullValue());
}

代码示例来源:origin: org.camunda.bpm/camunda-engine

@Test
public void failToGetProcessDiagramNoAuthenticatedTenants() {
 identityService.setAuthentication("user", null, null);
 // declare expected exception
 thrown.expect(ProcessEngineException.class);
 thrown.expectMessage("Cannot get the process definition");
 repositoryService.getProcessDiagram(processDefinitionId);
}

代码示例来源:origin: org.camunda.bpm/camunda-engine

public void testGetProcessDiagram() {
 // given
 String processDefinitionId = selectProcessDefinitionByKey(ONE_TASK_PROCESS_KEY).getId();
 createGrantAuthorization(PROCESS_DEFINITION, ONE_TASK_PROCESS_KEY, userId, READ);
 // when
 InputStream stream = repositoryService.getProcessDiagram(processDefinitionId);
 // then
 // no process diagram deployed
 assertNull(stream);
}

相关文章

微信公众号

最新文章

更多

RepositoryService类方法