use of org.activiti.workflow.simple.converter.WorkflowDefinitionConversion 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.workflow.simple.converter.WorkflowDefinitionConversion in project Activiti by Activiti.
the class ReportingUtil method generateTaskDurationReport.
// WARNING!!! DemoWare!!!
public static void generateTaskDurationReport(String processDefinitionId) {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
// Fetch process definition
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
// Report descriptin
String reportDescription = "Average task duration report for process definition " + processDefinition.getName() + " ( version " + processDefinition.getVersion() + ")";
// Script (just plain String for the moment)
String script = "importPackage(java.sql);" + "importPackage(java.lang);" + "importPackage(org.activiti.explorer.reporting);" + "" + "var processDefinitionId = '" + processDefinitionId + "';" + "" + "var result = ReportingUtil.executeSelectSqlQuery(\"select NAME_, avg(DURATION_) from ACT_HI_TASKINST where PROC_DEF_ID_ = '" + processDefinitionId + "' and END_TIME_ is not null group by NAME_\");" + "" + "var reportData = new ReportData();" + "var dataset = reportData.newDataset();" + "dataset.type = 'pieChart';" + "dataset.description = '" + reportDescription + "';" + "" + "while (result.next()) { " + " var name = result.getString(1);" + " var val = result.getLong(2) / 1000;" + " dataset.add(name, val);" + "}" + "" + "execution.setVariable('reportData', reportData.toBytes());";
// Generate bpmn model
WorkflowDefinition workflowDefinition = new WorkflowDefinition().name(processDefinition.getName() + " task duration report").description(reportDescription).addScriptStep(script);
// Convert to BPMN 2.0 XML
WorkflowDefinitionConversion conversion = ExplorerApp.get().getWorkflowDefinitionConversionFactory().createWorkflowDefinitionConversion(workflowDefinition);
conversion.convert();
conversion.getBpmnModel().setTargetNamespace("activiti-report");
// Generate DI
BpmnAutoLayout bpmnAutoLayout = new BpmnAutoLayout(conversion.getBpmnModel());
bpmnAutoLayout.execute();
// Deploy
repositoryService.createDeployment().name(processDefinition.getName() + " - task duration report").addString(conversion.getProcess().getId() + ".bpmn20.xml", conversion.getBpmn20Xml()).deploy();
}
use of org.activiti.workflow.simple.converter.WorkflowDefinitionConversion in project Activiti by Activiti.
the class WorkflowDefinitionConversionTest method testCustomReference.
/**
* Test if a custom reference (eg. type=cm:person) is turned into an association on the
* model.
*/
@Test
public void testCustomReference() throws Exception {
// TODO: finish test once all types are present
WorkflowDefinition definition = new WorkflowDefinition();
definition.setId("process");
HumanStepDefinition humanStep = new HumanStepDefinition();
humanStep.setId("step1");
FormDefinition form = new FormDefinition();
humanStep.setForm(form);
FormPropertyGroup group = new FormPropertyGroup();
group.setId("group");
group.setTitle("My group");
humanStep.getForm().addFormPropertyGroup(group);
// Add simple text
ReferencePropertyDefinition textProperty = new ReferencePropertyDefinition();
textProperty.setName("person");
textProperty.setMandatory(true);
textProperty.setType("cm:person");
group.addFormProperty(textProperty);
definition.addStep(humanStep);
WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(definition);
conversion.convert();
// Check content-model
M2Model model = AlfrescoConversionUtil.getContentModel(conversion);
assertNotNull(model);
M2Type type = model.getTypes().get(0);
assertNotNull(type);
// Simple text
M2ClassAssociation association = getAssociationFromType("person", type);
assertEquals("cm:person", association.getTarget().getClassName());
assertTrue(association.getTarget().isMandatory());
}
use of org.activiti.workflow.simple.converter.WorkflowDefinitionConversion in project Activiti by Activiti.
the class WorkflowDefinitionConversionTest method testTaskListenerForOutgoingProperties.
@Test
public void testTaskListenerForOutgoingProperties() throws Exception {
WorkflowDefinition definition = new WorkflowDefinition();
definition.setId("process");
HumanStepDefinition humanStep = new HumanStepDefinition();
humanStep.setId("step1");
FormDefinition form = new FormDefinition();
humanStep.setForm(form);
TextPropertyDefinition text = new TextPropertyDefinition();
text.setName("my text");
text.getParameters().put(AlfrescoConversionConstants.PARAMETER_ADD_PROPERTY_TO_OUTPUT, true);
FormPropertyGroup group = new FormPropertyGroup();
group.setId("group");
form.getFormGroups().add(group);
group.getFormPropertyDefinitions().add(text);
definition.addStep(humanStep);
WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(definition);
conversion.convert();
Process process = conversion.getProcess();
assertNotNull(process);
boolean listenerFound = false;
for (FlowElement flowElement : process.getFlowElements()) {
if (flowElement instanceof UserTask) {
UserTask task = (UserTask) flowElement;
assertNotNull(task.getTaskListeners());
assertEquals(2L, task.getTaskListeners().size());
assertEquals("create", task.getTaskListeners().get(0).getEvent());
assertEquals("complete", task.getTaskListeners().get(1).getEvent());
listenerFound = true;
}
}
assertTrue(listenerFound);
}
use of org.activiti.workflow.simple.converter.WorkflowDefinitionConversion in project Activiti by Activiti.
the class WorkflowDefinitionConversionTest method testExportArtifacts.
/**
* Check artifact export.
*/
@Test
public void testExportArtifacts() throws Exception {
WorkflowDefinition definition = new WorkflowDefinition();
HumanStepDefinition humanStep = new HumanStepDefinition();
humanStep.setAssignee("fred");
humanStep.setId("step 1");
FormDefinition form = new FormDefinition();
form.setFormKey("wf:activitiAdhoc");
humanStep.setForm(form);
definition.addStep(humanStep);
WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(definition);
conversion.convert();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
conversionFactory.getArtifactExporter().writeBpmnModel(stream, conversion);
byte[] byteArray = stream.toByteArray();
assertTrue(byteArray.length > 0);
stream = new ByteArrayOutputStream();
conversionFactory.getArtifactExporter().writeContentModel(stream, conversion);
byteArray = stream.toByteArray();
assertTrue(byteArray.length > 0);
stream = new ByteArrayOutputStream();
conversionFactory.getArtifactExporter().writeShareConfig(stream, conversion, true);
byteArray = stream.toByteArray();
assertTrue(byteArray.length > 0);
stream = new ByteArrayOutputStream();
conversionFactory.getArtifactExporter().writeShareConfig(stream, conversion, false);
byteArray = stream.toByteArray();
assertTrue(byteArray.length > 0);
}
Aggregations