org.activiti.engine.impl.util.IoUtil Java Examples
The following examples show how to use
org.activiti.engine.impl.util.IoUtil.
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: SerializableType.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
public byte[] serialize(Object value, ValueFields valueFields) { if (value == null) { return null; } ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; try { oos = createObjectOutputStream(baos); oos.writeObject(value); } catch (Exception e) { throw new ActivitiException("Couldn't serialize value '"+value+"' in variable '"+valueFields.getName()+"'", e); } finally { IoUtil.closeSilently(oos); } return baos.toByteArray(); }
Example #2
Source File: SimpleFlowWorkController.java From activiti-demo with Apache License 2.0 | 6 votes |
/** * 查看流程定义图 * @param request * @param processDefId 流程定义id * @return */ @RequestMapping(value = "/viewprocessDefImage.do") public String viewprocessDefImage(HttpServletRequest request, HttpServletResponse response, @RequestParam("processDefId") String processDefId) throws Exception{ //根据流程定义id查询流程定义 ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefId).singleResult(); InputStream inputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getDiagramResourceName()); // // 输出资源内容到相应对象 // byte[] b = new byte[1024]; // int len; // while ((len = inputStream.read(b, 0, 1024)) != -1) { // response.getOutputStream().write(b, 0, len); // } response.getOutputStream().write(IoUtil.readInputStream(inputStream, "processDefInputStream")); return null; }
Example #3
Source File: SimpleFlowWorkController.java From activiti-demo with Apache License 2.0 | 6 votes |
/** * 查看流程定义 * @param request * @param processDefId 流程定义id * @return */ @RequestMapping(value = "/viewprocessDef.do") public String viewprocessDef(HttpServletRequest request, HttpServletResponse response, @RequestParam("processDefId") String processDefId) throws Exception{ //根据流程定义id查询流程定义 ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefId).singleResult(); InputStream inputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName()); // // 输出资源内容到相应对象 // byte[] b = new byte[1024]; // int len; // while ((len = inputStream.read(b, 0, 1024)) != -1) { // response.getOutputStream().write(b, 0, len); // } response.getOutputStream().write(IoUtil.readInputStream(inputStream, "processDefInputStream")); return null; }
Example #4
Source File: ProcessDiagramCanvas.java From maven-framework-project with MIT License | 6 votes |
/** * Generates an image of what currently is drawn on the canvas. * * Throws an {@link ActivitiException} when {@link #close()} is already * called. */ public InputStream generateImage(String imageType) { if (closed) { throw new ActivitiException("ProcessDiagramGenerator already closed"); } ByteArrayOutputStream out = new ByteArrayOutputStream(); try { // Try to remove white space minX = (minX <= 5) ? 5 : minX; minY = (minY <= 5) ? 5 : minY; BufferedImage imageToSerialize = processDiagram; if (minX >= 0 && minY >= 0) { imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5); } ImageIO.write(imageToSerialize, imageType, out); } catch (IOException e) { throw new ActivitiException("Error while generating process image", e); } finally { IoUtil.closeSilently(out); } return new ByteArrayInputStream(out.toByteArray()); }
Example #5
Source File: ProcessDiagramCanvas.java From maven-framework-project with MIT License | 6 votes |
/** * Generates an image of what currently is drawn on the canvas. * * Throws an {@link ActivitiException} when {@link #close()} is already * called. */ public InputStream generateImage(String imageType) { if (closed) { throw new ActivitiException("ProcessDiagramGenerator already closed"); } ByteArrayOutputStream out = new ByteArrayOutputStream(); try { // Try to remove white space minX = (minX <= 5) ? 5 : minX; minY = (minY <= 5) ? 5 : minY; BufferedImage imageToSerialize = processDiagram; if (minX >= 0 && minY >= 0) { imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5); } ImageIO.write(imageToSerialize, imageType, out); } catch (IOException e) { throw new ActivitiException("Error while generating process image", e); } finally { IoUtil.closeSilently(out); } return new ByteArrayInputStream(out.toByteArray()); }
Example #6
Source File: ProcessDiagramCanvas.java From activiti-in-action-codes with Apache License 2.0 | 6 votes |
/** * Generates an image of what currently is drawn on the canvas. * <p/> * Throws an {@link ActivitiException} when {@link #close()} is already * called. */ public InputStream generateImage(String imageType) { if (closed) { throw new ActivitiException("ProcessDiagramGenerator already closed"); } ByteArrayOutputStream out = new ByteArrayOutputStream(); try { // Try to remove white space minX = (minX <= 5) ? 5 : minX; minY = (minY <= 5) ? 5 : minY; BufferedImage imageToSerialize = processDiagram; if (minX >= 0 && minY >= 0) { imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5); } ImageIO.write(imageToSerialize, imageType, out); } catch (IOException e) { throw new ActivitiException("Error while generating process image", e); } finally { IoUtil.closeSilently(out); } return new ByteArrayInputStream(out.toByteArray()); }
Example #7
Source File: ProcessDiagramCanvas.java From activiti-in-action-codes with Apache License 2.0 | 6 votes |
/** * Generates an image of what currently is drawn on the canvas. * <p/> * Throws an {@link ActivitiException} when {@link #close()} is already * called. */ public InputStream generateImage(String imageType) { if (closed) { throw new ActivitiException("ProcessDiagramGenerator already closed"); } ByteArrayOutputStream out = new ByteArrayOutputStream(); try { // Try to remove white space minX = (minX <= 5) ? 5 : minX; minY = (minY <= 5) ? 5 : minY; BufferedImage imageToSerialize = processDiagram; if (minX >= 0 && minY >= 0) { imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5); } ImageIO.write(imageToSerialize, imageType, out); } catch (IOException e) { throw new ActivitiException("Error while generating process image", e); } finally { IoUtil.closeSilently(out); } return new ByteArrayInputStream(out.toByteArray()); }
Example #8
Source File: ProcessDiagramCanvas.java From activiti-in-action-codes with Apache License 2.0 | 6 votes |
/** * Generates an image of what currently is drawn on the canvas. * <p/> * Throws an {@link ActivitiException} when {@link #close()} is already * called. */ public InputStream generateImage(String imageType) { if (closed) { throw new ActivitiException("ProcessDiagramGenerator already closed"); } ByteArrayOutputStream out = new ByteArrayOutputStream(); try { // Try to remove white space minX = (minX <= 5) ? 5 : minX; minY = (minY <= 5) ? 5 : minY; BufferedImage imageToSerialize = processDiagram; if (minX >= 0 && minY >= 0) { imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5); } ImageIO.write(imageToSerialize, imageType, out); } catch (IOException e) { throw new ActivitiException("Error while generating process image", e); } finally { IoUtil.closeSilently(out); } return new ByteArrayInputStream(out.toByteArray()); }
Example #9
Source File: ProcessDiagramCanvas.java From activiti-in-action-codes with Apache License 2.0 | 6 votes |
/** * Generates an image of what currently is drawn on the canvas. * <p/> * Throws an {@link ActivitiException} when {@link #close()} is already * called. */ public InputStream generateImage(String imageType) { if (closed) { throw new ActivitiException("ProcessDiagramGenerator already closed"); } ByteArrayOutputStream out = new ByteArrayOutputStream(); try { // Try to remove white space minX = (minX <= 5) ? 5 : minX; minY = (minY <= 5) ? 5 : minY; BufferedImage imageToSerialize = processDiagram; if (minX >= 0 && minY >= 0) { imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5); } ImageIO.write(imageToSerialize, imageType, out); } catch (IOException e) { throw new ActivitiException("Error while generating process image", e); } finally { IoUtil.closeSilently(out); } return new ByteArrayInputStream(out.toByteArray()); }
Example #10
Source File: ProcessDiagramCanvas.java From activiti-in-action-codes with Apache License 2.0 | 6 votes |
/** * Generates an image of what currently is drawn on the canvas. * <p/> * Throws an {@link ActivitiException} when {@link #close()} is already * called. */ public InputStream generateImage(String imageType) { if (closed) { throw new ActivitiException("ProcessDiagramGenerator already closed"); } ByteArrayOutputStream out = new ByteArrayOutputStream(); try { // Try to remove white space minX = (minX <= 5) ? 5 : minX; minY = (minY <= 5) ? 5 : minY; BufferedImage imageToSerialize = processDiagram; if (minX >= 0 && minY >= 0) { imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5); } ImageIO.write(imageToSerialize, imageType, out); } catch (IOException e) { throw new ActivitiException("Error while generating process image", e); } finally { IoUtil.closeSilently(out); } return new ByteArrayInputStream(out.toByteArray()); }
Example #11
Source File: ProcessDiagramCanvas.java From activiti-in-action-codes with Apache License 2.0 | 6 votes |
/** * Generates an image of what currently is drawn on the canvas. * <p/> * Throws an {@link ActivitiException} when {@link #close()} is already * called. */ public InputStream generateImage(String imageType) { if (closed) { throw new ActivitiException("ProcessDiagramGenerator already closed"); } ByteArrayOutputStream out = new ByteArrayOutputStream(); try { // Try to remove white space minX = (minX <= 5) ? 5 : minX; minY = (minY <= 5) ? 5 : minY; BufferedImage imageToSerialize = processDiagram; if (minX >= 0 && minY >= 0) { imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5); } ImageIO.write(imageToSerialize, imageType, out); } catch (IOException e) { throw new ActivitiException("Error while generating process image", e); } finally { IoUtil.closeSilently(out); } return new ByteArrayInputStream(out.toByteArray()); }
Example #12
Source File: ProcessDiagramCanvas.java From activiti-in-action-codes with Apache License 2.0 | 6 votes |
/** * Generates an image of what currently is drawn on the canvas. * <p/> * Throws an {@link ActivitiException} when {@link #close()} is already * called. */ public InputStream generateImage(String imageType) { if (closed) { throw new ActivitiException("ProcessDiagramGenerator already closed"); } ByteArrayOutputStream out = new ByteArrayOutputStream(); try { // Try to remove white space minX = (minX <= 5) ? 5 : minX; minY = (minY <= 5) ? 5 : minY; BufferedImage imageToSerialize = processDiagram; if (minX >= 0 && minY >= 0) { imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5); } ImageIO.write(imageToSerialize, imageType, out); } catch (IOException e) { throw new ActivitiException("Error while generating process image", e); } finally { IoUtil.closeSilently(out); } return new ByteArrayInputStream(out.toByteArray()); }
Example #13
Source File: ProcessDiagramCanvas.java From activiti-in-action-codes with Apache License 2.0 | 6 votes |
/** * Generates an image of what currently is drawn on the canvas. * <p/> * Throws an {@link ActivitiException} when {@link #close()} is already * called. */ public InputStream generateImage(String imageType) { if (closed) { throw new ActivitiException("ProcessDiagramGenerator already closed"); } ByteArrayOutputStream out = new ByteArrayOutputStream(); try { // Try to remove white space minX = (minX <= 5) ? 5 : minX; minY = (minY <= 5) ? 5 : minY; BufferedImage imageToSerialize = processDiagram; if (minX >= 0 && minY >= 0) { imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5); } ImageIO.write(imageToSerialize, imageType, out); } catch (IOException e) { throw new ActivitiException("Error while generating process image", e); } finally { IoUtil.closeSilently(out); } return new ByteArrayInputStream(out.toByteArray()); }
Example #14
Source File: DeploymentBuilderImpl.java From flowable-engine with Apache License 2.0 | 6 votes |
@Override public DeploymentBuilder addZipInputStream(ZipInputStream zipInputStream) { try { ZipEntry entry = zipInputStream.getNextEntry(); while (entry != null) { if (!entry.isDirectory()) { String entryName = entry.getName(); byte[] bytes = IoUtil.readInputStream(zipInputStream, entryName); ResourceEntity resource = new ResourceEntity(); resource.setName(entryName); resource.setBytes(bytes); deployment.addResource(resource); } entry = zipInputStream.getNextEntry(); } } catch (Exception e) { throw new ActivitiException("problem reading zip input stream", e); } return this; }
Example #15
Source File: SerializableType.java From flowable-engine with Apache License 2.0 | 6 votes |
public byte[] serialize(Object value, ValueFields valueFields) { if (value == null) { return null; } ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; try { oos = createObjectOutputStream(baos); oos.writeObject(value); } catch (Exception e) { throw new ActivitiException("Couldn't serialize value '" + value + "' in variable '" + valueFields.getName() + "'", e); } finally { IoUtil.closeSilently(oos); } return baos.toByteArray(); }
Example #16
Source File: BpmnDeploymentTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Deployment(resources = { "org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.bpmn20.xml", "org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg" }) public void testProcessDiagramResource() { ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); assertEquals("org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.bpmn20.xml", processDefinition.getResourceName()); assertTrue(processDefinition.hasStartFormKey()); String diagramResourceName = processDefinition.getDiagramResourceName(); assertEquals("org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg", diagramResourceName); InputStream diagramStream = repositoryService.getResourceAsStream(deploymentIdFromDeploymentAnnotation, "org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg"); byte[] diagramBytes = IoUtil.readInputStream(diagramStream, "diagram stream"); assertEquals(33343, diagramBytes.length); }
Example #17
Source File: DeploymentBuilderImpl.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
public DeploymentBuilder addZipInputStream(ZipInputStream zipInputStream) { try { ZipEntry entry = zipInputStream.getNextEntry(); while (entry != null) { if (!entry.isDirectory()) { String entryName = entry.getName(); byte[] bytes = IoUtil.readInputStream(zipInputStream, entryName); ResourceEntity resource = resourceEntityManager.create(); resource.setName(entryName); resource.setBytes(bytes); deployment.addResource(resource); } entry = zipInputStream.getNextEntry(); } } catch (Exception e) { throw new ActivitiException("problem reading zip input stream", e); } return this; }
Example #18
Source File: DbSqlSession.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
public void executeSchemaResource(String operation, String component, String resourceName, boolean isOptional) { InputStream inputStream = null; try { inputStream = ReflectUtil.getResourceAsStream(resourceName); if (inputStream == null) { if (isOptional) { log.info("no schema resource {} for {}", resourceName, operation); } else { throw new ActivitiException("resource '" + resourceName + "' is not available"); } } else { executeSchemaResource(operation, component, resourceName, inputStream); } } finally { IoUtil.closeSilently(inputStream); } }
Example #19
Source File: DeploymentPersistenceTest.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
public void testDeploymentPersistence() { Deployment deployment = repositoryService.createDeployment().name("strings").addString("org/activiti/test/HelloWorld.string", "hello world").addString("org/activiti/test/TheAnswer.string", "42") .deploy(); List<Deployment> deployments = repositoryService.createDeploymentQuery().list(); assertEquals(1, deployments.size()); deployment = deployments.get(0); assertEquals("strings", deployment.getName()); assertNotNull(deployment.getDeploymentTime()); String deploymentId = deployment.getId(); List<String> resourceNames = repositoryService.getDeploymentResourceNames(deploymentId); Set<String> expectedResourceNames = new HashSet<String>(); expectedResourceNames.add("org/activiti/test/HelloWorld.string"); expectedResourceNames.add("org/activiti/test/TheAnswer.string"); assertEquals(expectedResourceNames, new HashSet<String>(resourceNames)); InputStream resourceStream = repositoryService.getResourceAsStream(deploymentId, "org/activiti/test/HelloWorld.string"); assertTrue(Arrays.equals("hello world".getBytes(), IoUtil.readInputStream(resourceStream, "test"))); resourceStream = repositoryService.getResourceAsStream(deploymentId, "org/activiti/test/TheAnswer.string"); assertTrue(Arrays.equals("42".getBytes(), IoUtil.readInputStream(resourceStream, "test"))); repositoryService.deleteDeployment(deploymentId); }
Example #20
Source File: BpmnDeploymentTest.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
@Deployment(resources = { "org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.bpmn20.xml", "org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg" }) public void testProcessDiagramResource() { ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); assertEquals("org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.bpmn20.xml", processDefinition.getResourceName()); BpmnModel processModel = repositoryService.getBpmnModel(processDefinition.getId()); List<StartEvent> startEvents = processModel.getMainProcess().findFlowElementsOfType(StartEvent.class); assertEquals(1, startEvents.size()); assertEquals("someFormKey", startEvents.get(0).getFormKey()); String diagramResourceName = processDefinition.getDiagramResourceName(); assertEquals("org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg", diagramResourceName); InputStream diagramStream = repositoryService.getResourceAsStream(deploymentIdFromDeploymentAnnotation, "org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg"); byte[] diagramBytes = IoUtil.readInputStream(diagramStream, "diagram stream"); assertEquals(33343, diagramBytes.length); }
Example #21
Source File: DeploymentPersistenceTest.java From flowable-engine with Apache License 2.0 | 5 votes |
public void testDeploymentPersistence() { Deployment deployment = repositoryService .createDeployment() .name("strings") .addString("org/activiti/test/HelloWorld.string", "hello world") .addString("org/activiti/test/TheAnswer.string", "42") .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE) .deploy(); List<Deployment> deployments = repositoryService.createDeploymentQuery().list(); assertEquals(1, deployments.size()); deployment = deployments.get(0); assertEquals("strings", deployment.getName()); assertNotNull(deployment.getDeploymentTime()); String deploymentId = deployment.getId(); List<String> resourceNames = repositoryService.getDeploymentResourceNames(deploymentId); Set<String> expectedResourceNames = new HashSet<String>(); expectedResourceNames.add("org/activiti/test/HelloWorld.string"); expectedResourceNames.add("org/activiti/test/TheAnswer.string"); assertEquals(expectedResourceNames, new HashSet<String>(resourceNames)); InputStream resourceStream = repositoryService.getResourceAsStream(deploymentId, "org/activiti/test/HelloWorld.string"); assertTrue(Arrays.equals("hello world".getBytes(), IoUtil.readInputStream(resourceStream, "test"))); resourceStream = repositoryService.getResourceAsStream(deploymentId, "org/activiti/test/TheAnswer.string"); assertTrue(Arrays.equals("42".getBytes(), IoUtil.readInputStream(resourceStream, "test"))); repositoryService.deleteDeployment(deploymentId); }
Example #22
Source File: SpringAutoDeployTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
private boolean waitUntilFileIsWritten(String filePath, int expectedBytes) throws URISyntaxException { while (IoUtil.getFile(filePath).length() != (long) expectedBytes) { try { wait(100L); } catch (InterruptedException e) { fail(e.getMessage()); } } return true; }
Example #23
Source File: SerializableType.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public Object deserialize(byte[] bytes, ValueFields valueFields) { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); try { ObjectInputStream ois = createObjectInputStream(bais); Object deserializedObject = ois.readObject(); return deserializedObject; } catch (Exception e) { throw new ActivitiException("Couldn't deserialize object in variable '"+valueFields.getName()+"'", e); } finally { IoUtil.closeSilently(bais); } }
Example #24
Source File: DeploymentBuilderImpl.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public DeploymentBuilder addInputStream(String resourceName, InputStream inputStream) { if (inputStream == null) { throw new ActivitiIllegalArgumentException("inputStream for resource '" + resourceName + "' is null"); } byte[] bytes = IoUtil.readInputStream(inputStream, resourceName); ResourceEntity resource = resourceEntityManager.create(); resource.setName(resourceName); resource.setBytes(bytes); deployment.addResource(resource); return this; }
Example #25
Source File: DemoDataGenerator.java From maven-framework-project with MIT License | 5 votes |
protected void createUser(String userId, String firstName, String lastName, String password, String email, String imageResource, List<String> groups, List<String> userInfo) { if (identityService.createUserQuery().userId(userId).count() == 0) { // Following data can already be set by demo setup script User user = identityService.newUser(userId); user.setFirstName(firstName); user.setLastName(lastName); user.setPassword(password); user.setEmail(email); identityService.saveUser(user); if (groups != null) { for (String group : groups) { identityService.createMembership(userId, group); } } } // Following data is not set by demo setup script // image if (imageResource != null) { byte[] pictureBytes = IoUtil.readInputStream(this.getClass().getClassLoader().getResourceAsStream(imageResource), null); Picture picture = new Picture(pictureBytes, "image/jpeg"); identityService.setUserPicture(userId, picture); } // user info if (userInfo != null) { for (int i = 0; i < userInfo.size(); i += 2) { identityService.setUserInfo(userId, userInfo.get(i), userInfo.get(i + 1)); } } }
Example #26
Source File: ProcessDefinitionDiagramHelper.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
/** * Generates a diagram resource for a ProcessDefinitionEntity and associated BpmnParse. The * returned resource has not yet been persisted, nor attached to the ProcessDefinitionEntity. * This requires that the ProcessDefinitionEntity have its key and resource name already set. * * The caller must determine whether creating a diagram for this process definition is appropriate or not, * for example see {@link #shouldCreateDiagram(ProcessDefinitionEntity, DeploymentEntity)}. */ public ResourceEntity createDiagramForProcessDefinition(ProcessDefinitionEntity processDefinition, BpmnParse bpmnParse) { if (StringUtils.isEmpty(processDefinition.getKey()) || StringUtils.isEmpty(processDefinition.getResourceName())) { throw new IllegalStateException("Provided process definition must have both key and resource name set."); } ResourceEntity resource = createResourceEntity(); ProcessEngineConfiguration processEngineConfiguration = Context.getCommandContext().getProcessEngineConfiguration(); try { byte[] diagramBytes = IoUtil.readInputStream( processEngineConfiguration.getProcessDiagramGenerator().generateDiagram(bpmnParse.getBpmnModel(), "png", processEngineConfiguration.getActivityFontName(), processEngineConfiguration.getLabelFontName(), processEngineConfiguration.getAnnotationFontName(), processEngineConfiguration.getClassLoader()), null); String diagramResourceName = ResourceNameUtil.getProcessDiagramResourceName( processDefinition.getResourceName(), processDefinition.getKey(), "png"); resource.setName(diagramResourceName); resource.setBytes(diagramBytes); resource.setDeploymentId(processDefinition.getDeploymentId()); // Mark the resource as 'generated' resource.setGenerated(true); } catch (Throwable t) { // if anything goes wrong, we don't store the image (the process will still be executable). log.warn("Error while generating process diagram, image will not be stored in repository", t); resource = null; } return resource; }
Example #27
Source File: ProcessEngines.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
private static ProcessEngine buildProcessEngine(URL resource) { InputStream inputStream = null; try { inputStream = resource.openStream(); ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(inputStream); return processEngineConfiguration.buildProcessEngine(); } catch (IOException e) { throw new ActivitiIllegalArgumentException("couldn't open resource stream: " + e.getMessage(), e); } finally { IoUtil.closeSilently(inputStream); } }
Example #28
Source File: StartTimerEventTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void testTimerShouldNotBeRemovedWhenUndeployingOldVersion() throws Exception { // Deploy test process String processXml = new String(IoUtil.readInputStream(getClass().getResourceAsStream("StartTimerEventTest.testTimerShouldNotBeRemovedWhenUndeployingOldVersion.bpmn20.xml"), "")); String firstDeploymentId = repositoryService.createDeployment().addInputStream("StartTimerEventTest.testVersionUpgradeShouldCancelJobs.bpmn20.xml", new ByteArrayInputStream(processXml.getBytes())).deploy().getId(); // After process start, there should be timer created TimerJobQuery jobQuery = managementService.createTimerJobQuery(); assertEquals(1, jobQuery.count()); //we deploy new process version, with some small change String processChanged = processXml.replaceAll("beforeChange","changed"); String secondDeploymentId = repositoryService.createDeployment().addInputStream("StartTimerEventTest.testVersionUpgradeShouldCancelJobs.bpmn20.xml", new ByteArrayInputStream(processChanged.getBytes())).deploy().getId(); assertEquals(1, jobQuery.count()); // Remove the first deployment repositoryService.deleteDeployment(firstDeploymentId, true); // The removal of an old version should not affect timer deletion // ACT-1533: this was a bug, and the timer was deleted! assertEquals(1, jobQuery.count()); // Cleanup cleanDB(); repositoryService.deleteDeployment(secondDeploymentId, true); }
Example #29
Source File: ProcessEngines.java From flowable-engine with Apache License 2.0 | 5 votes |
private static ProcessEngine buildProcessEngine(URL resource) { InputStream inputStream = null; try { inputStream = resource.openStream(); ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(inputStream); return processEngineConfiguration.buildProcessEngine(); } catch (IOException e) { throw new ActivitiIllegalArgumentException("couldn't open resource stream: " + e.getMessage(), e); } finally { IoUtil.closeSilently(inputStream); } }
Example #30
Source File: DemoDataConfiguration.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected void createUser(String userId, String firstName, String lastName, String password, String email, String imageResource, List<String> groups, List<String> userInfo) { if (identityService.createUserQuery().userId(userId).count() == 0) { // Following data can already be set by demo setup script User user = identityService.newUser(userId); user.setFirstName(firstName); user.setLastName(lastName); user.setPassword(password); user.setEmail(email); identityService.saveUser(user); if (groups != null) { for (String group : groups) { identityService.createMembership(userId, group); } } } // Following data is not set by demo setup script // image if (imageResource != null) { byte[] pictureBytes = IoUtil.readInputStream(this.getClass().getClassLoader().getResourceAsStream(imageResource), null); Picture picture = new Picture(pictureBytes, "image/jpeg"); identityService.setUserPicture(userId, picture); } // user info if (userInfo != null) { for (int i = 0; i < userInfo.size(); i += 2) { identityService.setUserInfo(userId, userInfo.get(i), userInfo.get(i + 1)); } } }