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