From cd41be4455f4f93ead337aca3d311b54b4da9431 Mon Sep 17 00:00:00 2001 From: jasquat Date: Thu, 9 Feb 2023 16:03:26 -0500 Subject: [PATCH] pyl w/ burnettk --- .../src/spiffworkflow_backend/models/task.py | 2 +- .../routes/process_instances_controller.py | 37 ++++++++++++------- .../services/process_instance_processor.py | 26 ++++++++++--- .../src/routes/ProcessInstanceShow.tsx | 4 +- 4 files changed, 47 insertions(+), 22 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/models/task.py b/spiffworkflow-backend/src/spiffworkflow_backend/models/task.py index 2ec61cff3..26f615ed2 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/models/task.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/models/task.py @@ -1,6 +1,5 @@ """Task.""" import enum -from SpiffWorkflow.task import TaskStateNames # type: ignore from typing import Any from typing import Optional from typing import Union @@ -8,6 +7,7 @@ from typing import Union import marshmallow from marshmallow import Schema from marshmallow_enum import EnumField # type: ignore +from SpiffWorkflow.task import TaskStateNames # type: ignore class MultiInstanceType(enum.Enum): 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 5d5960205..470c31983 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py @@ -11,7 +11,7 @@ from flask import jsonify from flask import make_response from flask import request from flask.wrappers import Response -from SpiffWorkflow.task import TaskState, TaskStateNames # type: ignore +from SpiffWorkflow.task import TaskState # type: ignore from sqlalchemy import and_ from sqlalchemy import or_ @@ -20,7 +20,6 @@ from spiffworkflow_backend.models.db import db from spiffworkflow_backend.models.human_task import HumanTaskModel from spiffworkflow_backend.models.human_task_user import HumanTaskUserModel from spiffworkflow_backend.models.process_instance import ProcessInstanceApiSchema -from spiffworkflow_backend.models.task import Task from spiffworkflow_backend.models.process_instance import ( ProcessInstanceCannotBeDeletedError, ) @@ -37,6 +36,7 @@ from spiffworkflow_backend.models.spec_reference import SpecReferenceCache from spiffworkflow_backend.models.spec_reference import SpecReferenceNotFoundError from spiffworkflow_backend.models.spiff_logging import SpiffLoggingModel from spiffworkflow_backend.models.spiff_step_details import SpiffStepDetailsModel +from spiffworkflow_backend.models.task import Task from spiffworkflow_backend.models.user import UserModel from spiffworkflow_backend.routes.process_api_blueprint import ( _find_process_instance_by_id_or_raise, @@ -583,33 +583,44 @@ def process_instance_task_list( if task_data is None: task_data = {} tasks[step_detail.task_id]["data"] = task_data - tasks[step_detail.task_id]['state'] = Task.task_state_name_to_int(step_detail.task_state) + tasks[step_detail.task_id]["state"] = Task.task_state_name_to_int( + step_detail.task_state + ) else: for subprocess_id, subprocess_info in subprocesses.items(): - if step_detail.task_id in subprocess_info['tasks']: + if step_detail.task_id in subprocess_info["tasks"]: task_data = ( - step_detail.task_json["task_data"] | step_detail.task_json["python_env"] + step_detail.task_json["task_data"] + | step_detail.task_json["python_env"] ) if task_data is None: task_data = {} - subprocess_info['tasks'][step_detail.task_id]["data"] = task_data - subprocess_info['tasks'][step_detail.task_id]['state'] = Task.task_state_name_to_int(step_detail.task_state) + subprocess_info["tasks"][step_detail.task_id]["data"] = task_data + subprocess_info["tasks"][step_detail.task_id]["state"] = ( + Task.task_state_name_to_int(step_detail.task_state) + ) subprocess_state_overrides[subprocess_id] = TaskState.WAITING for subprocess_info in subprocesses.values(): - for spiff_task_id in subprocess_info['tasks']: + for spiff_task_id in subprocess_info["tasks"]: if spiff_task_id not in steps_by_id: - subprocess_info['tasks'][spiff_task_id]['data'] = {} - subprocess_info['tasks'][spiff_task_id]['state'] = subprocess_state_overrides.get(spiff_task_id, TaskState.FUTURE) + subprocess_info["tasks"][spiff_task_id]["data"] = {} + subprocess_info["tasks"][spiff_task_id]["state"] = ( + subprocess_state_overrides.get(spiff_task_id, TaskState.FUTURE) + ) for spiff_task_id in tasks: if spiff_task_id not in steps_by_id: - tasks[spiff_task_id]['data'] = {} - tasks[spiff_task_id]['state'] = subprocess_state_overrides.get(spiff_task_id, TaskState.FUTURE) + tasks[spiff_task_id]["data"] = {} + tasks[spiff_task_id]["state"] = subprocess_state_overrides.get( + spiff_task_id, TaskState.FUTURE + ) process_instance.bpmn_json = json.dumps(bpmn_json) processor = ProcessInstanceProcessor(process_instance) - spiff_task = processor.__class__.get_task_by_bpmn_identifier(step_details[-1].bpmn_task_identifier, processor.bpmn_process_instance) + spiff_task = processor.__class__.get_task_by_bpmn_identifier( + step_details[-1].bpmn_task_identifier, processor.bpmn_process_instance + ) if spiff_task is not None: spiff_task.complete() diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py index db6ae2ec0..549d7f39f 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py @@ -730,7 +730,9 @@ class ProcessInstanceProcessor: "end_in_seconds": end_in_seconds, } - def spiff_step_details(self, spiff_task: Optional[SpiffTask] = None) -> SpiffStepDetailsModel: + def spiff_step_details( + self, spiff_task: Optional[SpiffTask] = None + ) -> SpiffStepDetailsModel: """SaveSpiffStepDetails.""" details_mapping = self.spiff_step_details_mapping(spiff_task=spiff_task) details_model = SpiffStepDetailsModel(**details_mapping) @@ -983,8 +985,12 @@ class ProcessInstanceProcessor: db.session.add(human_task_user) self.increment_spiff_step() - spiff_step_detail_mapping = self.spiff_step_details_mapping(spiff_task=ready_or_waiting_task, start_in_seconds=time.time()) - spiff_step_detail = SpiffStepDetailsModel(**spiff_step_detail_mapping) + spiff_step_detail_mapping = self.spiff_step_details_mapping( + spiff_task=ready_or_waiting_task, start_in_seconds=time.time() + ) + spiff_step_detail = SpiffStepDetailsModel( + **spiff_step_detail_mapping + ) db.session.add(spiff_step_detail) db.session.commit() @@ -1731,11 +1737,19 @@ class ProcessInstanceProcessor: human_task.completed_by_user_id = user.id human_task.completed = True db.session.add(human_task) - details_model = SpiffStepDetailsModel.query.filter_by(process_instance_id=self.process_instance_model.id, task_id=str(task.id), task_state="READY").order_by(SpiffStepDetailsModel.id.desc()).first() + details_model = ( + SpiffStepDetailsModel.query.filter_by( + process_instance_id=self.process_instance_model.id, + task_id=str(task.id), + task_state="READY", + ) + .order_by(SpiffStepDetailsModel.id.desc()) # type: ignore + .first() + ) if details_model is None: raise SpiffStepDetailIsMissingError( - f"Cannot find a ready spiff_step_detail entry for process instance {self.process_instance_model.id} " - f"and task_id is {task.id}" + "Cannot find a ready spiff_step_detail entry for process instance" + f" {self.process_instance_model.id} and task_id is {task.id}" ) details_model.task_state = task.get_state_name() diff --git a/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx b/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx index 10be9ed5a..e21e33049 100644 --- a/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx +++ b/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx @@ -243,7 +243,7 @@ export default function ProcessInstanceShow({ variant }: OwnProps) { const spiffStepLink = (label: any, distance: number) => { const processIdentifier = searchParams.get('process_identifier'); const callActivityTaskId = searchParams.get('call_activity_task_id'); - let queryParamArray = []; + const queryParamArray = []; if (processIdentifier) { queryParamArray.push(`process_identifier=${processIdentifier}`); } @@ -251,7 +251,7 @@ export default function ProcessInstanceShow({ variant }: OwnProps) { queryParamArray.push(`call_activity_task_id=${callActivityTaskId}`); } let queryParams = ''; - if (queryParamArray.length > 0){ + if (queryParamArray.length > 0) { queryParams = `?${queryParamArray.join('&')}`; } return (