1+ from uuid import uuid4
2+
3+ def update_event_definition_attributes (dct ):
4+
5+ def update_specs (wf_spec ):
6+ for spec in wf_spec ['task_specs' ].values ():
7+ if 'event_definition' in spec :
8+ spec ['event_definition' ].pop ('internal' , None )
9+ spec ['event_definition' ].pop ('external' , None )
10+ if 'escalation_code' in spec ['event_definition' ]:
11+ spec ['event_definition' ]['code' ] = spec ['event_definition' ].pop ('escalation_code' )
12+ if 'error_code' in spec ['event_definition' ]:
13+ spec ['event_definition' ]['code' ] = spec ['event_definition' ].pop ('error_code' )
14+
15+ update_specs (dct ['spec' ])
16+ for sp_spec in dct ['subprocess_specs' ].values ():
17+ update_specs (sp_spec )
18+
19+ def remove_boundary_event_parent (dct ):
20+
21+ def update_specs (wf_spec ):
22+ new_specs , delete_specs = {}, []
23+ for spec in wf_spec ['task_specs' ].values ():
24+ if spec ['typename' ] == '_BoundaryEventParent' :
25+ delete_specs .append (spec ['name' ])
26+ spec .pop ('main_child_task_spec' )
27+ spec ['typename' ] = 'BoundaryEventSplit'
28+ spec ['name' ] = spec ['name' ].replace ('BoundaryEventParent' , 'BoundaryEventSplit' )
29+ new_specs [spec ['name' ]] = spec
30+ join = {
31+ "name" : spec ['name' ].replace ('BoundaryEventSplit' , 'BoundaryEventJoin' ),
32+ "manual" : False ,
33+ "bpmn_id" : None ,
34+ "lookahead" : 2 ,
35+ "inputs" : spec ['outputs' ],
36+ "outputs" : [],
37+ "split_task" : spec ['name' ],
38+ "threshold" : None ,
39+ "cancel" : True ,
40+ "typename" : "BoundaryEventJoin"
41+ }
42+ new_specs [join ['name' ]] = join
43+
44+ for parent in spec ['inputs' ]:
45+ parent_spec = wf_spec ['task_specs' ][parent ]
46+ parent_spec ['outputs' ] = [name .replace ('BoundaryEventParent' , 'BoundaryEventSplit' ) for name in parent_spec ['outputs' ]]
47+
48+ for child in spec ['outputs' ]:
49+ child_spec = wf_spec ['task_specs' ][child ]
50+ child_spec ['outputs' ].append (join ['name' ])
51+ child_spec ['inputs' ] = [name .replace ('BoundaryEventParent' , 'BoundaryEventSplit' ) for name in child_spec ['inputs' ]]
52+
53+ wf_spec ['task_specs' ].update (new_specs )
54+ for name in delete_specs :
55+ del wf_spec ['task_specs' ][name ]
56+
57+ def update_tasks (wf ):
58+ new_tasks = {}
59+ for task in wf ['tasks' ].values ():
60+ if task ['task_spec' ].endswith ('BoundaryEventParent' ):
61+ task ['task_spec' ] = task ['task_spec' ].replace ('BoundaryEventParent' , 'BoundaryEventSplit' )
62+ completed = all ([ wf ['tasks' ][child ]['state' ] in [64 , 256 ] for child in task ['children' ] ])
63+ for child in task ['children' ]:
64+ child_task = wf ['tasks' ][child ]
65+ if child_task ['state' ] < 8 :
66+ # MAYBE, LIKELY, FUTURE: use parent state
67+ state = child_task ['state' ]
68+ elif child_task ['state' ] < 64 :
69+ # WAITING, READY, STARTED (definite): join is FUTURE
70+ state = 4
71+ elif child_task ['state' ] == 64 :
72+ # COMPLETED: if the join is not finished, WAITING, otherwise COMPLETED
73+ state = 64 if completed else 8
74+ elif child_task ['state' ] == 128 :
75+ # ERROR: we don't know what the original state was, but we can't proceed through the gateway
76+ state = 8
77+ else :
78+ # Cancelled tasks don't have children
79+ continue
80+ new_task = {
81+ 'id' : str (uuid4 ()),
82+ 'parent' : child_task ['id' ],
83+ 'children' : [],
84+ 'state' : state ,
85+ 'task_spec' : task ['task_spec' ].replace ('BoundaryEventSplit' , 'BoundaryEventJoin' ),
86+ 'last_state_change' : None ,
87+ 'triggered' : False ,
88+ 'internal_data' : {},
89+ 'data' : {},
90+ }
91+ child_task ['children' ].append (new_task ['id' ])
92+ new_tasks [new_task ['id' ]] = new_task
93+
94+ wf ['tasks' ].update (new_tasks )
95+ pass
96+
97+ update_specs (dct ['spec' ])
98+ for sp_spec in dct ['subprocess_specs' ].values ():
99+ update_specs (sp_spec )
100+
101+ update_tasks (dct )
102+ for sp in dct ['subprocesses' ].values ():
103+ update_tasks (sp )
0 commit comments