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");
}
}
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);
}
}
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();
}
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.");
}
}
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;
}
Aggregations