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