Skip to content

Commit 5266747

Browse files
committed
add calculated correlations to waiting events
1 parent 6508254 commit 5266747

File tree

5 files changed

+129
-3
lines changed

5 files changed

+129
-3
lines changed

SpiffWorkflow/bpmn/specs/event_definitions/message.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ def calculate_correlations(self, script_engine, cp, ctx):
7777
return correlations
7878

7979
def details(self, my_task):
80-
return PendingBpmnEvent(self.name, self.__class__.__name__, self.correlation_properties)
80+
return PendingBpmnEvent(
81+
self.name,
82+
self.__class__.__name__,
83+
self.correlation_properties,
84+
my_task.workflow.correlations
85+
)
8186

8287
def __eq__(self, other):
8388
return super().__eq__(other) and self.name == other.name

SpiffWorkflow/bpmn/util/event.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ def __init__(self, event_definition, payload=None, correlations=None, target=Non
77

88

99
class PendingBpmnEvent:
10-
def __init__(self, name, event_type, value=None):
10+
def __init__(self, name, event_type, value=None, correlations=None):
1111
self.name = name
1212
self.event_type = event_type
13-
self.value = value
13+
self.value = value
14+
self.correlations = correlations or {}

tests/SpiffWorkflow/bpmn/CollaborationTest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def testBpmnMessage(self):
5959
self.assertEqual(['lover'], events[0].value[0].correlation_keys)
6060
self.assertEqual('from_name', events[0].value[0].retrieval_expression)
6161
self.assertEqual('lover_name', events[0].value[0].name)
62+
self.assertEqual({'lover': {'lover_name': 'Peggy'}}, events[0].correlations)
6263

6364
payload = {'from_name': 'Peggy', 'other_nonsense': 1001}
6465
message = BpmnEvent(
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from SpiffWorkflow import TaskState
2+
from SpiffWorkflow.bpmn import BpmnWorkflow, BpmnEvent
3+
4+
from .BaseTestCase import BaseTestCase
5+
6+
7+
class WaitingEventTest(BaseTestCase):
8+
9+
def test_data_persists_through_call_activity(self):
10+
11+
spec, subprocesses = self.load_workflow_spec('waiting_event.bpmn', 'main')
12+
workflow = BpmnWorkflow(spec, subprocesses)
13+
workflow.do_engine_steps()
14+
events = workflow.waiting_events()
15+
self.assertEqual(len(events), 1)
16+
self.assertEqual(events[0].correlations, {'MainCorrelationKey': {'uid': 1}})
17+
18+
task = workflow.get_next_task(state=TaskState.WAITING)
19+
payload = {'uid': 1, 'data': 'asdf'},
20+
event = BpmnEvent(task.task_spec.event_definition, payload, events[0].correlations)
21+
workflow.send_event(event)
22+
workflow.do_engine_steps()
23+
self.assertTrue(workflow.completed)
24+
self.assertTrue(workflow.data, {'a_var': payload})
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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:spiffworkflow="http://spiffworkflow.org/bpmn/schema/1.0/core" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_96f6665" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.0.0-dev">
3+
<bpmn:message id="A" name="A" />
4+
<bpmn:correlationProperty id="uid" name="uid">
5+
<bpmn:correlationPropertyRetrievalExpression messageRef="B">
6+
<bpmn:formalExpression>uid</bpmn:formalExpression>
7+
</bpmn:correlationPropertyRetrievalExpression>
8+
</bpmn:correlationProperty>
9+
<bpmn:collaboration id="Collaboration_0v09bq0">
10+
<bpmn:participant id="Participant_0t9mpe3" processRef="main" />
11+
<bpmn:correlationKey id="CorrelationKey_0sbzdpi" name="MainCorrelationKey">
12+
<bpmn:correlationPropertyRef>uid</bpmn:correlationPropertyRef>
13+
</bpmn:correlationKey>
14+
</bpmn:collaboration>
15+
<bpmn:process id="main" isExecutable="true">
16+
<bpmn:startEvent id="StartEvent_1">
17+
<bpmn:outgoing>Flow_0dv9as9</bpmn:outgoing>
18+
</bpmn:startEvent>
19+
<bpmn:endEvent id="EndEvent_1">
20+
<bpmn:incoming>Flow_1rr1vsn</bpmn:incoming>
21+
</bpmn:endEvent>
22+
<bpmn:subProcess id="Activity_0ifb3pp" name="My sub process">
23+
<bpmn:incoming>Flow_0dv9as9</bpmn:incoming>
24+
<bpmn:outgoing>Flow_1rr1vsn</bpmn:outgoing>
25+
<bpmn:receiveTask id="Activity_0qpzdpu" name="Example manual task" messageRef="B" spiffworkflow:isMatchingCorrelation="true">
26+
<bpmn:extensionElements>
27+
<spiffworkflow:messageVariable>a_var</spiffworkflow:messageVariable>
28+
<spiffworkflow:processVariableCorrelation>
29+
<spiffworkflow:propertyId>uid</spiffworkflow:propertyId>
30+
<spiffworkflow:expression>1</spiffworkflow:expression>
31+
</spiffworkflow:processVariableCorrelation>
32+
</bpmn:extensionElements>
33+
<bpmn:incoming>Flow_0tla9tb</bpmn:incoming>
34+
<bpmn:outgoing>Flow_08rb5on</bpmn:outgoing>
35+
</bpmn:receiveTask>
36+
<bpmn:startEvent id="Event_0jbdkgd">
37+
<bpmn:outgoing>Flow_0tla9tb</bpmn:outgoing>
38+
</bpmn:startEvent>
39+
<bpmn:endEvent id="Event_11tb5c8">
40+
<bpmn:incoming>Flow_08rb5on</bpmn:incoming>
41+
</bpmn:endEvent>
42+
<bpmn:sequenceFlow id="Flow_0tla9tb" sourceRef="Event_0jbdkgd" targetRef="Activity_0qpzdpu" />
43+
<bpmn:sequenceFlow id="Flow_08rb5on" sourceRef="Activity_0qpzdpu" targetRef="Event_11tb5c8" />
44+
</bpmn:subProcess>
45+
<bpmn:sequenceFlow id="Flow_0dv9as9" sourceRef="StartEvent_1" targetRef="Activity_0ifb3pp" />
46+
<bpmn:sequenceFlow id="Flow_1rr1vsn" sourceRef="Activity_0ifb3pp" targetRef="EndEvent_1" />
47+
</bpmn:process>
48+
<bpmn:message id="B" name="B" />
49+
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
50+
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_0v09bq0">
51+
<bpmndi:BPMNShape id="Participant_0t9mpe3_di" bpmnElement="Participant_0t9mpe3" isHorizontal="true">
52+
<dc:Bounds x="560" y="220" width="370" height="140" />
53+
</bpmndi:BPMNShape>
54+
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
55+
<dc:Bounds x="619" y="269" width="36" height="36" />
56+
</bpmndi:BPMNShape>
57+
<bpmndi:BPMNShape id="Event_14za570_di" bpmnElement="EndEvent_1">
58+
<dc:Bounds x="872" y="269" width="36" height="36" />
59+
</bpmndi:BPMNShape>
60+
<bpmndi:BPMNShape id="Activity_1vcs9l0_di" bpmnElement="Activity_0ifb3pp" isExpanded="false">
61+
<dc:Bounds x="710" y="247" width="100" height="80" />
62+
<bpmndi:BPMNLabel />
63+
</bpmndi:BPMNShape>
64+
<bpmndi:BPMNEdge id="Flow_0dv9as9_di" bpmnElement="Flow_0dv9as9">
65+
<di:waypoint x="655" y="287" />
66+
<di:waypoint x="710" y="287" />
67+
</bpmndi:BPMNEdge>
68+
<bpmndi:BPMNEdge id="Flow_1rr1vsn_di" bpmnElement="Flow_1rr1vsn">
69+
<di:waypoint x="810" y="287" />
70+
<di:waypoint x="872" y="287" />
71+
</bpmndi:BPMNEdge>
72+
</bpmndi:BPMNPlane>
73+
</bpmndi:BPMNDiagram>
74+
<bpmndi:BPMNDiagram id="BPMNDiagram_0qke028">
75+
<bpmndi:BPMNPlane id="BPMNPlane_1k2fhlz" bpmnElement="Activity_0ifb3pp">
76+
<bpmndi:BPMNShape id="Activity_0a83z9o_di" bpmnElement="Activity_0qpzdpu">
77+
<dc:Bounds x="270" y="170" width="100" height="80" />
78+
</bpmndi:BPMNShape>
79+
<bpmndi:BPMNShape id="Event_0jbdkgd_di" bpmnElement="Event_0jbdkgd">
80+
<dc:Bounds x="172" y="192" width="36" height="36" />
81+
</bpmndi:BPMNShape>
82+
<bpmndi:BPMNShape id="Event_11tb5c8_di" bpmnElement="Event_11tb5c8">
83+
<dc:Bounds x="422" y="192" width="36" height="36" />
84+
</bpmndi:BPMNShape>
85+
<bpmndi:BPMNEdge id="Flow_0tla9tb_di" bpmnElement="Flow_0tla9tb">
86+
<di:waypoint x="208" y="210" />
87+
<di:waypoint x="270" y="210" />
88+
</bpmndi:BPMNEdge>
89+
<bpmndi:BPMNEdge id="Flow_08rb5on_di" bpmnElement="Flow_08rb5on">
90+
<di:waypoint x="370" y="210" />
91+
<di:waypoint x="422" y="210" />
92+
</bpmndi:BPMNEdge>
93+
</bpmndi:BPMNPlane>
94+
</bpmndi:BPMNDiagram>
95+
</bpmn:definitions>

0 commit comments

Comments
 (0)