Search in sources :

Example 1 with BpmnAutoLayout

use of org.activiti.bpmn.BpmnAutoLayout 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();
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) BpmnAutoLayout(org.activiti.bpmn.BpmnAutoLayout) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessEngine(org.activiti.engine.ProcessEngine) RepositoryService(org.activiti.engine.RepositoryService)

Example 2 with BpmnAutoLayout

use of org.activiti.bpmn.BpmnAutoLayout 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));
}
Also used : DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) ProcessDiagramGenerator(org.activiti.image.ProcessDiagramGenerator) InputStream(java.io.InputStream) BpmnAutoLayout(org.activiti.bpmn.BpmnAutoLayout) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) BpmnModel(org.activiti.bpmn.model.BpmnModel) InputStreamResource(org.springframework.core.io.InputStreamResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with BpmnAutoLayout

use of org.activiti.bpmn.BpmnAutoLayout in project Activiti by Activiti.

the class WorkflowDefinitionConversion method convert.

/**
   * Call this method to actually execute the conversion of the {@link WorkflowDefinition}
   * which was provided in the constructor.
   */
public void convert() {
    if (workflowDefinition == null) {
        throw new SimpleWorkflowException("Cannot start conversion: need to set a WorkflowDefinition first!");
    }
    this.incrementalIdMapping = new HashMap<String, Integer>();
    this.additionalArtifacts = new HashMap<String, Object>();
    // Create new process
    bpmnModel = new BpmnModel();
    process = new Process();
    bpmnModel.addProcess(process);
    // Let conversion listeners know initialization is finished
    if (conversionFactory.getAllWorkflowDefinitionConversionListeners() != null) {
        for (WorkflowDefinitionConversionListener conversionListener : conversionFactory.getAllWorkflowDefinitionConversionListeners()) {
            conversionListener.beforeStepsConversion(this);
        }
    }
    // Convert each step
    convertSteps(workflowDefinition.getSteps());
    // Let conversion listeners know step conversion is done
    if (conversionFactory.getAllWorkflowDefinitionConversionListeners() != null) {
        for (WorkflowDefinitionConversionListener conversionListener : conversionFactory.getAllWorkflowDefinitionConversionListeners()) {
            conversionListener.afterStepsConversion(this);
        }
    }
    // Add DI information to bpmn model
    BpmnAutoLayout bpmnAutoLayout = new BpmnAutoLayout(bpmnModel);
    bpmnAutoLayout.execute();
}
Also used : WorkflowDefinitionConversionListener(org.activiti.workflow.simple.converter.listener.WorkflowDefinitionConversionListener) BpmnAutoLayout(org.activiti.bpmn.BpmnAutoLayout) Process(org.activiti.bpmn.model.Process) SimpleWorkflowException(org.activiti.workflow.simple.exception.SimpleWorkflowException) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Example 4 with BpmnAutoLayout

use of org.activiti.bpmn.BpmnAutoLayout in project Activiti by Activiti.

the class ProcessWithCompensationConverterTest method testConvertingAfterAutoLayout.

@Test
public void testConvertingAfterAutoLayout() {
    final InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("ProcessWithCompensationAssociation.bpmn20.xml");
    BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
    BpmnModel bpmnModel1 = bpmnXMLConverter.convertToBpmnModel(new InputStreamProvider() {

        @Override
        public InputStream getInputStream() {
            return inputStream;
        }
    }, false, false);
    if (bpmnModel1.getLocationMap().size() == 0) {
        BpmnAutoLayout bpmnLayout = new BpmnAutoLayout(bpmnModel1);
        bpmnLayout.execute();
    }
    byte[] xmlByte = bpmnXMLConverter.convertToXML(bpmnModel1);
    final InputStream byteArrayInputStream = new ByteArrayInputStream(xmlByte);
    BpmnModel bpmnModel2 = bpmnXMLConverter.convertToBpmnModel(new InputStreamProvider() {

        @Override
        public InputStream getInputStream() {
            return byteArrayInputStream;
        }
    }, false, false);
    assertThat(bpmnModel1.getLocationMap()).hasSize(10);
    assertThat(bpmnModel2.getLocationMap()).hasSize(10);
    assertThat(bpmnModel1.getFlowLocationMap()).hasSize(7);
    assertThat(bpmnModel2.getFlowLocationMap()).hasSize(7);
}
Also used : InputStreamProvider(org.activiti.bpmn.converter.util.InputStreamProvider) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BpmnAutoLayout(org.activiti.bpmn.BpmnAutoLayout) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter) BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.jupiter.api.Test)

Example 5 with BpmnAutoLayout

use of org.activiti.bpmn.BpmnAutoLayout in project Activiti by Activiti.

the class SubProcessConverterAutoLayoutTest method convertModelToXML.

@Test
public void convertModelToXML() throws Exception {
    BpmnModel bpmnModel = readXMLFile();
    // Add DI information to bpmn model
    BpmnAutoLayout bpmnAutoLayout = new BpmnAutoLayout(bpmnModel);
    bpmnAutoLayout.execute();
    BpmnModel parsedModel = exportAndReadXMLFile(bpmnModel);
    validateModel(parsedModel);
    deployProcess(parsedModel);
}
Also used : BpmnAutoLayout(org.activiti.bpmn.BpmnAutoLayout) BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.jupiter.api.Test)

Aggregations

BpmnAutoLayout (org.activiti.bpmn.BpmnAutoLayout)5 BpmnModel (org.activiti.bpmn.model.BpmnModel)4 InputStream (java.io.InputStream)2 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)2 Test (org.junit.jupiter.api.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 BpmnXMLConverter (org.activiti.bpmn.converter.BpmnXMLConverter)1 InputStreamProvider (org.activiti.bpmn.converter.util.InputStreamProvider)1 Process (org.activiti.bpmn.model.Process)1 ProcessEngine (org.activiti.engine.ProcessEngine)1 RepositoryService (org.activiti.engine.RepositoryService)1 ProcessDiagramGenerator (org.activiti.image.ProcessDiagramGenerator)1 DefaultProcessDiagramGenerator (org.activiti.image.impl.DefaultProcessDiagramGenerator)1 WorkflowDefinitionConversion (org.activiti.workflow.simple.converter.WorkflowDefinitionConversion)1 WorkflowDefinitionConversionListener (org.activiti.workflow.simple.converter.listener.WorkflowDefinitionConversionListener)1 WorkflowDefinition (org.activiti.workflow.simple.definition.WorkflowDefinition)1 SimpleWorkflowException (org.activiti.workflow.simple.exception.SimpleWorkflowException)1 InputStreamResource (org.springframework.core.io.InputStreamResource)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1