public static BpmnModelInstance oneClassDelegateServiceTask(String className) { return ProcessModels.newModel() .startEvent() .serviceTask("serviceTask") .camundaClass(className) .endEvent() .done(); } }
@Override public ServiceTaskBuilder builder() { return new ServiceTaskBuilder((BpmnModelInstance) modelInstance, this); }
@Deployment public static WebArchive createProcessApplication() { BpmnModelInstance process = Bpmn.createExecutableProcess(TEST_PROCESS) .startEvent() .serviceTask() .camundaDelegateExpression("${bpmnElementRetrievalDelegate}") .done(); return initWebArchiveDeployment() .addClass(BpmnElementRetrievalDelegate.class) .addAsResource(new StringAsset(Bpmn.convertToString(process)), "testProcess.bpmn20.xml"); }
protected BpmnModelInstance createFailingProcess() { return Bpmn.createExecutableProcess("Process") .startEvent() .serviceTask("failing") .camundaAsyncAfter() .camundaAsyncBefore() .camundaClass(FailingDelegate.class) .endEvent() .done(); }
public BpmnModelInstance build() { return ProcessModels.newModel(processKey) .startEvent() .serviceTask(externalTaskName) .camundaType(externalTaskType) .camundaTopic(topic) .camundaTaskPriority(priority.toString()) .endEvent() .done(); }
private BpmnModelInstance prepareFailingServiceTaskWithRetryCycle() { BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .serviceTask() .camundaClass(FAILING_CLASS) .camundaAsyncBefore() .camundaFailedJobRetryTimeCycle("R10/PT5M") .endEvent() .done(); return modelInstance; }
/** * Deploy a process model, which contains an external task. The topic is * given via parameter so the test cases are independent. * * @param engine the engine which is used to deploy the instance * @param topicName the topic name for the external task */ public static void deploy(ProcessEngine engine, String topicName) { BpmnModelInstance instance = Bpmn.createExecutableProcess(PROCESS_DEF_KEY) .startEvent() .serviceTask(EXTERNAL_TASK) .camundaType(EXTERNAL_TASK_TYPE) .camundaTopic(topicName) .endEvent() .done(); engine.getRepositoryService().createDeployment() .addModelInstance(ProcessWithExternalTaskScenario.class.getSimpleName() + ".startProcessWithFetch.bpmn20.xml", instance) .deploy(); }
public void testAsyncAfterErrorEvent() { // given BpmnModelInstance instance = Bpmn.createExecutableProcess("process") .startEvent() .serviceTask("servTask") .camundaClass(ThrowBpmnErrorDelegate.class) .boundaryEvent() .camundaAsyncAfter(true) .camundaFailedJobRetryTimeCycle("R10/PT10S") .errorEventDefinition() .errorEventDefinitionDone() .serviceTask() .camundaClass("foo") .endEvent() .moveToActivity("servTask") .endEvent().done(); deployment(instance); runtimeService.startProcessInstanceByKey("process"); Job job = managementService.createJobQuery().singleResult(); // when job fails try { managementService.executeJob(job.getId()); } catch (Exception e) { // ignore } // then job = managementService.createJobQuery().singleResult(); Assert.assertEquals(9, job.getRetries()); }
private BpmnModelInstance prepareFailingServiceTask() { BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .serviceTask() .camundaClass(FAILING_CLASS) .camundaAsyncBefore() .endEvent() .done(); return modelInstance; }
public static void main(String[] args) { BpmnModelInstance model = Bpmn.createExecutableProcess("payment") .startEvent() .serviceTask().id("charge").name("Charge credit card").camundaClass(ChargeCreditCardAdapter.class.getName()) // .boundaryEvent().error() .serviceTask().name("Ask customer to update credit card").camundaExpression("#{true}") // noop .receiveTask().id("wait").name("Wait for new credit card data").message("CreditCardUpdated") .boundaryEvent().timerWithDuration("PT7D") // 7 days .endEvent().camundaExecutionListenerClass("end", PaymentFailedAdapter.class.getName()) .moveToActivity("wait").connectTo("charge") // loop back with new data .moveToActivity("charge") .endEvent().camundaExecutionListenerClass("end", PaymentCompletedAdapter.class.getName()) .done(); File file = new File("result.bpmn"); Bpmn.writeModelToFile(file, model); } }
.parallelGateway("parallel") .serviceTask("external") .camundaType("external") .camundaTopic("external") .boundaryEvent() .message("message") .moveToNode("parallel") .serviceTask() .camundaAsyncBefore() .camundaExpression("${1/0}") .moveToLastGateway() .userTask() .done();
public void testConcurrentExecution() { deploymentForTenant("tenant1", Bpmn.createExecutableProcess(PROCESS_DEFINITION_KEY) .startEvent() .parallelGateway("fork") .serviceTask() .camundaClass(AssertingJavaDelegate.class.getName()) .parallelGateway("join") .endEvent() .moveToNode("fork") .serviceTask() .camundaClass(AssertingJavaDelegate.class.getName()) .connectTo("join") .done()); AssertingJavaDelegate.addAsserts(hasTenantId("tenant1")); startProcessInstance(PROCESS_DEFINITION_KEY); }
protected BpmnModelInstance createProcessWithServiceTask(String key) { return Bpmn.createExecutableProcess(key) .startEvent() .serviceTask() .camundaExpression("${true}") .endEvent() .done(); }
public void testCompleteWithNonLocalVariables() { // given BpmnModelInstance instance = Bpmn.createExecutableProcess("Process").startEvent().serviceTask("externalTask") .camundaType("external").camundaTopic("foo").camundaTaskPriority("100") .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, ReadLocalVariableListenerImpl.class) .userTask("user").endEvent().done(); deployment(instance); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process"); List<LockedExternalTask> lockedTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic("foo", 1L).execute(); // when externalTaskService.complete(lockedTasks.get(0).getId(), WORKER_ID, Variables.createVariables().putValue("abc", "bar"), null); // then VariableInstance variableInstance = runtimeService.createVariableInstanceQuery() .processInstanceIdIn(processInstance.getId()).singleResult(); assertNotNull(variableInstance); assertEquals("bar", variableInstance.getValue()); assertEquals("abc", variableInstance.getName()); }
private void createFlow() { engine.getRepositoryService().createDeployment() // .addModelInstance("order.bpmn", Bpmn.createProcess("order").executable() // .startEvent() .serviceTask().name("Retrieve payment").camundaClass(RetrievePaymentAdapter.class.getName()) .serviceTask().name("Fetch goods").camundaClass(FetchGoodsAdapter.class.getName()) .serviceTask().name("Ship goods").camundaClass(ShipGoodsAdapter.class.getName()) .endEvent().camundaExecutionListenerClass("end", OrderDeliveredAdapter.class.getName()) .done() ).deploy(); }
@Test public void testSetLocalScopeWithJavaDelegate() { testHelper.deploy(Bpmn.createExecutableProcess("process") .startEvent() .serviceTask() .id("activityId") .camundaClass(JavaDelegate.class) .endEvent() .done()); engineRule.getRuntimeService().startProcessInstanceByKey("process"); }
@Test public void testNonInterruptingSetVariableInDelegateWithSynchronousEvent() { BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY) .startEvent() .userTask().name(TASK_BEFORE_CONDITION) .serviceTask(TASK_WITH_CONDITION_ID) .camundaClass(SetVariableDelegate.class.getName()) .userTask() .endEvent().done(); modelInstance = modify(modelInstance) .serviceTaskBuilder(TASK_WITH_CONDITION_ID) .boundaryEvent() .cancelActivity(false) .conditionalEventDefinition(CONDITIONAL_EVENT) .condition(CONDITION_EXPR) .conditionalEventDefinitionDone() .done(); engine.manageDeployment(repositoryService.createDeployment().addModelInstance(CONDITIONAL_MODEL, modelInstance).deploy()); // given process with event sub process conditional start event and service task with delegate class which sets a variable ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY); TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId()); //when task before service task is completed taskService.complete(taskQuery.singleResult().getId()); //then service task with delegated code is called and variable is set //-> non interrupting conditional event is triggered //execution stays at user task after service task tasksAfterVariableIsSet = taskQuery.list(); assertEquals(1, tasksAfterVariableIsSet.size()); assertEquals(0, conditionEventSubscriptionQuery.list().size()); }
.serviceTask("car").name("Reserve car").camundaClass(ReserveCarAdapter.class) .boundaryEvent().compensateEventDefinition().compensateEventDefinitionDone() .compensationStart().serviceTask("CancelCar").camundaClass(CancelCarAdapter.class).compensationDone() .serviceTask("hotel").name("Book hotel").camundaClass(BookHotelAdapter.class) .boundaryEvent().compensateEventDefinition().compensateEventDefinitionDone() .compensationStart().serviceTask("CancelHotel").camundaClass(CancelHotelAdapter.class).compensationDone() .serviceTask("flight").name("Book flight").camundaClass(BookFlightAdapter.class) .boundaryEvent().compensateEventDefinition().compensateEventDefinitionDone() .compensationStart().serviceTask("CancelFlight").camundaClass(CancelFlightAdapter.class).compensationDone() .endEvent();
.startEvent() .serviceTask("serviceTask1") .camundaClass(IncreaseCurrentTimeServiceTask.class.getName()) .boundaryEvent("compensationBoundary1") .compensateEventDefinition() .compensateEventDefinitionDone() .moveToActivity("serviceTask1") .serviceTask("serviceTask2") .camundaClass(IncreaseCurrentTimeServiceTask.class.getName()) .boundaryEvent("compensationBoundary2") .compensateEventDefinition() .compensateEventDefinitionDone()
public void testPropagateTenantIdToVariableInstanceFromExecution() { deploymentForTenant(TENANT_ID, Bpmn.createExecutableProcess(PROCESS_DEFINITION_KEY) .startEvent() .serviceTask() .camundaClass(SetVariableTask.class.getName()) .camundaAsyncAfter() .endEvent() .done()); startProcessInstance(PROCESS_DEFINITION_KEY); VariableInstance variableInstance = runtimeService.createVariableInstanceQuery().singleResult(); assertThat(variableInstance, is(notNullValue())); // inherit the tenant id from execution assertThat(variableInstance.getTenantId(), is(TENANT_ID)); }