Feature/event payload migration fix (#443)

* also update exclusive gateways when migrating to event payload spiffworkflow

* pyl w/ burnettk

* build docker image for this branch w/ burnettk

* check to make sure configs are not None w/ burnettk

* do not migrate tasks related to exclusive gateways w/ burnettk

---------

Co-authored-by: jasquat <jasquat@users.noreply.github.com>
This commit is contained in:
jasquat 2023-08-17 12:43:29 -04:00 committed by GitHub
parent a0202c6a5b
commit ed9bdd42da
2 changed files with 64 additions and 46 deletions

View File

@ -32,6 +32,7 @@ on:
branches:
- main
- feature/event-payloads-part-2
- feature/event-payload-migration-fix
- spiffdemo
jobs:

View File

@ -41,72 +41,89 @@ class VersionOneThree:
print("end VersionOneThree.run")
def get_relevant_task_definitions(self) -> list[TaskDefinitionModel]:
task_definitions: list[TaskDefinitionModel] = TaskDefinitionModel.query.filter_by(
typename="_BoundaryEventParent"
task_definitions: list[TaskDefinitionModel] = TaskDefinitionModel.query.filter(
# this actually affect most types of gateways but Exclusive is the only we fully support in the WebUi as of 2023-08-15
TaskDefinitionModel.typename.in_(["_BoundaryEventParent", "ExclusiveGateway"]) # type: ignore
).all()
return task_definitions
def process_task_definition(self, task_definition: TaskDefinitionModel) -> None:
task_definition.typename = "BoundaryEventSplit"
task_definition.typename = task_definition.typename.replace("_BoundaryEventParent", "BoundaryEventSplit")
task_definition.bpmn_identifier = task_definition.bpmn_identifier.replace(
"BoundaryEventParent", "BoundaryEventSplit"
)
properties_json = copy.copy(task_definition.properties_json)
properties_json.pop("main_child_task_spec")
properties_json.pop("main_child_task_spec", None)
properties_json["typename"] = task_definition.typename
properties_json["name"] = task_definition.bpmn_identifier
# mostly for ExclusiveGateways
if "cond_task_specs" in properties_json and properties_json["cond_task_specs"] is not None:
for cond_task_spec in properties_json["cond_task_specs"]:
cond_task_spec["task_spec"] = cond_task_spec["task_spec"].replace(
"BoundaryEventParent", "BoundaryEventSplit"
)
if "default_task_spec" in properties_json and properties_json["default_task_spec"] is not None:
properties_json["default_task_spec"] = properties_json["default_task_spec"].replace(
"BoundaryEventParent", "BoundaryEventSplit"
)
task_definition.properties_json = properties_json
flag_modified(task_definition, "properties_json") # type: ignore
db.session.add(task_definition)
join_properties_json = {
"name": task_definition.bpmn_identifier.replace("BoundaryEventSplit", "BoundaryEventJoin"),
"manual": False,
"bpmn_id": None,
"lookahead": 2,
"inputs": properties_json["outputs"],
"outputs": [],
"split_task": task_definition.bpmn_identifier,
"threshold": None,
"cancel": True,
"typename": "BoundaryEventJoin",
}
if task_definition.typename == "BoundaryEventSplit":
join_properties_json = {
"name": task_definition.bpmn_identifier.replace("BoundaryEventSplit", "BoundaryEventJoin"),
"manual": False,
"bpmn_id": None,
"lookahead": 2,
"inputs": properties_json["outputs"],
"outputs": [],
"split_task": task_definition.bpmn_identifier,
"threshold": None,
"cancel": True,
"typename": "BoundaryEventJoin",
}
join_task_definition = TaskDefinitionModel(
bpmn_process_definition_id=task_definition.bpmn_process_definition_id,
bpmn_identifier=join_properties_json["name"],
typename=join_properties_json["typename"],
properties_json=join_properties_json,
)
db.session.add(join_task_definition)
for parent_bpmn_identifier in properties_json["inputs"]:
parent_task_definition = TaskDefinitionModel.query.filter_by(
bpmn_identifier=parent_bpmn_identifier,
join_task_definition = TaskDefinitionModel(
bpmn_process_definition_id=task_definition.bpmn_process_definition_id,
).first()
parent_task_definition.properties_json["outputs"] = [
name.replace("BoundaryEventParent", "BoundaryEventSplit")
for name in parent_task_definition.properties_json["outputs"]
]
flag_modified(parent_task_definition, "properties_json") # type: ignore
db.session.add(parent_task_definition)
bpmn_identifier=join_properties_json["name"],
typename=join_properties_json["typename"],
properties_json=join_properties_json,
)
db.session.add(join_task_definition)
for child_bpmn_identifier in properties_json["outputs"]:
child_task_definition = TaskDefinitionModel.query.filter_by(
bpmn_identifier=child_bpmn_identifier,
bpmn_process_definition_id=task_definition.bpmn_process_definition_id,
).first()
child_task_definition.properties_json["outputs"].append(join_task_definition.bpmn_identifier)
child_task_definition.properties_json["inputs"] = [
name.replace("BoundaryEventParent", "BoundaryEventSplit")
for name in child_task_definition.properties_json["inputs"]
]
flag_modified(child_task_definition, "properties_json") # type: ignore
db.session.add(child_task_definition)
for parent_bpmn_identifier in properties_json["inputs"]:
parent_task_definition = TaskDefinitionModel.query.filter_by(
bpmn_identifier=parent_bpmn_identifier,
bpmn_process_definition_id=task_definition.bpmn_process_definition_id,
).first()
parent_task_definition.properties_json["outputs"] = [
name.replace("BoundaryEventParent", "BoundaryEventSplit")
for name in parent_task_definition.properties_json["outputs"]
]
flag_modified(parent_task_definition, "properties_json") # type: ignore
db.session.add(parent_task_definition)
for child_bpmn_identifier in properties_json["outputs"]:
child_task_definition = TaskDefinitionModel.query.filter_by(
bpmn_identifier=child_bpmn_identifier,
bpmn_process_definition_id=task_definition.bpmn_process_definition_id,
).first()
child_task_definition.properties_json["outputs"].append(join_task_definition.bpmn_identifier)
child_task_definition.properties_json["inputs"] = [
name.replace("BoundaryEventParent", "BoundaryEventSplit")
for name in child_task_definition.properties_json["inputs"]
]
flag_modified(child_task_definition, "properties_json") # type: ignore
db.session.add(child_task_definition)
def process_task_model(self, task_model: TaskModel, task_definition: TaskDefinitionModel) -> None:
if task_definition.typename != "BoundaryEventSplit":
return
task_model.properties_json["task_spec"] = task_definition.bpmn_identifier
flag_modified(task_model, "properties_json") # type: ignore
db.session.add(task_model)