fixed get call activity task data w/ burnettk

This commit is contained in:
jasquat 2023-03-01 12:23:04 -05:00
parent e9f8364b1a
commit 3865fefd0c
No known key found for this signature in database
3 changed files with 21 additions and 18 deletions

View File

@ -580,6 +580,7 @@ def process_instance_task_list(
subprocess_info["tasks"][spiff_task_id]["state"] = ( subprocess_info["tasks"][spiff_task_id]["state"] = (
subprocess_state_overrides.get(spiff_task_id, TaskState.FUTURE) subprocess_state_overrides.get(spiff_task_id, TaskState.FUTURE)
) )
for spiff_task_id in tasks: for spiff_task_id in tasks:
if spiff_task_id not in steps_by_id: if spiff_task_id not in steps_by_id:
tasks[spiff_task_id]["data"] = {} tasks[spiff_task_id]["data"] = {}

View File

@ -620,7 +620,7 @@ def _render_jinja_template(unprocessed_template: str, spiff_task: SpiffTask) ->
wfe.error_line = unprocessed_template.split("\n")[tb.tb_lineno - 1] wfe.error_line = unprocessed_template.split("\n")[tb.tb_lineno - 1]
tb = tb.tb_next tb = tb.tb_next
wfe.add_note( wfe.add_note(
"Jinja2 template errors can happen when trying to displaying task data" "Jinja2 template errors can happen when trying to display task data"
) )
raise wfe from error raise wfe from error

View File

@ -1,6 +1,7 @@
"""Process_instance_processor.""" """Process_instance_processor."""
from hashlib import sha256 from hashlib import sha256
from spiffworkflow_backend.models import serialized_bpmn_definition from spiffworkflow_backend.models import serialized_bpmn_definition
from spiffworkflow_backend.models import process_instance_data
from spiffworkflow_backend.models.process_instance_data import ProcessInstanceDataModel from spiffworkflow_backend.models.process_instance_data import ProcessInstanceDataModel
from spiffworkflow_backend.models.serialized_bpmn_definition import SerializedBpmnDefinitionModel # noqa: F401 from spiffworkflow_backend.models.serialized_bpmn_definition import SerializedBpmnDefinitionModel # noqa: F401
import _strptime # type: ignore import _strptime # type: ignore
@ -520,7 +521,7 @@ class ProcessInstanceProcessor:
) )
@classmethod @classmethod
def get_full_bpmn_json(cls, process_instance_model: ProcessInstanceModel) -> dict: def _get_full_bpmn_json(cls, process_instance_model: ProcessInstanceModel) -> dict:
if process_instance_model.serialized_bpmn_definition_id is None: if process_instance_model.serialized_bpmn_definition_id is None:
return {} return {}
serialized_bpmn_definition = process_instance_model.serialized_bpmn_definition serialized_bpmn_definition = process_instance_model.serialized_bpmn_definition
@ -571,7 +572,7 @@ class ProcessInstanceProcessor:
spiff_logger.setLevel(logging.WARNING) spiff_logger.setLevel(logging.WARNING)
try: try:
full_bpmn_json = ProcessInstanceProcessor.get_full_bpmn_json(process_instance_model) full_bpmn_json = ProcessInstanceProcessor._get_full_bpmn_json(process_instance_model)
bpmn_process_instance = ( bpmn_process_instance = (
ProcessInstanceProcessor._serializer.deserialize_json( ProcessInstanceProcessor._serializer.deserialize_json(
json.dumps(full_bpmn_json) json.dumps(full_bpmn_json)
@ -732,12 +733,12 @@ class ProcessInstanceProcessor:
Rerturns: {process_name: [task_1, task_2, ...], ...} Rerturns: {process_name: [task_1, task_2, ...], ...}
""" """
bpmn_json = json.loads(self.process_instance_model.serialized_bpmn_definition.static_json or "{}") bpmn_definition_dict = json.loads(self.process_instance_model.serialized_bpmn_definition.static_json or "{}")
processes: dict[str, list[str]] = {bpmn_json["spec"]["name"]: []} processes: dict[str, list[str]] = {bpmn_definition_dict["spec"]["name"]: []}
for task_name, _task_spec in bpmn_json["spec"]["task_specs"].items(): for task_name, _task_spec in bpmn_definition_dict["spec"]["task_specs"].items():
processes[bpmn_json["spec"]["name"]].append(task_name) processes[bpmn_definition_dict["spec"]["name"]].append(task_name)
if "subprocess_specs" in bpmn_json: if "subprocess_specs" in bpmn_definition_dict:
for subprocess_name, subprocess_details in bpmn_json[ for subprocess_name, subprocess_details in bpmn_definition_dict[
"subprocess_specs" "subprocess_specs"
].items(): ].items():
processes[subprocess_name] = [] processes[subprocess_name] = []
@ -772,7 +773,7 @@ class ProcessInstanceProcessor:
################################################################# #################################################################
def get_all_task_specs(self, bpmn_json: dict) -> dict[str, dict]: def get_all_task_specs(self) -> dict[str, dict]:
"""This looks both at top level task_specs and subprocess_specs in the serialized data. """This looks both at top level task_specs and subprocess_specs in the serialized data.
It returns a dict of all task specs based on the task name like it is in the serialized form. It returns a dict of all task specs based on the task name like it is in the serialized form.
@ -780,9 +781,10 @@ class ProcessInstanceProcessor:
NOTE: this may not fully work for tasks that are NOT call activities since their task_name may not be unique NOTE: this may not fully work for tasks that are NOT call activities since their task_name may not be unique
but in our current use case we only care about the call activities here. but in our current use case we only care about the call activities here.
""" """
spiff_task_json = bpmn_json["spec"]["task_specs"] or {} bpmn_definition_dict = json.loads(self.process_instance_model.serialized_bpmn_definition.static_json or "{}")
if "subprocess_specs" in bpmn_json: spiff_task_json = bpmn_definition_dict["spec"]["task_specs"] or {}
for _subprocess_name, subprocess_details in bpmn_json[ if "subprocess_specs" in bpmn_definition_dict:
for _subprocess_name, subprocess_details in bpmn_definition_dict[
"subprocess_specs" "subprocess_specs"
].items(): ].items():
if "task_specs" in subprocess_details: if "task_specs" in subprocess_details:
@ -804,13 +806,13 @@ class ProcessInstanceProcessor:
Also note that subprocess_task_id might in fact be a call activity, because spiff treats Also note that subprocess_task_id might in fact be a call activity, because spiff treats
call activities like subprocesses in terms of the serialization. call activities like subprocesses in terms of the serialization.
""" """
bpmn_json = json.loads(self.process_instance_model.serialized_bpmn_definition.static_json or "{}") process_instance_data_dict = json.loads(self.process_instance_model.process_instance_data.runtime_json or '{}')
spiff_task_json = self.get_all_task_specs(bpmn_json) spiff_task_json = self.get_all_task_specs()
subprocesses_by_child_task_ids = {} subprocesses_by_child_task_ids = {}
task_typename_by_task_id = {} task_typename_by_task_id = {}
if "subprocesses" in bpmn_json: if "subprocesses" in process_instance_data_dict:
for subprocess_id, subprocess_details in bpmn_json["subprocesses"].items(): for subprocess_id, subprocess_details in process_instance_data_dict["subprocesses"].items():
for task_id, task_details in subprocess_details["tasks"].items(): for task_id, task_details in subprocess_details["tasks"].items():
subprocesses_by_child_task_ids[task_id] = subprocess_id subprocesses_by_child_task_ids[task_id] = subprocess_id
task_name = task_details["task_spec"] task_name = task_details["task_spec"]