From 771acc3c2e62fbe117d7fbab4bb8a7c62119ef60 Mon Sep 17 00:00:00 2001 From: jasquat Date: Mon, 17 Apr 2023 14:46:18 -0400 Subject: [PATCH] use the full bpmn process path to determine most recent task w/ burnettk --- .../routes/process_instances_controller.py | 22 ++++++++++++++----- .../services/task_service.py | 11 ++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py index 37fa778b..f0943cd2 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py @@ -691,19 +691,29 @@ def process_instance_task_list( task_models = task_model_query.all() if most_recent_tasks_only: most_recent_tasks = {} - most_recent_subprocesses = set() + + # if you have a loop and there is a subprocess, and you are going around for the second time, + # ignore the tasks in the "first loop" subprocess + relevant_subprocess_guids = {bpmn_process_guid, None} + + bpmn_process_cache: dict[str, list[str]] = {} for task_model in task_models: - bpmn_process_guid = task_model.bpmn_process_guid or "TOP" - row_key = f"{bpmn_process_guid}:::{task_model.bpmn_identifier}" + if task_model.bpmn_process_guid not in bpmn_process_cache: + bpmn_process = BpmnProcessModel.query.filter_by(guid=task_model.bpmn_process_guid).first() + full_bpmn_process_path = TaskService.full_bpmn_process_path(bpmn_process) + bpmn_process_cache[task_model.bpmn_process_guid] = full_bpmn_process_path + else: + full_bpmn_process_path = bpmn_process_cache[task_model.bpmn_process_guid] + + row_key = f"{':::'.join(full_bpmn_process_path)}:::{task_model.bpmn_identifier}" if row_key not in most_recent_tasks: most_recent_tasks[row_key] = task_model if task_model.typename in ["SubWorkflowTask", "CallActivity"]: - most_recent_subprocesses.add(task_model.guid) - + relevant_subprocess_guids.add(task_model.guid) task_models = [ task_model for task_model in most_recent_tasks.values() - if task_model.bpmn_process_guid in most_recent_subprocesses or task_model.bpmn_process_guid is None + if task_model.bpmn_process_guid in relevant_subprocess_guids ] if to_task_model is not None: diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/task_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/task_service.py index 2e904a07..76880da2 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/task_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/task_service.py @@ -511,6 +511,17 @@ class TaskService: return (bpmn_processes + b, [parent_task_model] + t) return (bpmn_processes, task_models) + @classmethod + def full_bpmn_process_path(cls, bpmn_process: BpmnProcessModel) -> list[str]: + """Returns a list of bpmn process identifiers pointing the given bpmn_process.""" + bpmn_process_identifiers: list[str] = [bpmn_process.bpmn_process_definition.bpmn_identifier] + if bpmn_process.direct_parent_process_id is not None: + parent_bpmn_process = BpmnProcessModel.query.filter_by(id=bpmn_process.direct_parent_process_id).first() + if parent_bpmn_process is not None: + # always prepend new identifiers since they come first in the path + bpmn_process_identifiers = cls.full_bpmn_process_path(parent_bpmn_process) + bpmn_process_identifiers + return bpmn_process_identifiers + @classmethod def reset_task_model_dict( cls,