Search in sources :

Example 11 with ProcessDiagramGenerator

use of org.activiti.image.ProcessDiagramGenerator in project CzechIdMng by bcvsolutions.

the class DefaultWorkflowHistoricProcessInstanceService method getDiagram.

/**
 * Generate diagram for process instance. Highlight historic path (activity
 * and flows)
 */
@Override
public InputStream getDiagram(String processInstanceId) {
    if (processInstanceId == null) {
        throw new ActivitiIllegalArgumentException("No process instance id provided");
    }
    HistoricProcessInstance pi = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
    if (pi == null) {
        throw new ActivitiObjectNotFoundException("Process instance with id " + processInstanceId + " could not be found", ProcessInstance.class);
    }
    ProcessDefinitionEntity pde = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(pi.getProcessDefinitionId());
    if (pde != null && pde.isGraphicalNotationDefined()) {
        BpmnModel bpmnModel = repositoryService.getBpmnModel(pde.getId());
        List<String> historicActivityInstanceList = new ArrayList<String>();
        List<String> highLightedFlows = new ArrayList<String>();
        historicActivityInstanceList = getHighLightedFlows(bpmnModel, processInstanceId, historicActivityInstanceList, highLightedFlows);
        ProcessDiagramGenerator diagramGenerator = new DefaultProcessDiagramGenerator();
        return diagramGenerator.generateDiagram(bpmnModel, "png", historicActivityInstanceList, highLightedFlows);
    } else {
        throw new ActivitiException("Process instance with id " + processInstanceId + " has no graphic description");
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) ProcessDiagramGenerator(org.activiti.image.ProcessDiagramGenerator) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Example 12 with ProcessDiagramGenerator

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

the class ProcessDiagramGeneratorTest method testAllElements.

@Deployment
public void testAllElements() 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();
    BpmnModel bpmnModel = repositoryService.getBpmnModel(id);
    try (final InputStream resourceStream = imageGenerator.generateDiagram(bpmnModel, activityFontName, labelFontName, annotationFontName)) {
        SVGOMDocument svg = parseXml(resourceStream);
        List<String> startEventIdList = asList("startevent1", "errorstartevent1", "signalstartevent1", "messagestartevent1", "timerstartevent1");
        checkDiagramElements(startEventIdList, svg);
        List<String> userTaskIdList = asList("usertask1", "usertask2", "usertask3", "usertask4", "usertask5", "usertask6", "usertask7", "usertask8", "usertask9", "usertask10", "usertask11", "usertask12", "usertask13", "usertask14", "usertask15", "usertask16", "usertask17", "usertask18", "usertask19");
        checkDiagramElements(userTaskIdList, svg);
        List<String> scriptTaskIdList = asList("scripttask1", "scripttask2", "scripttask3");
        checkDiagramElements(scriptTaskIdList, svg);
        List<String> otherTaskIdList = asList("servicetask1", "mailtask1", "manualtask1", "receivetask1", "callactivity1");
        checkDiagramElements(otherTaskIdList, svg);
        List<String> intermediateEvent = asList("timerintermediatecatchevent1", "signalintermediatecatchevent1", "messageintermediatecatchevent1", "signalintermediatethrowevent1", "compensationintermediatethrowevent1", "noneintermediatethrowevent1");
        checkDiagramElements(intermediateEvent, svg);
        List<String> gatewayIdList = asList("parallelgateway1", "parallelgateway2", "exclusivegateway1", "exclusivegateway3", "inclusivegateway1", "inclusivegateway2", "eventgateway1");
        checkDiagramElements(gatewayIdList, svg);
        List<String> containerIdList = asList("subprocess1", "eventsubprocess1", "pool1", "pool2", "pool3", "lane1", "lane2", "lane3", "lane4");
        checkDiagramElements(containerIdList, svg);
        List<String> endEventIdList = asList("errorendevent1", "endevent1", "endevent2", "endevent3", "endevent4", "endevent5", "endevent6", "endevent7", "endevent8", "endevent9", "endevent10", "endevent11", "endevent12");
        checkDiagramElements(endEventIdList, svg);
    }
}
Also used : SVGOMDocument(org.apache.batik.anim.dom.SVGOMDocument) 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 13 with ProcessDiagramGenerator

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

the class ProcessDiagramGeneratorTest method testHighLighted.

@Deployment
public void testHighLighted() throws Exception {
    ProcessDiagramGenerator imageGenerator = new DefaultProcessDiagramGenerator();
    String activityFontName = imageGenerator.getDefaultActivityFontName();
    String labelFontName = imageGenerator.getDefaultLabelFontName();
    String annotationFontName = imageGenerator.getDefaultAnnotationFontName();
    runtimeService.startProcessInstanceByKey("myProcess");
    List<Task> tasks = taskService.createTaskQuery().list();
    for (Task task : tasks) {
        taskService.complete(task.getId());
    }
    Task task = taskService.createTaskQuery().taskDefinitionKey("usertask4").singleResult();
    taskService.complete(task.getId());
    List<String> activityIds = runtimeService.getActiveActivityIds(task.getProcessInstanceId());
    InputStream diagram = imageGenerator.generateDiagram(repositoryService.getBpmnModel(task.getProcessDefinitionId()), activityIds);
    assertThat(diagram).isNotNull();
    List<String> highLightedFlows = asList("flow1", "flow2", "flow3", "flow4", "flow5", "flow6");
    diagram = imageGenerator.generateDiagram(repositoryService.getBpmnModel(task.getProcessDefinitionId()), activityIds, highLightedFlows);
    assertThat(diagram).isNotNull();
    diagram = imageGenerator.generateDiagram(repositoryService.getBpmnModel(task.getProcessDefinitionId()), activityIds, highLightedFlows, activityFontName, labelFontName, annotationFontName);
    assertThat(diagram).isNotNull();
}
Also used : Task(org.activiti.engine.task.Task) DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) ProcessDiagramGenerator(org.activiti.image.ProcessDiagramGenerator) InputStream(java.io.InputStream) DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) Deployment(org.activiti.engine.test.Deployment)

Example 14 with ProcessDiagramGenerator

use of org.activiti.image.ProcessDiagramGenerator in project alfresco-remote-api by Alfresco.

the class ProcessesImpl method getProcessImage.

@Override
public BinaryResource getProcessImage(String processId) {
    validateIfUserAllowedToWorkWithProcess(processId);
    ProcessInstance processInstance = activitiProcessEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processId).singleResult();
    if (processInstance == null) {
        throw new EntityNotFoundException(processId);
    }
    try {
        BpmnModel model = activitiProcessEngine.getRepositoryService().getBpmnModel(processInstance.getProcessDefinitionId());
        if (model != null && model.getLocationMap().size() > 0) {
            List<String> activeActivities = activitiProcessEngine.getRuntimeService().getActiveActivityIds(processId);
            ProcessDiagramGenerator generator = new DefaultProcessDiagramGenerator();
            InputStream generateDiagram = generator.generateDiagram(model, "png", activeActivities);
            File file = TempFileProvider.createTempFile(processId + UUID.randomUUID(), ".png");
            FileOutputStream fos = new FileOutputStream(file);
            IOUtils.copy(generateDiagram, fos);
            fos.close();
            return new FileBinaryResource(file);
        } else {
            throw new EntityNotFoundException(processId + "/image");
        }
    } catch (IOException error) {
        throw new ApiException("Error while getting process image.");
    }
}
Also used : InputStream(java.io.InputStream) DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) IOException(java.io.IOException) FileBinaryResource(org.alfresco.rest.framework.resource.content.FileBinaryResource) BpmnModel(org.activiti.bpmn.model.BpmnModel) ProcessDiagramGenerator(org.activiti.image.ProcessDiagramGenerator) DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) FileOutputStream(java.io.FileOutputStream) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) File(java.io.File) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException)

Example 15 with ProcessDiagramGenerator

use of org.activiti.image.ProcessDiagramGenerator in project alfresco-repository by Alfresco.

the class ActivitiWorkflowEngine method getWorkflowImage.

/**
 * {@inheritDoc}
 */
public InputStream getWorkflowImage(String workflowInstanceId) {
    String processInstanceId = createLocalId(workflowInstanceId);
    ExecutionEntity pi = (ExecutionEntity) runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
    // If the process is finished, there is no diagram available
    if (pi != null) {
        // Fetch the bpmn model
        BpmnModel model = repoService.getBpmnModel(pi.getProcessDefinitionId());
        if (model != null && model.getLocationMap().size() > 0) {
            ProcessDiagramGenerator generator = new DefaultProcessDiagramGenerator();
            return generator.generateDiagram(model, ActivitiConstants.PROCESS_INSTANCE_IMAGE_FORMAT, runtimeService.getActiveActivityIds(processInstanceId));
        }
    }
    return null;
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) ProcessDiagramGenerator(org.activiti.image.ProcessDiagramGenerator) 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