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: branches:
- main - main
- feature/event-payloads-part-2 - feature/event-payloads-part-2
- feature/event-payload-migration-fix
- spiffdemo - spiffdemo
jobs: jobs:

View File

@ -41,72 +41,89 @@ class VersionOneThree:
print("end VersionOneThree.run") print("end VersionOneThree.run")
def get_relevant_task_definitions(self) -> list[TaskDefinitionModel]: def get_relevant_task_definitions(self) -> list[TaskDefinitionModel]:
task_definitions: list[TaskDefinitionModel] = TaskDefinitionModel.query.filter_by( task_definitions: list[TaskDefinitionModel] = TaskDefinitionModel.query.filter(
typename="_BoundaryEventParent" # 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() ).all()
return task_definitions return task_definitions
def process_task_definition(self, task_definition: TaskDefinitionModel) -> None: 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( task_definition.bpmn_identifier = task_definition.bpmn_identifier.replace(
"BoundaryEventParent", "BoundaryEventSplit" "BoundaryEventParent", "BoundaryEventSplit"
) )
properties_json = copy.copy(task_definition.properties_json) 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["typename"] = task_definition.typename
properties_json["name"] = task_definition.bpmn_identifier 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 task_definition.properties_json = properties_json
flag_modified(task_definition, "properties_json") # type: ignore flag_modified(task_definition, "properties_json") # type: ignore
db.session.add(task_definition) db.session.add(task_definition)
join_properties_json = { if task_definition.typename == "BoundaryEventSplit":
"name": task_definition.bpmn_identifier.replace("BoundaryEventSplit", "BoundaryEventJoin"), join_properties_json = {
"manual": False, "name": task_definition.bpmn_identifier.replace("BoundaryEventSplit", "BoundaryEventJoin"),
"bpmn_id": None, "manual": False,
"lookahead": 2, "bpmn_id": None,
"inputs": properties_json["outputs"], "lookahead": 2,
"outputs": [], "inputs": properties_json["outputs"],
"split_task": task_definition.bpmn_identifier, "outputs": [],
"threshold": None, "split_task": task_definition.bpmn_identifier,
"cancel": True, "threshold": None,
"typename": "BoundaryEventJoin", "cancel": True,
} "typename": "BoundaryEventJoin",
}
join_task_definition = TaskDefinitionModel( 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,
bpmn_process_definition_id=task_definition.bpmn_process_definition_id, bpmn_process_definition_id=task_definition.bpmn_process_definition_id,
).first() bpmn_identifier=join_properties_json["name"],
parent_task_definition.properties_json["outputs"] = [ typename=join_properties_json["typename"],
name.replace("BoundaryEventParent", "BoundaryEventSplit") properties_json=join_properties_json,
for name in parent_task_definition.properties_json["outputs"] )
] db.session.add(join_task_definition)
flag_modified(parent_task_definition, "properties_json") # type: ignore
db.session.add(parent_task_definition)
for child_bpmn_identifier in properties_json["outputs"]: for parent_bpmn_identifier in properties_json["inputs"]:
child_task_definition = TaskDefinitionModel.query.filter_by( parent_task_definition = TaskDefinitionModel.query.filter_by(
bpmn_identifier=child_bpmn_identifier, bpmn_identifier=parent_bpmn_identifier,
bpmn_process_definition_id=task_definition.bpmn_process_definition_id, bpmn_process_definition_id=task_definition.bpmn_process_definition_id,
).first() ).first()
child_task_definition.properties_json["outputs"].append(join_task_definition.bpmn_identifier) parent_task_definition.properties_json["outputs"] = [
child_task_definition.properties_json["inputs"] = [ name.replace("BoundaryEventParent", "BoundaryEventSplit")
name.replace("BoundaryEventParent", "BoundaryEventSplit") for name in parent_task_definition.properties_json["outputs"]
for name in child_task_definition.properties_json["inputs"] ]
] flag_modified(parent_task_definition, "properties_json") # type: ignore
flag_modified(child_task_definition, "properties_json") # type: ignore db.session.add(parent_task_definition)
db.session.add(child_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: 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 task_model.properties_json["task_spec"] = task_definition.bpmn_identifier
flag_modified(task_model, "properties_json") # type: ignore flag_modified(task_model, "properties_json") # type: ignore
db.session.add(task_model) db.session.add(task_model)