Search in sources :

Example 1 with ProcessDiagramGenerator

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

the class SimpleTableEditor method showDiagram.

protected void showDiagram() {
    StreamResource.StreamSource streamSource = new StreamSource() {

        private static final long serialVersionUID = 6993112534181068935L;

        public InputStream getStream() {
            WorkflowDefinitionConversion workflowDefinitionConversion = ExplorerApp.get().getWorkflowDefinitionConversionFactory().createWorkflowDefinitionConversion(createWorkflow());
            final ProcessEngineImpl defaultProcessEngine = (ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine();
            final ProcessEngineConfiguration processEngineConfiguration = defaultProcessEngine.getProcessEngineConfiguration();
            final ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
            return diagramGenerator.generateDiagram(workflowDefinitionConversion.getBpmnModel(), "png", processEngineConfiguration.getActivityFontName(), processEngineConfiguration.getLabelFontName(), processEngineConfiguration.getAnnotationFontName(), processEngineConfiguration.getClassLoader());
        }
    };
    // resource must have unique id (or cache-crap can happen)!
    StreamResource imageresource = new StreamResource(streamSource, UUID.randomUUID() + ".png", ExplorerApp.get());
    Embedded diagram = new Embedded("", imageresource);
    diagram.setType(Embedded.TYPE_IMAGE);
    diagram.setSizeUndefined();
    // using panel for scrollbars
    imagePanel = new Panel();
    imagePanel.setScrollable(true);
    imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
    imagePanel.setWidth(100, UNITS_PERCENTAGE);
    imagePanel.setHeight("100%");
    mainLayout.addComponent(imagePanel);
    HorizontalLayout panelLayout = new HorizontalLayout();
    panelLayout.setSizeUndefined();
    imagePanel.setContent(panelLayout);
    imagePanel.addComponent(diagram);
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) Panel(com.vaadin.ui.Panel) DetailPanel(org.activiti.explorer.ui.custom.DetailPanel) StreamSource(com.vaadin.terminal.StreamResource.StreamSource) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) StreamResource(com.vaadin.terminal.StreamResource) ProcessDiagramGenerator(org.activiti.image.ProcessDiagramGenerator) StreamSource(com.vaadin.terminal.StreamResource.StreamSource) Embedded(com.vaadin.ui.Embedded) ProcessEngineImpl(org.activiti.engine.impl.ProcessEngineImpl) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 2 with ProcessDiagramGenerator

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

the class AdminRunningInstancesPanel method addProcessImage.

protected void addProcessImage(ProcessDefinition processDefinition, HistoricProcessInstance processInstance) {
    if (currentEmbedded != null) {
        mainPanel.removeComponent(currentEmbedded);
    }
    ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processDefinition.getId());
    // Only show when graphical notation is defined
    if (processDefinitionEntity != null && processDefinitionEntity.isGraphicalNotationDefined()) {
        if (imageHeader == null) {
            imageHeader = new Label(i18nManager.getMessage(Messages.PROCESS_HEADER_DIAGRAM));
            imageHeader.addStyleName(ExplorerLayout.STYLE_H3);
            imageHeader.addStyleName(ExplorerLayout.STYLE_DETAIL_BLOCK);
            imageHeader.addStyleName(ExplorerLayout.STYLE_NO_LINE);
            addDetailComponent(imageHeader);
        }
        ProcessEngineConfiguration processEngineConfig = ((ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine()).getProcessEngineConfiguration();
        ProcessDiagramGenerator diagramGenerator = processEngineConfig.getProcessDiagramGenerator();
        StreamResource diagram = new ProcessDefinitionImageStreamResourceBuilder().buildStreamResource(processInstance.getId(), processInstance.getProcessDefinitionId(), repositoryService, runtimeService, diagramGenerator, processEngineConfig);
        currentEmbedded = new Embedded(null, diagram);
        currentEmbedded.setType(Embedded.TYPE_IMAGE);
        addDetailComponent(currentEmbedded);
    }
}
Also used : ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) StreamResource(com.vaadin.terminal.StreamResource) ProcessDiagramGenerator(org.activiti.image.ProcessDiagramGenerator) Label(com.vaadin.ui.Label) PrettyTimeLabel(org.activiti.explorer.ui.custom.PrettyTimeLabel) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) Embedded(com.vaadin.ui.Embedded) ProcessDefinitionImageStreamResourceBuilder(org.activiti.explorer.ui.process.ProcessDefinitionImageStreamResourceBuilder) ProcessEngineImpl(org.activiti.engine.impl.ProcessEngineImpl)

Example 3 with ProcessDiagramGenerator

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

the class ProcessEngineMvcEndpoint method processDefinitionDiagram.

/**
     * Look up the process definition by key. For example,
     * this is <A href="http://localhost:8080/activiti/processes/fulfillmentProcess">process-diagram for</A>
     * a process definition named {@code fulfillmentProcess}.
     */
@RequestMapping(value = "/processes/{processDefinitionKey:.*}", method = RequestMethod.GET, produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public ResponseEntity processDefinitionDiagram(@PathVariable String processDefinitionKey) {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey(processDefinitionKey).latestVersion().singleResult();
    if (processDefinition == null) {
        return ResponseEntity.status(NOT_FOUND).body(null);
    }
    ProcessDiagramGenerator processDiagramGenerator = new DefaultProcessDiagramGenerator();
    BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
    if (bpmnModel.getLocationMap().size() == 0) {
        BpmnAutoLayout autoLayout = new BpmnAutoLayout(bpmnModel);
        autoLayout.execute();
    }
    InputStream is = processDiagramGenerator.generateJpgDiagram(bpmnModel);
    return ResponseEntity.ok(new InputStreamResource(is));
}
Also used : DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) ProcessDiagramGenerator(org.activiti.image.ProcessDiagramGenerator) InputStream(java.io.InputStream) BpmnAutoLayout(org.activiti.bpmn.BpmnAutoLayout) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) BpmnModel(org.activiti.bpmn.model.BpmnModel) InputStreamResource(org.springframework.core.io.InputStreamResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with ProcessDiagramGenerator

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

the class ProcessDiagramGeneratorTest method testGenerateDefaultDiagram.

/**
 * Test that when the diagram is generated for a model without graphic info
 * then the default diagram image is returned
 * or the ActivitiInterchangeInfoNotFoundException is thrown
 * depending on the value of the generateDefaultDiagram parameter.
 */
@Deployment
public void testGenerateDefaultDiagram() throws Exception {
    // GIVEN
    String id = repositoryService.createProcessDefinitionQuery().processDefinitionKey("fixSystemFailure").singleResult().getId();
    BpmnModel bpmnModel = repositoryService.getBpmnModel(id);
    ProcessDiagramGenerator imageGenerator = new DefaultProcessDiagramGenerator();
    String activityFontName = imageGenerator.getDefaultActivityFontName();
    String labelFontName = imageGenerator.getDefaultLabelFontName();
    String annotationFontName = imageGenerator.getDefaultAnnotationFontName();
    // WHEN
    try (final InputStream resourceStream = imageGenerator.generateDiagram(bpmnModel, emptyList(), emptyList(), activityFontName, labelFontName, annotationFontName, true)) {
        // THEN
        assertThat(resourceStream).isNotNull();
        byte[] diagram = IOUtils.toByteArray(resourceStream);
        assertThat(diagram).isNotNull();
        try (InputStream imageStream = getClass().getResourceAsStream(imageGenerator.getDefaultDiagramImageFileName())) {
            assertThat(diagram).isEqualTo(IOUtils.toByteArray(imageStream));
        }
    }
    // THEN
    assertThatExceptionOfType(ActivitiInterchangeInfoNotFoundException.class).isThrownBy(// WHEN
    () -> imageGenerator.generateDiagram(bpmnModel, emptyList(), emptyList(), activityFontName, labelFontName, annotationFontName, false)).withMessage("No interchange information found.");
    // THEN
    assertThatExceptionOfType(ActivitiImageException.class).isThrownBy(// WHEN
    () -> imageGenerator.generateDiagram(bpmnModel, emptyList(), emptyList(), activityFontName, labelFontName, annotationFontName, true, "invalid-file-name")).withMessage("Error occurred while getting default diagram image from file: invalid-file-name");
}
Also used : DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) ProcessDiagramGenerator(org.activiti.image.ProcessDiagramGenerator) InputStream(java.io.InputStream) DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) BpmnModel(org.activiti.bpmn.model.BpmnModel) Deployment(org.activiti.engine.test.Deployment)

Example 5 with ProcessDiagramGenerator

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

the class ProcessDiagramGeneratorTest method testSmallBoxLabels.

@Deployment
public void testSmallBoxLabels() throws Exception {
    ProcessDiagramGenerator imageGenerator = new DefaultProcessDiagramGenerator();
    String activityFontName = imageGenerator.getDefaultActivityFontName();
    String labelFontName = imageGenerator.getDefaultLabelFontName();
    String annotationFontName = imageGenerator.getDefaultAnnotationFontName();
    String id = repositoryService.createProcessDefinitionQuery().processDefinitionKey("myProcess").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)

Aggregations

ProcessDiagramGenerator (org.activiti.image.ProcessDiagramGenerator)14 InputStream (java.io.InputStream)10 DefaultProcessDiagramGenerator (org.activiti.image.impl.DefaultProcessDiagramGenerator)9 BpmnModel (org.activiti.bpmn.model.BpmnModel)8 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