Skip to content

Commit 6508254

Browse files
committed
add default correlation key
1 parent 79b1f32 commit 6508254

File tree

4 files changed

+76
-11
lines changed

4 files changed

+76
-11
lines changed

SpiffWorkflow/spiff/parser/event_parsers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ def parse_message_event(self, message_event):
8282
expression, variable = self.parse_message_extensions(message_event)
8383
correlations = self.get_message_correlations(message_ref)
8484
process_correlations = self.parse_process_correlations(message_event)
85+
for prop in correlations + process_correlations:
86+
if len(prop.correlation_keys) == 0:
87+
prop.correlation_keys.append('MainCorrelationKey')
8588
event_def = MessageEventDefinition(name, correlations, expression, variable, process_correlations)
8689
else:
8790
name = message_event.getparent().get('name')
@@ -179,4 +182,4 @@ def create_task(self):
179182
extensions = self.parse_extensions()
180183
task.prescript = extensions.get('preScript')
181184
task.postscript = extensions.get('postScript')
182-
return task
185+
return task

tests/SpiffWorkflow/spiff/CorrelationTest.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,24 @@ def actual_test(self, save_restore=False):
8787
self.workflow.catch(event)
8888
self.workflow.do_engine_steps()
8989
self.assertTrue(self.workflow.completed)
90+
91+
class DefaultCorrelationKeyTest(BaseTestCase):
92+
93+
def test_default_key(self):
94+
spec, subprocesses = self.load_workflow_spec('default_correlation_key.bpmn', 'main')
95+
self.workflow = BpmnWorkflow(spec, subprocesses)
96+
self.workflow.do_engine_steps()
97+
self.assertEqual(self.workflow.correlations, {'MainCorrelationKey': {'uid': 1}})
98+
waiting_task = self.workflow.get_next_task(state=TaskState.WAITING)
99+
event_def = waiting_task.task_spec.event_definition
100+
payload = {'uid': 1}
101+
correlations = event_def.calculate_correlations(
102+
waiting_task.workflow.script_engine,
103+
event_def.correlation_properties,
104+
payload
105+
)
106+
event = BpmnEvent(event_def, payload, correlations)
107+
self.workflow.catch(event)
108+
self.workflow.do_engine_steps()
109+
self.assertTrue(self.workflow.completed)
110+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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:process id="main" isExecutable="true">
4+
<bpmn:startEvent id="StartEvent_1">
5+
<bpmn:outgoing>Flow_17db3yp</bpmn:outgoing>
6+
</bpmn:startEvent>
7+
<bpmn:sequenceFlow id="Flow_17db3yp" sourceRef="StartEvent_1" targetRef="Activity_0qpzdpu" />
8+
<bpmn:endEvent id="EndEvent_1">
9+
<bpmn:incoming>Flow_12pkbxb</bpmn:incoming>
10+
</bpmn:endEvent>
11+
<bpmn:sequenceFlow id="Flow_12pkbxb" sourceRef="Activity_0qpzdpu" targetRef="EndEvent_1" />
12+
<bpmn:receiveTask id="Activity_0qpzdpu" name="Example manual task" messageRef="B" spiffworkflow:isMatchingCorrelation="true">
13+
<bpmn:extensionElements>
14+
<spiffworkflow:messageVariable>a_var</spiffworkflow:messageVariable>
15+
<spiffworkflow:processVariableCorrelation>
16+
<spiffworkflow:propertyId>uid</spiffworkflow:propertyId>
17+
<spiffworkflow:expression>1</spiffworkflow:expression>
18+
</spiffworkflow:processVariableCorrelation>
19+
</bpmn:extensionElements>
20+
<bpmn:incoming>Flow_17db3yp</bpmn:incoming>
21+
<bpmn:outgoing>Flow_12pkbxb</bpmn:outgoing>
22+
</bpmn:receiveTask>
23+
</bpmn:process>
24+
<bpmn:message id="B" name="B" />
25+
<bpmn:correlationProperty id="uid" name="uid">
26+
<bpmn:correlationPropertyRetrievalExpression messageRef="B">
27+
<bpmn:formalExpression>uid</bpmn:formalExpression>
28+
</bpmn:correlationPropertyRetrievalExpression>
29+
</bpmn:correlationProperty>
30+
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
31+
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_from_local_tests_nmkz3hh">
32+
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
33+
<dc:Bounds x="179" y="159" width="36" height="36" />
34+
</bpmndi:BPMNShape>
35+
<bpmndi:BPMNShape id="Event_14za570_di" bpmnElement="EndEvent_1">
36+
<dc:Bounds x="432" y="159" width="36" height="36" />
37+
</bpmndi:BPMNShape>
38+
<bpmndi:BPMNShape id="Activity_0a83z9o_di" bpmnElement="Activity_0qpzdpu">
39+
<dc:Bounds x="270" y="137" width="100" height="80" />
40+
</bpmndi:BPMNShape>
41+
<bpmndi:BPMNEdge id="Flow_17db3yp_di" bpmnElement="Flow_17db3yp">
42+
<di:waypoint x="215" y="177" />
43+
<di:waypoint x="270" y="177" />
44+
</bpmndi:BPMNEdge>
45+
<bpmndi:BPMNEdge id="Flow_12pkbxb_di" bpmnElement="Flow_12pkbxb">
46+
<di:waypoint x="370" y="177" />
47+
<di:waypoint x="432" y="177" />
48+
</bpmndi:BPMNEdge>
49+
</bpmndi:BPMNPlane>
50+
</bpmndi:BPMNDiagram>
51+
</bpmn:definitions>

tests/SpiffWorkflow/spiff/data/receive_correlations.bpmn

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@
4040
</bpmn:correlationKey>
4141
</bpmn:collaboration>
4242
<bpmn:message id="Message_16t6tet" name="message" />
43-
<bpmn:correlationProperty id="prop_1" name="prop_1">
44-
<bpmn:correlationPropertyRetrievalExpression messageRef="Message_16t6tet">
45-
<bpmn:formalExpression>msg_value_1</bpmn:formalExpression>
46-
</bpmn:correlationPropertyRetrievalExpression>
47-
</bpmn:correlationProperty>
48-
<bpmn:correlationProperty id="prop_2" name="prop_2">
49-
<bpmn:correlationPropertyRetrievalExpression messageRef="Message_16t6tet">
50-
<bpmn:formalExpression>msg_value_2</bpmn:formalExpression>
51-
</bpmn:correlationPropertyRetrievalExpression>
52-
</bpmn:correlationProperty>
5343
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
5444
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="correlation-test">
5545
<bpmndi:BPMNShape id="Event_0gayte6_di" bpmnElement="Event_0gayte6">

0 commit comments

Comments
 (0)