Search in sources :

Example 6 with ProcessDiagramGenerator

use of org.activiti.image.ProcessDiagramGenerator in project Activiti by Activiti.

the class ProcessDiagramGeneratorTest method testTransactionElements.

@Deployment
public void testTransactionElements() throws Exception {
    ProcessDiagramGenerator imageGenerator = new DefaultProcessDiagramGenerator();
    String activityFontName = imageGenerator.getDefaultActivityFontName();
    String labelFontName = imageGenerator.getDefaultLabelFontName();
    String annotationFontName = imageGenerator.getDefaultAnnotationFontName();
    String id = repositoryService.createProcessDefinitionQuery().processDefinitionKey("transactionSubRequest").singleResult().getId();
    List<String> activityIds = new ArrayList<>();
    List<String> highLightedFlows = new ArrayList<>();
    InputStream diagram = imageGenerator.generateDiagram(repositoryService.getBpmnModel(id), activityIds, highLightedFlows);
    assertThat(diagram).isNotNull();
    diagram = imageGenerator.generateDiagram(repositoryService.getBpmnModel(id), activityIds, highLightedFlows, activityFontName, labelFontName, annotationFontName);
    assertThat(diagram).isNotNull();
}
Also used : DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) ProcessDiagramGenerator(org.activiti.image.ProcessDiagramGenerator) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) Deployment(org.activiti.engine.test.Deployment)

Example 7 with ProcessDiagramGenerator

use of org.activiti.image.ProcessDiagramGenerator in project Activiti by Activiti.

the class ProcessInstanceDetailPanel method addProcessImage.

protected void addProcessImage() {
    ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processDefinition.getId());
    // Only show when graphical notation is defined
    if (processDefinitionEntity != null) {
        boolean didDrawImage = false;
        if (ExplorerApp.get().isUseJavascriptDiagram()) {
            try {
                final InputStream definitionStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
                XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory();
                XMLStreamReader xtr = xif.createXMLStreamReader(definitionStream);
                BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
                if (!bpmnModel.getFlowLocationMap().isEmpty()) {
                    int maxX = 0;
                    int maxY = 0;
                    for (String key : bpmnModel.getLocationMap().keySet()) {
                        GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(key);
                        double elementX = graphicInfo.getX() + graphicInfo.getWidth();
                        if (maxX < elementX) {
                            maxX = (int) elementX;
                        }
                        double elementY = graphicInfo.getY() + graphicInfo.getHeight();
                        if (maxY < elementY) {
                            maxY = (int) elementY;
                        }
                    }
                    // using panel for scrollbars
                    Panel imagePanel = new Panel();
                    imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
                    imagePanel.setWidth(100, UNITS_PERCENTAGE);
                    imagePanel.setHeight(100, UNITS_PERCENTAGE);
                    URL explorerURL = ExplorerApp.get().getURL();
                    URL url = new URL(explorerURL.getProtocol(), explorerURL.getHost(), explorerURL.getPort(), explorerURL.getPath().replace("/ui", "") + "diagram-viewer/index.html?processDefinitionId=" + processDefinition.getId() + "&processInstanceId=" + processInstance.getId());
                    Embedded browserPanel = new Embedded("", new ExternalResource(url));
                    browserPanel.setType(Embedded.TYPE_BROWSER);
                    browserPanel.setWidth(maxX + 350 + "px");
                    browserPanel.setHeight(maxY + 220 + "px");
                    HorizontalLayout panelLayoutT = new HorizontalLayout();
                    panelLayoutT.setSizeUndefined();
                    imagePanel.setContent(panelLayoutT);
                    imagePanel.addComponent(browserPanel);
                    panelLayout.addComponent(imagePanel);
                    didDrawImage = true;
                }
            } catch (Exception e) {
                LOGGER.error("Error loading process diagram component", e);
            }
        }
        if (!didDrawImage && processDefinitionEntity.isGraphicalNotationDefined()) {
            ProcessEngineConfiguration processEngineConfiguration = ProcessEngines.getDefaultProcessEngine().getProcessEngineConfiguration();
            ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
            StreamResource diagram = new ProcessDefinitionImageStreamResourceBuilder().buildStreamResource(processInstance, repositoryService, runtimeService, diagramGenerator, processEngineConfiguration);
            if (diagram != null) {
                Label header = new Label(i18nManager.getMessage(Messages.PROCESS_HEADER_DIAGRAM));
                header.addStyleName(ExplorerLayout.STYLE_H3);
                header.addStyleName(ExplorerLayout.STYLE_DETAIL_BLOCK);
                header.addStyleName(ExplorerLayout.STYLE_NO_LINE);
                panelLayout.addComponent(header);
                Embedded embedded = new Embedded(null, diagram);
                embedded.setType(Embedded.TYPE_IMAGE);
                embedded.setSizeUndefined();
                // using panel for scrollbars
                Panel imagePanel = new Panel();
                imagePanel.setScrollable(true);
                imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
                imagePanel.setWidth(100, UNITS_PERCENTAGE);
                imagePanel.setHeight(100, UNITS_PERCENTAGE);
                HorizontalLayout panelLayoutT = new HorizontalLayout();
                panelLayoutT.setSizeUndefined();
                imagePanel.setContent(panelLayoutT);
                imagePanel.addComponent(embedded);
                panelLayout.addComponent(imagePanel);
            }
        }
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStream(java.io.InputStream) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) Label(com.vaadin.ui.Label) PrettyTimeLabel(org.activiti.explorer.ui.custom.PrettyTimeLabel) ExternalResource(com.vaadin.terminal.ExternalResource) URL(java.net.URL) BpmnModel(org.activiti.bpmn.model.BpmnModel) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter) HorizontalLayout(com.vaadin.ui.HorizontalLayout) Panel(com.vaadin.ui.Panel) DetailPanel(org.activiti.explorer.ui.custom.DetailPanel) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) StreamResource(com.vaadin.terminal.StreamResource) ProcessDiagramGenerator(org.activiti.image.ProcessDiagramGenerator) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) Embedded(com.vaadin.ui.Embedded) ProcessDefinitionImageStreamResourceBuilder(org.activiti.explorer.ui.process.ProcessDefinitionImageStreamResourceBuilder) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 8 with ProcessDiagramGenerator

use of org.activiti.image.ProcessDiagramGenerator in project Activiti by Activiti.

the class SimpleTableEditor method save.

protected void save() {
    WorkflowDefinition workflowDefinition = createWorkflow();
    final ProcessEngineImpl defaultProcessEngine = (ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine();
    RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();
    ProcessEngineConfiguration processEngineConfiguration = defaultProcessEngine.getProcessEngineConfiguration();
    ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
    Model model = null;
    if (modelId == null) {
        // new process
        model = repositoryService.newModel();
    } else {
        // update existing process
        model = repositoryService.getModel(modelId);
    }
    model.setName(workflowDefinition.getName());
    model.setCategory(SimpleTableEditorConstants.TABLE_EDITOR_CATEGORY);
    repositoryService.saveModel(model);
    // Store model entity
    WorkflowDefinitionConversion conversion = ExplorerApp.get().getWorkflowDefinitionConversionFactory().createWorkflowDefinitionConversion(workflowDefinition);
    conversion.convert();
    try {
        // Write JSON to byte-array and set as editor-source
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ExplorerApp.get().getSimpleWorkflowJsonConverter().writeWorkflowDefinition(workflowDefinition, new OutputStreamWriter(baos));
        repositoryService.addModelEditorSource(model.getId(), baos.toByteArray());
        // Store process image
        // TODO: we should really allow the service to take an inputstream as input. Now we load it into memory ...
        repositoryService.addModelEditorSourceExtra(model.getId(), IOUtils.toByteArray(diagramGenerator.generateDiagram(conversion.getBpmnModel(), "png", processEngineConfiguration.getActivityFontName(), processEngineConfiguration.getLabelFontName(), processEngineConfiguration.getAnnotationFontName(), processEngineConfiguration.getClassLoader())));
    } catch (IOException e) {
        logger.warn("Could not generate process image. Image is not stored and will not be shown.", e);
    }
    ExplorerApp.get().getViewManager().showEditorProcessDefinitionPage(model.getId());
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) ProcessDiagramGenerator(org.activiti.image.ProcessDiagramGenerator) Model(org.activiti.engine.repository.Model) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ProcessEngineImpl(org.activiti.engine.impl.ProcessEngineImpl) RepositoryService(org.activiti.engine.RepositoryService)

Example 9 with ProcessDiagramGenerator

use of org.activiti.image.ProcessDiagramGenerator in project Activiti by Activiti.

the class ProcessInstanceDiagramResource method getProcessInstanceDiagram.

@RequestMapping(value = "/runtime/process-instances/{processInstanceId}/diagram", method = RequestMethod.GET)
public ResponseEntity<byte[]> getProcessInstanceDiagram(@PathVariable String processInstanceId, HttpServletResponse response) {
    ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);
    ProcessDefinition pde = repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId());
    if (pde != null && pde.hasGraphicalNotation()) {
        BpmnModel bpmnModel = repositoryService.getBpmnModel(pde.getId());
        ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
        InputStream resource = diagramGenerator.generateDiagram(bpmnModel, "png", runtimeService.getActiveActivityIds(processInstance.getId()), Collections.<String>emptyList(), processEngineConfiguration.getActivityFontName(), processEngineConfiguration.getLabelFontName(), processEngineConfiguration.getAnnotationFontName(), processEngineConfiguration.getClassLoader(), 1.0);
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.set("Content-Type", "image/png");
        try {
            return new ResponseEntity<byte[]>(IOUtils.toByteArray(resource), responseHeaders, HttpStatus.OK);
        } catch (Exception e) {
            throw new ActivitiIllegalArgumentException("Error exporting diagram", e);
        }
    } else {
        throw new ActivitiIllegalArgumentException("Process instance with id '" + processInstance.getId() + "' has no graphical notation defined.");
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) ProcessDiagramGenerator(org.activiti.image.ProcessDiagramGenerator) InputStream(java.io.InputStream) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) BpmnModel(org.activiti.bpmn.model.BpmnModel) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with ProcessDiagramGenerator

use of org.activiti.image.ProcessDiagramGenerator in project bamboobsc by billchen198318.

the class BusinessProcessManagementUtils method getDiagramByte.

private static byte[] getDiagramByte(ProcessInstance pi) throws Exception {
    byte[] data = null;
    ProcessDiagramGenerator processDiagramGenerator = new DefaultProcessDiagramGenerator();
    BpmnModel model = repositoryService.getBpmnModel(pi.getProcessDefinitionId());
    InputStream is = processDiagramGenerator.generateDiagram(model, "png", runtimeService.getActiveActivityIds(pi.getId()));
    data = IOUtils.toByteArray(is);
    is.close();
    is = null;
    return data;
}
Also used : DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) ProcessDiagramGenerator(org.activiti.image.ProcessDiagramGenerator) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Aggregations

ProcessDiagramGenerator (org.activiti.image.ProcessDiagramGenerator)15 InputStream (java.io.InputStream)10 DefaultProcessDiagramGenerator (org.activiti.image.impl.DefaultProcessDiagramGenerator)10 BpmnModel (org.activiti.bpmn.model.BpmnModel)9 Deployment (org.activiti.engine.test.Deployment)5 ProcessEngineConfiguration (org.activiti.engine.ProcessEngineConfiguration)4 StreamResource (com.vaadin.terminal.StreamResource)3 Embedded (com.vaadin.ui.Embedded)3 ArrayList (java.util.ArrayList)3 ProcessEngineImpl (org.activiti.engine.impl.ProcessEngineImpl)3 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)3 HorizontalLayout (com.vaadin.ui.HorizontalLayout)2 Label (com.vaadin.ui.Label)2 Panel (com.vaadin.ui.Panel)2 IOException (java.io.IOException)2 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)2 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)2 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)2 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)2 DetailPanel (org.activiti.explorer.ui.custom.DetailPanel)2