Merge pull request #203 from sartography/151-data-store-exclusive-branch-expression

Added the ability to use the custom functions within a decision/flow …
This commit is contained in:
Dan Funk 2020-12-01 14:44:27 -05:00 committed by GitHub
commit e15130e09c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 5 deletions

View File

@ -32,6 +32,14 @@ class CustomBpmnScriptEngine(BpmnScriptEngine):
It will execute python code read in from the bpmn. It will also make any scripts in the
scripts directory available for execution. """
def evaluate(self, task, expression):
"""
Evaluate the given expression, within the context of the given task and
return the result.
"""
return self.evaluate_expression(task, expression)
def execute(self, task: SpiffTask, script, data):
study_id = task.workflow.data[WorkflowProcessor.STUDY_ID_KEY]
@ -100,8 +108,25 @@ class CustomBpmnScriptEngine(BpmnScriptEngine):
Evaluate the given expression, within the context of the given task and
return the result.
"""
exp, valid = self.validateExpression(expression)
return self._eval(exp, **task.data)
study_id = task.workflow.data[WorkflowProcessor.STUDY_ID_KEY]
if WorkflowProcessor.WORKFLOW_ID_KEY in task.workflow.data:
workflow_id = task.workflow.data[WorkflowProcessor.WORKFLOW_ID_KEY]
else:
workflow_id = None
try:
if task.workflow.data[WorkflowProcessor.VALIDATION_PROCESS_KEY]:
augmentMethods = Script.generate_augmented_validate_list(task, study_id, workflow_id)
else:
augmentMethods = Script.generate_augmented_list(task, study_id, workflow_id)
exp, valid = self.validateExpression(expression)
return self._eval(exp, externalMethods=augmentMethods, **task.data)
except Exception as e:
raise WorkflowTaskExecException(task,
"Error evaluating expression "
"'%s', %s" % (expression, str(e)))
@staticmethod
def camel_to_snake(camel):

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_0kmksnn" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.7.0">
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_0kmksnn" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.7.0">
<bpmn:process id="Process_0exnnpv" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>SequenceFlow_1nfe5m9</bpmn:outgoing>
@ -12,7 +12,7 @@
</bpmn:scriptTask>
<bpmn:sequenceFlow id="SequenceFlow_1bqiin0" sourceRef="Task_Script_Load_Study_Sponsors" targetRef="Activity_0cm6tn2" />
<bpmn:endEvent id="EndEvent_171dj09">
<bpmn:incoming>Flow_05136ua</bpmn:incoming>
<bpmn:incoming>Flow_1efanns</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_09cika8" sourceRef="Activity_0cm6tn2" targetRef="Activity_0d8iftx" />
<bpmn:scriptTask id="Activity_0cm6tn2" name="setval">
@ -37,7 +37,19 @@
<bpmn:outgoing>Flow_05136ua</bpmn:outgoing>
<bpmn:script>empty = user_data_get('testme','empty')</bpmn:script>
</bpmn:scriptTask>
<bpmn:sequenceFlow id="Flow_05136ua" sourceRef="Activity_0xw717o" targetRef="EndEvent_171dj09" />
<bpmn:sequenceFlow id="Flow_05136ua" sourceRef="Activity_0xw717o" targetRef="Gateway_06osfqz" />
<bpmn:exclusiveGateway id="Gateway_06osfqz" default="Flow_00s638e">
<bpmn:incoming>Flow_05136ua</bpmn:incoming>
<bpmn:outgoing>Flow_1efanns</bpmn:outgoing>
<bpmn:outgoing>Flow_00s638e</bpmn:outgoing>
</bpmn:exclusiveGateway>
<bpmn:sequenceFlow id="Flow_1efanns" name="test flow expression" sourceRef="Gateway_06osfqz" targetRef="EndEvent_171dj09">
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">user_data_get('nothing','default') == 'default'</bpmn:conditionExpression>
</bpmn:sequenceFlow>
<bpmn:endEvent id="Event_1yebjqg">
<bpmn:incoming>Flow_00s638e</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_00s638e" sourceRef="Gateway_06osfqz" targetRef="Event_1yebjqg" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0exnnpv">
@ -84,7 +96,24 @@
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_05136ua_di" bpmnElement="Flow_05136ua">
<di:waypoint x="810" y="330" />
<di:waypoint x="810" y="385" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="Gateway_06osfqz_di" bpmnElement="Gateway_06osfqz" isMarkerVisible="true">
<dc:Bounds x="785" y="385" width="50" height="50" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_1efanns_di" bpmnElement="Flow_1efanns">
<di:waypoint x="810" y="435" />
<di:waypoint x="810" y="672" />
<bpmndi:BPMNLabel>
<dc:Bounds x="798" y="551" width="54" height="27" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="Event_1yebjqg_di" bpmnElement="Event_1yebjqg">
<dc:Bounds x="1012" y="392" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_00s638e_di" bpmnElement="Flow_00s638e">
<di:waypoint x="835" y="410" />
<di:waypoint x="1012" y="410" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>