Last active
August 29, 2015 14:04
-
-
Save menski/72d35ce43b7d07fc9c19 to your computer and use it in GitHub Desktop.
Example of scripting with camunda BPM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:camunda="http://activiti.org/bpmn" | |
targetNamespace="http://camunda.org/exmaples"> | |
<process id="testProcess" isExecutable="true"> | |
<startEvent id="startEvent" /> | |
<sequenceFlow id="flow1" sourceRef="startEvent" targetRef="scriptTask" /> | |
<scriptTask id="scriptTask" scriptFormat="groovy"> | |
<extensionElements> | |
<camunda:inputOutput> | |
<camunda:inputParameter name="friend"> | |
<!-- script as input parameter --> | |
<camunda:script scriptFormat="groovy"> | |
friends = ["Fritz", "Heinz", "Horst", "Klaus"] | |
friends[new Random().nextInt(friends.size())] | |
</camunda:script> | |
</camunda:inputParameter> | |
</camunda:inputOutput> | |
</extensionElements> | |
<!-- script as script task --> | |
<script> | |
println "Hello $friend! Welcome to our casino" | |
</script> | |
</scriptTask> | |
<sequenceFlow id="flow2" sourceRef="scriptTask" targetRef="gateway" /> | |
<exclusiveGateway id="gateway" name="Dice"> | |
<extensionElements> | |
<camunda:executionListener event="start"> | |
<!-- script as execution listener --> | |
<camunda:script scriptFormat="groovy"> | |
aNumber = new Random().nextInt(6) + 1 | |
println "$aNumber was diced" | |
execution.setVariable('aNumber', aNumber) | |
</camunda:script> | |
</camunda:executionListener> | |
</extensionElements> | |
</exclusiveGateway> | |
<sequenceFlow sourceRef="gateway" targetRef="userTask1"> | |
<!-- script as sequence flow condition --> | |
<conditionExpression xsi:type="tFormalExpression" language="groovy"> | |
<![CDATA[ | |
aNumber < 4 | |
]]> | |
</conditionExpression> | |
</sequenceFlow> | |
<userTask id="userTask1" name="Less than 4"> | |
<extensionElements> | |
<camunda:taskListener event="create"> | |
<!-- script as task listener --> | |
<camunda:script scriptFormat="groovy"> | |
println "User task '$task.name' was $task.eventName" | |
</camunda:script> | |
</camunda:taskListener> | |
</extensionElements> | |
</userTask> | |
<sequenceFlow sourceRef="gateway" targetRef="userTask2"> | |
<!-- script as sequence flow condition --> | |
<conditionExpression xsi:type="tFormalExpression" language="groovy"> | |
aNumber > 3 | |
</conditionExpression> | |
</sequenceFlow> | |
<userTask id="userTask2" name="Greater than 3"> | |
<extensionElements> | |
<camunda:taskListener event="create"> | |
<!-- script as task listener --> | |
<camunda:script scriptFormat="groovy"> | |
println "User task '$task.name' was $task.eventName" | |
</camunda:script> | |
</camunda:taskListener> | |
</extensionElements> | |
</userTask> | |
</process> | |
<!-- bpmn di omitted --> | |
</definitions> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment