@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(); } }
@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(); } }
public ProcessDefinition build() { ProcessDefinition mockDefinition = mock(ProcessDefinition.class); when(mockDefinition.getId()).thenReturn(id); when(mockDefinition.getCategory()).thenReturn(category); when(mockDefinition.getName()).thenReturn(name); when(mockDefinition.getKey()).thenReturn(key); when(mockDefinition.getDescription()).thenReturn(description); when(mockDefinition.getVersion()).thenReturn(version); when(mockDefinition.getResourceName()).thenReturn(resource); when(mockDefinition.getDeploymentId()).thenReturn(deploymentId); when(mockDefinition.getDiagramResourceName()).thenReturn(diagram); when(mockDefinition.isSuspended()).thenReturn(suspended); when(mockDefinition.hasStartFormKey()).thenReturn(startFormKey); when(mockDefinition.getTenantId()).thenReturn(tenantId); when(mockDefinition.getVersionTag()).thenReturn(versionTag); when(mockDefinition.isStartableInTasklist()).thenReturn(isStartableInTasklist); return mockDefinition; } }
@Deployment(resources={ "org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testMultipleDiagramResourcesProvided.bpmn20.xml", "org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testMultipleDiagramResourcesProvided.a.jpg", "org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testMultipleDiagramResourcesProvided.b.jpg", "org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testMultipleDiagramResourcesProvided.c.jpg" }) public void testMultipleDiagramResourcesProvided() { ProcessDefinition processA = repositoryService.createProcessDefinitionQuery().processDefinitionKey("a").singleResult(); ProcessDefinition processB = repositoryService.createProcessDefinitionQuery().processDefinitionKey("b").singleResult(); ProcessDefinition processC = repositoryService.createProcessDefinitionQuery().processDefinitionKey("c").singleResult(); assertEquals("org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testMultipleDiagramResourcesProvided.a.jpg", processA.getDiagramResourceName()); assertEquals("org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testMultipleDiagramResourcesProvided.b.jpg", processB.getDiagramResourceName()); assertEquals("org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testMultipleDiagramResourcesProvided.c.jpg", processC.getDiagramResourceName()); }
@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); }
public static ProcessDefinitionDto fromProcessDefinition(ProcessDefinition definition) { ProcessDefinitionDto dto = new ProcessDefinitionDto(); dto.id = definition.getId(); dto.key = definition.getKey(); dto.category = definition.getCategory(); dto.description = definition.getDescription(); dto.name = definition.getName(); dto.version = definition.getVersion(); dto.resource = definition.getResourceName(); dto.deploymentId = definition.getDeploymentId(); dto.diagram = definition.getDiagramResourceName(); dto.suspended = definition.isSuspended(); dto.tenantId = definition.getTenantId(); dto.versionTag = definition.getVersionTag(); dto.historyTimeToLive = definition.getHistoryTimeToLive(); dto.isStartableInTasklist = definition.isStartableInTasklist(); return dto; }
public static ProcessDefinitionDto fromProcessDefinition(ProcessDefinition definition) { ProcessDefinitionDto dto = new ProcessDefinitionDto(); dto.id = definition.getId(); dto.key = definition.getKey(); dto.category = definition.getCategory(); dto.description = definition.getDescription(); dto.name = definition.getName(); dto.version = definition.getVersion(); dto.resource = definition.getResourceName(); dto.deploymentId = definition.getDeploymentId(); dto.diagram = definition.getDiagramResourceName(); dto.suspended = definition.isSuspended(); dto.tenantId = definition.getTenantId(); dto.versionTag = definition.getVersionTag(); dto.historyTimeToLive = definition.getHistoryTimeToLive(); dto.isStartableInTasklist = definition.isStartableInTasklist(); return dto; }
public static HalProcessDefinition fromProcessDefinition(ProcessDefinition processDefinition, ProcessEngine processEngine) { HalProcessDefinition halProcDef = new HalProcessDefinition(); halProcDef.id = processDefinition.getId(); halProcDef.key = processDefinition.getKey(); halProcDef.category = processDefinition.getCategory(); halProcDef.description = processDefinition.getDescription(); halProcDef.name = processDefinition.getName(); halProcDef.version = processDefinition.getVersion(); halProcDef.resource = processDefinition.getResourceName(); halProcDef.deploymentId = processDefinition.getDeploymentId(); halProcDef.diagram = processDefinition.getDiagramResourceName(); halProcDef.suspended = processDefinition.isSuspended(); halProcDef.contextPath = ApplicationContextPathUtil.getApplicationPathForDeployment(processEngine, processDefinition.getDeploymentId()); halProcDef.linker.createLink(REL_SELF, processDefinition.getId()); halProcDef.linker.createLink(REL_DEPLOYMENT, processDefinition.getDeploymentId()); halProcDef.linker.createLink(REL_DEPLOYMENT_RESOURCE, processDefinition.getDeploymentId(), processDefinition.getResourceName()); return halProcDef; }
public static HalProcessDefinition fromProcessDefinition(ProcessDefinition processDefinition, ProcessEngine processEngine) { HalProcessDefinition halProcDef = new HalProcessDefinition(); halProcDef.id = processDefinition.getId(); halProcDef.key = processDefinition.getKey(); halProcDef.category = processDefinition.getCategory(); halProcDef.description = processDefinition.getDescription(); halProcDef.name = processDefinition.getName(); halProcDef.version = processDefinition.getVersion(); halProcDef.resource = processDefinition.getResourceName(); halProcDef.deploymentId = processDefinition.getDeploymentId(); halProcDef.diagram = processDefinition.getDiagramResourceName(); halProcDef.suspended = processDefinition.isSuspended(); halProcDef.contextPath = ApplicationContextPathUtil.getApplicationPathForDeployment(processEngine, processDefinition.getDeploymentId()); halProcDef.linker.createLink(REL_SELF, processDefinition.getId()); halProcDef.linker.createLink(REL_DEPLOYMENT, processDefinition.getDeploymentId()); halProcDef.linker.createLink(REL_DEPLOYMENT_RESOURCE, processDefinition.getDeploymentId(), processDefinition.getResourceName()); return halProcDef; }
@Deployment public void testGetBpmnXmlFileThroughService() { String deploymentId = repositoryService.createDeploymentQuery().singleResult().getId(); List<String> deploymentResources = repositoryService.getDeploymentResourceNames(deploymentId); // verify bpmn file name assertEquals(1, deploymentResources.size()); String bpmnResourceName = "org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testGetBpmnXmlFileThroughService.bpmn20.xml"; assertEquals(bpmnResourceName, deploymentResources.get(0)); ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); assertEquals(bpmnResourceName, processDefinition.getResourceName()); assertNull(processDefinition.getDiagramResourceName()); assertFalse(processDefinition.hasStartFormKey()); ReadOnlyProcessDefinition readOnlyProcessDefinition = ((RepositoryServiceImpl)repositoryService).getDeployedProcessDefinition(processDefinition.getId()); assertNull(readOnlyProcessDefinition.getDiagramResourceName()); // verify content InputStream deploymentInputStream = repositoryService.getResourceAsStream(deploymentId, bpmnResourceName); String contentFromDeployment = readInputStreamToString(deploymentInputStream); assertTrue(contentFromDeployment.length() > 0); assertTrue(contentFromDeployment.contains("process id=\"emptyProcess\"")); InputStream fileInputStream = ReflectUtil.getResourceAsStream("org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testGetBpmnXmlFileThroughService.bpmn20.xml"); String contentFromFile = readInputStreamToString(fileInputStream); assertEquals(contentFromFile, contentFromDeployment); }
@Deployment(resources={ "org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.bpmn20.xml", "org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg" }) public void testProcessDiagramResource() { ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); assertEquals("org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.bpmn20.xml", processDefinition.getResourceName()); assertTrue(processDefinition.hasStartFormKey()); String diagramResourceName = processDefinition.getDiagramResourceName(); assertEquals("org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg", diagramResourceName); InputStream diagramStream = repositoryService.getResourceAsStream(deploymentId, "org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg"); byte[] diagramBytes = IoUtil.readInputStream(diagramStream, "diagram stream"); assertEquals(33343, diagramBytes.length); }
@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 } }
@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(); } }
@Deployment(resources={ "org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testMultipleDiagramResourcesProvided.bpmn20.xml", "org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testMultipleDiagramResourcesProvided.a.jpg", "org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testMultipleDiagramResourcesProvided.b.jpg", "org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testMultipleDiagramResourcesProvided.c.jpg" }) public void testMultipleDiagramResourcesProvided() { ProcessDefinition processA = repositoryService.createProcessDefinitionQuery().processDefinitionKey("a").singleResult(); ProcessDefinition processB = repositoryService.createProcessDefinitionQuery().processDefinitionKey("b").singleResult(); ProcessDefinition processC = repositoryService.createProcessDefinitionQuery().processDefinitionKey("c").singleResult(); assertEquals("org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testMultipleDiagramResourcesProvided.a.jpg", processA.getDiagramResourceName()); assertEquals("org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testMultipleDiagramResourcesProvided.b.jpg", processB.getDiagramResourceName()); assertEquals("org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testMultipleDiagramResourcesProvided.c.jpg", processC.getDiagramResourceName()); }
public static ProcessDefinitionDto fromProcessDefinition(ProcessDefinition definition) { ProcessDefinitionDto dto = new ProcessDefinitionDto(); dto.id = definition.getId(); dto.key = definition.getKey(); dto.category = definition.getCategory(); dto.description = definition.getDescription(); dto.name = definition.getName(); dto.version = definition.getVersion(); dto.resource = definition.getResourceName(); dto.deploymentId = definition.getDeploymentId(); dto.diagram = definition.getDiagramResourceName(); dto.suspended = definition.isSuspended(); dto.tenantId = definition.getTenantId(); dto.versionTag = definition.getVersionTag(); dto.historyTimeToLive = definition.getHistoryTimeToLive(); dto.isStartableInTasklist = definition.isStartableInTasklist(); return dto; }
public static HalProcessDefinition fromProcessDefinition(ProcessDefinition processDefinition, ProcessEngine processEngine) { HalProcessDefinition halProcDef = new HalProcessDefinition(); halProcDef.id = processDefinition.getId(); halProcDef.key = processDefinition.getKey(); halProcDef.category = processDefinition.getCategory(); halProcDef.description = processDefinition.getDescription(); halProcDef.name = processDefinition.getName(); halProcDef.version = processDefinition.getVersion(); halProcDef.resource = processDefinition.getResourceName(); halProcDef.deploymentId = processDefinition.getDeploymentId(); halProcDef.diagram = processDefinition.getDiagramResourceName(); halProcDef.suspended = processDefinition.isSuspended(); halProcDef.contextPath = ApplicationContextPathUtil.getApplicationPathForDeployment(processEngine, processDefinition.getDeploymentId()); halProcDef.linker.createLink(REL_SELF, processDefinition.getId()); halProcDef.linker.createLink(REL_DEPLOYMENT, processDefinition.getDeploymentId()); halProcDef.linker.createLink(REL_DEPLOYMENT_RESOURCE, processDefinition.getDeploymentId(), processDefinition.getResourceName()); return halProcDef; }
@Deployment(resources={ "org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.bpmn20.xml", "org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg" }) public void testProcessDiagramResource() { ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); assertEquals("org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.bpmn20.xml", processDefinition.getResourceName()); assertTrue(processDefinition.hasStartFormKey()); String diagramResourceName = processDefinition.getDiagramResourceName(); assertEquals("org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg", diagramResourceName); InputStream diagramStream = repositoryService.getResourceAsStream(deploymentId, "org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg"); byte[] diagramBytes = IoUtil.readInputStream(diagramStream, "diagram stream"); assertEquals(33343, diagramBytes.length); }
@Deployment public void testGetBpmnXmlFileThroughService() { String deploymentId = repositoryService.createDeploymentQuery().singleResult().getId(); List<String> deploymentResources = repositoryService.getDeploymentResourceNames(deploymentId); // verify bpmn file name assertEquals(1, deploymentResources.size()); String bpmnResourceName = "org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testGetBpmnXmlFileThroughService.bpmn20.xml"; assertEquals(bpmnResourceName, deploymentResources.get(0)); ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); assertEquals(bpmnResourceName, processDefinition.getResourceName()); assertNull(processDefinition.getDiagramResourceName()); assertFalse(processDefinition.hasStartFormKey()); ReadOnlyProcessDefinition readOnlyProcessDefinition = ((RepositoryServiceImpl)repositoryService).getDeployedProcessDefinition(processDefinition.getId()); assertNull(readOnlyProcessDefinition.getDiagramResourceName()); // verify content InputStream deploymentInputStream = repositoryService.getResourceAsStream(deploymentId, bpmnResourceName); String contentFromDeployment = readInputStreamToString(deploymentInputStream); assertTrue(contentFromDeployment.length() > 0); assertTrue(contentFromDeployment.contains("process id=\"emptyProcess\"")); InputStream fileInputStream = ReflectUtil.getResourceAsStream("org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testGetBpmnXmlFileThroughService.bpmn20.xml"); String contentFromFile = readInputStreamToString(fileInputStream); assertEquals(contentFromFile, contentFromDeployment); }
@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 } }