use the full bpmn process path to determine most recent task w/ burnettk

This commit is contained in:
jasquat 2023-04-17 14:46:18 -04:00
parent 6bdec79a27
commit 771acc3c2e
2 changed files with 27 additions and 6 deletions

View File

@ -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:

View File

@ -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,