Search in sources :

Example 26 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel 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 27 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel in project herd by FINRAOS.

the class AbstractServiceTest method getBpmnModelForXmlResource.

/**
 * Generates the BpmnModel for the given Activiti xml resource.
 *
 * @param activitiXmlResource the classpath location of Activiti Xml
 *
 * @return BpmnModel the constructed model
 * @throws Exception if any exception occurs in creation
 */
protected BpmnModel getBpmnModelForXmlResource(String activitiXmlResource) throws Exception {
    String activitiXml = IOUtils.toString(resourceLoader.getResource(activitiXmlResource).getInputStream());
    BpmnModel bpmnModel;
    try {
        bpmnModel = activitiHelper.constructBpmnModelFromXmlAndValidate(activitiXml);
    } catch (Exception ex) {
        throw new IllegalArgumentException("Error processing Activiti XML: " + ex.getMessage(), ex);
    }
    return bpmnModel;
}
Also used : BpmnModel(org.activiti.bpmn.model.BpmnModel)

Example 28 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel in project herd by FINRAOS.

the class AddEmrStepsTest method buildActivitiXml.

private String buildActivitiXml(String implementation, List<FieldExtension> fieldExtensionList) throws Exception {
    BpmnModel bpmnModel = getBpmnModelForXmlResource(ACTIVITI_XML_ADD_EMR_STEPS_WITH_CLASSPATH);
    ServiceTask serviceTask = (ServiceTask) bpmnModel.getProcesses().get(0).getFlowElement("addStepServiceTask");
    serviceTask.setImplementation(implementation);
    serviceTask.getFieldExtensions().addAll(fieldExtensionList);
    return getActivitiXmlFromBpmnModel(bpmnModel);
}
Also used : ServiceTask(org.activiti.bpmn.model.ServiceTask) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Example 29 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel in project herd by FINRAOS.

the class ActivitiDelegateTest method testDelegateWrongClass.

/**
 * This method tests when wrong class name is used in service task, the process instance is created.
 */
@Test
public void testDelegateWrongClass() throws Exception {
    BpmnModel bpmnModel = getBpmnModelForXmlResource(ACTIVITI_XML_HERD_WORKFLOW);
    ServiceTask serviceTask = (ServiceTask) bpmnModel.getProcesses().get(0).getFlowElement("servicetask1");
    serviceTask.setImplementation("ClassDoesNotExist");
    serviceTask.getFieldExtensions().clear();
    // Run a job with Activiti XML that will start cluster.
    try {
        jobServiceTestHelper.createJobFromActivitiXml(getActivitiXmlFromBpmnModel(bpmnModel), null);
        fail();
    } catch (Exception e) {
        assertEquals(ActivitiException.class, e.getClass());
        assertEquals("couldn't instantiate class ClassDoesNotExist", e.getMessage());
    }
}
Also used : ServiceTask(org.activiti.bpmn.model.ServiceTask) ActivitiException(org.activiti.engine.ActivitiException) ActivitiException(org.activiti.engine.ActivitiException) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test) HerdActivitiServiceTaskTest(org.finra.herd.service.activiti.task.HerdActivitiServiceTaskTest)

Example 30 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel in project herd by FINRAOS.

the class ActivitiDelegateTest method testDelegateSpringBeansNotPopulatedAgain.

/**
 * This method tests the scenario where a java delegate is not populated again with spring beans.
 */
@Test
public void testDelegateSpringBeansNotPopulatedAgain() throws Exception {
    BpmnModel bpmnModel = getBpmnModelForXmlResource(ACTIVITI_XML_HERD_WORKFLOW);
    ServiceTask serviceTask = (ServiceTask) bpmnModel.getProcesses().get(0).getFlowElement("servicetask1");
    serviceTask.setImplementation(MockJavaDelegate.class.getCanonicalName());
    serviceTask.getFieldExtensions().clear();
    // Define the job definition
    jobDefinitionServiceTestHelper.createJobDefinitionForActivitiXml(getActivitiXmlFromBpmnModel(bpmnModel));
    // Executing the job twice so that the same JavaDelegate object is used and spring beans are not wired again.
    jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME));
    jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME));
}
Also used : ServiceTask(org.activiti.bpmn.model.ServiceTask) MockJavaDelegate(org.finra.herd.service.activiti.task.MockJavaDelegate) BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test) HerdActivitiServiceTaskTest(org.finra.herd.service.activiti.task.HerdActivitiServiceTaskTest)

Aggregations

BpmnModel (org.activiti.bpmn.model.BpmnModel)265 Test (org.junit.jupiter.api.Test)123 Test (org.junit.Test)57 Process (org.activiti.bpmn.model.Process)26 BpmnXMLConverter (org.activiti.bpmn.converter.BpmnXMLConverter)22 InputStream (java.io.InputStream)19 StartEvent (org.activiti.bpmn.model.StartEvent)17 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)16 ArrayList (java.util.ArrayList)14 FlowElement (org.activiti.bpmn.model.FlowElement)13 ServiceTask (org.activiti.bpmn.model.ServiceTask)13 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)12 EndEvent (org.activiti.bpmn.model.EndEvent)11 ValidationError (org.activiti.validation.ValidationError)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 SubProcess (org.activiti.bpmn.model.SubProcess)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 Deployment (org.activiti.engine.repository.Deployment)9 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 ProcessDiagramGenerator (org.activiti.image.ProcessDiagramGenerator)9