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