Search in sources :

Example 36 with SequenceFlow

use of org.activiti.bpmn.model.SequenceFlow in project Activiti by Activiti.

the class DefaultWorkflowDefinitionConversionListener method generateSequenceflowMappings.

protected SequenceFlowMapping generateSequenceflowMappings(Process process) {
    HashMap<String, List<SequenceFlow>> incomingSequenceFlowMapping = new HashMap<String, List<SequenceFlow>>();
    HashMap<String, List<SequenceFlow>> outgoingSequenceFlowMapping = new HashMap<String, List<SequenceFlow>>();
    for (FlowElement flowElement : process.findFlowElementsOfType(SequenceFlow.class)) {
        SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
        String srcId = sequenceFlow.getSourceRef();
        String targetId = sequenceFlow.getTargetRef();
        if (outgoingSequenceFlowMapping.get(srcId) == null) {
            outgoingSequenceFlowMapping.put(srcId, new ArrayList<SequenceFlow>());
        }
        outgoingSequenceFlowMapping.get(srcId).add(sequenceFlow);
        if (incomingSequenceFlowMapping.get(targetId) == null) {
            incomingSequenceFlowMapping.put(targetId, new ArrayList<SequenceFlow>());
        }
        incomingSequenceFlowMapping.get(targetId).add(sequenceFlow);
    }
    SequenceFlowMapping mapping = new SequenceFlowMapping();
    mapping.setIncomingSequenceFlowMapping(incomingSequenceFlowMapping);
    mapping.setOutgoingSequenceFlowMapping(outgoingSequenceFlowMapping);
    return mapping;
}
Also used : HashMap(java.util.HashMap) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) FlowElement(org.activiti.bpmn.model.FlowElement) ArrayList(java.util.ArrayList) List(java.util.List)

Example 37 with SequenceFlow

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

the class JobDefinitionRestControllerTest method getActivitiJobXml.

private String getActivitiJobXml(String namespace, String jobName) {
    BpmnModel bpmnModel = new BpmnModel();
    Process process = new Process();
    process.setId(namespace + '.' + jobName);
    {
        StartEvent element = new StartEvent();
        element.setId("start");
        process.addFlowElement(element);
    }
    {
        EndEvent element = new EndEvent();
        element.setId("end");
        process.addFlowElement(element);
    }
    process.addFlowElement(new SequenceFlow("start", "end"));
    bpmnModel.addProcess(process);
    return getActivitiXmlFromBpmnModel(bpmnModel);
}
Also used : SequenceFlow(org.activiti.bpmn.model.SequenceFlow) StartEvent(org.activiti.bpmn.model.StartEvent) EndEvent(org.activiti.bpmn.model.EndEvent) Process(org.activiti.bpmn.model.Process) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Example 38 with SequenceFlow

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

the class JobDefinitionServiceTest method testCreateJobDefinitionAssertThrowErrorWhenFirstTaskNotAsync.

/**
 * Asserts that create job definition proceeds throws an exception when the first task is not async
 *
 * @throws Exception
 */
@Test
public void testCreateJobDefinitionAssertThrowErrorWhenFirstTaskNotAsync() throws Exception {
    String namespace = NAMESPACE;
    String jobName = JOB_NAME;
    BpmnModel bpmnModel = new BpmnModel();
    Process process = new Process();
    process.setId(namespace + '.' + jobName);
    {
        StartEvent element = new StartEvent();
        element.setId("start");
        process.addFlowElement(element);
    }
    {
        ScriptTask element = new ScriptTask();
        element.setId("script");
        element.setScriptFormat("js");
        element.setScript("// do nothing");
        process.addFlowElement(element);
    }
    {
        EndEvent element = new EndEvent();
        element.setId("end");
        process.addFlowElement(element);
    }
    process.addFlowElement(new SequenceFlow("start", "script"));
    process.addFlowElement(new SequenceFlow("script", "end"));
    bpmnModel.addProcess(process);
    String activitiJobXml = getActivitiXmlFromBpmnModel(bpmnModel);
    namespaceDaoTestHelper.createNamespaceEntity(namespace);
    try {
        jobDefinitionService.createJobDefinition(new JobDefinitionCreateRequest(namespace, jobName, null, activitiJobXml, null, null), true);
        fail();
    } catch (Exception e) {
        assertEquals(IllegalArgumentException.class, e.getClass());
        assertEquals("Element with id \"script\" must be set to activiti:async=true. All tasks which start the workflow must be asynchronous to prevent " + "certain undesired transactional behavior, such as records of workflow not being saved on errors. Please refer to Activiti and herd " + "documentations for details.", e.getMessage());
    }
}
Also used : ScriptTask(org.activiti.bpmn.model.ScriptTask) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) StartEvent(org.activiti.bpmn.model.StartEvent) JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) EndEvent(org.activiti.bpmn.model.EndEvent) Process(org.activiti.bpmn.model.Process) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test)

Example 39 with SequenceFlow

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

the class HerdCommandInvokerTest method testAssertAsynchronousTaskErrorWrittenToJobEntity.

/**
 * Tests the error handling behavior for asynchronous tasks. This test proves 2 behaviors: when a asynchronous task is executed, and an error occurs, any
 * variables written by the tasks are persisted, and the error message and stack trace is recorded in the JobEntity which belongs to the execution. Writing
 * the exception in JobEntity ensures that we are able to retrieve the exception message in our GetJob API.
 * <p/>
 * This test must run outside of a transaction since the workflow will be executing asynchronously.
 *
 * @throws Exception
 */
@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void testAssertAsynchronousTaskErrorWrittenToJobEntity() throws Exception {
    // Create a workflow
    BpmnModel bpmnModel = new BpmnModel();
    Process process = new Process();
    process.setId("test");
    {
        StartEvent element = new StartEvent();
        element.setId("start");
        process.addFlowElement(element);
    }
    {
        ScriptTask element = new ScriptTask();
        element.setId("script1");
        element.setScriptFormat("js");
        element.setAsynchronous(true);
        element.setScript("execution.setVariable('foo', 'bar');");
        process.addFlowElement(element);
    }
    {
        ScriptTask element = new ScriptTask();
        element.setId("script2");
        element.setScriptFormat("js");
        element.setScript("throw new Error()");
        process.addFlowElement(element);
    }
    {
        EndEvent element = new EndEvent();
        element.setId("end");
        process.addFlowElement(element);
    }
    process.addFlowElement(new SequenceFlow("start", "script1"));
    process.addFlowElement(new SequenceFlow("script1", "script2"));
    process.addFlowElement(new SequenceFlow("script2", "end"));
    bpmnModel.addProcess(process);
    // Deploy the workflow
    activitiRepositoryService.createDeployment().addBpmnModel("bpmn20.xml", bpmnModel).deploy();
    // Start the process instance
    ProcessInstance processInstance = activitiRuntimeService.startProcessInstanceByKey("test");
    try {
        /*
             * Wait for process instance to run.
             * Note that we cannot use the convenience method waitUntilAllProcessCompleted() since the workflow will be in an error state and therefore stay
             * active.
             */
        long startTime = System.currentTimeMillis();
        HistoricVariableInstance persistedVariable = null;
        while (persistedVariable == null) {
            persistedVariable = activitiHistoryService.createHistoricVariableInstanceQuery().variableName("foo").singleResult();
            Thread.sleep(10);
            if (System.currentTimeMillis() - startTime > 10000) {
                fail("workflow did not reach the desired state within a reasonable time");
            }
        }
        // Make assertions
        // Assert variable is persisted
        assertEquals("bar", persistedVariable.getValue());
        // Assert exception message is logged
        assertEquals("ActivitiException: problem evaluating script: Error in <eval> at line number 1 at column number 0", activitiManagementService.createJobQuery().executionId(processInstance.getProcessInstanceId()).singleResult().getExceptionMessage());
    } finally {
        deleteActivitiDeployments();
    }
}
Also used : ScriptTask(org.activiti.bpmn.model.ScriptTask) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) StartEvent(org.activiti.bpmn.model.StartEvent) EndEvent(org.activiti.bpmn.model.EndEvent) Process(org.activiti.bpmn.model.Process) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test) HerdActivitiServiceTaskTest(org.finra.herd.service.activiti.task.HerdActivitiServiceTaskTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 40 with SequenceFlow

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

the class JobDefinitionServiceImpl method assertFirstTaskIsAsync.

/**
 * Asserts that the first asyncable task in the given model is indeed asynchronous. Only asserts when the configuration is set to true.
 *
 * @param bpmnModel The BPMN model
 */
private void assertFirstTaskIsAsync(BpmnModel bpmnModel) {
    if (Boolean.TRUE.equals(configurationHelper.getProperty(ConfigurationValue.ACTIVITI_JOB_DEFINITION_ASSERT_ASYNC, Boolean.class))) {
        Process process = bpmnModel.getMainProcess();
        for (StartEvent startEvent : process.findFlowElementsOfType(StartEvent.class)) {
            for (SequenceFlow sequenceFlow : startEvent.getOutgoingFlows()) {
                String targetRef = sequenceFlow.getTargetRef();
                FlowElement targetFlowElement = process.getFlowElement(targetRef);
                if (targetFlowElement instanceof Activity) {
                    Assert.isTrue(((Activity) targetFlowElement).isAsynchronous(), "Element with id \"" + targetRef + "\" must be set to activiti:async=true. All tasks which start the workflow must be asynchronous to prevent certain undesired " + "transactional behavior, such as records of workflow not being saved on errors. Please refer to Activiti and herd documentations " + "for details.");
                }
            }
        }
    }
}
Also used : SequenceFlow(org.activiti.bpmn.model.SequenceFlow) FlowElement(org.activiti.bpmn.model.FlowElement) StartEvent(org.activiti.bpmn.model.StartEvent) Activity(org.activiti.bpmn.model.Activity) Process(org.activiti.bpmn.model.Process)

Aggregations

SequenceFlow (org.activiti.bpmn.model.SequenceFlow)63 FlowElement (org.activiti.bpmn.model.FlowElement)34 Process (org.activiti.bpmn.model.Process)23 SubProcess (org.activiti.bpmn.model.SubProcess)19 BpmnModel (org.activiti.bpmn.model.BpmnModel)16 StartEvent (org.activiti.bpmn.model.StartEvent)15 EndEvent (org.activiti.bpmn.model.EndEvent)14 ArrayList (java.util.ArrayList)12 FlowNode (org.activiti.bpmn.model.FlowNode)12 GraphicInfo (org.activiti.bpmn.model.GraphicInfo)11 UserTask (org.activiti.bpmn.model.UserTask)11 Activity (org.activiti.bpmn.model.Activity)10 Gateway (org.activiti.bpmn.model.Gateway)9 HashMap (java.util.HashMap)7 Lane (org.activiti.bpmn.model.Lane)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)6 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)6 ExclusiveGateway (org.activiti.bpmn.model.ExclusiveGateway)6 Pool (org.activiti.bpmn.model.Pool)6