pyl w/ burnettk

This commit is contained in:
jasquat 2023-02-09 16:03:26 -05:00
parent 0c30751946
commit cd41be4455
4 changed files with 47 additions and 22 deletions

View File

@ -1,6 +1,5 @@
"""Task.""" """Task."""
import enum import enum
from SpiffWorkflow.task import TaskStateNames # type: ignore
from typing import Any from typing import Any
from typing import Optional from typing import Optional
from typing import Union from typing import Union
@ -8,6 +7,7 @@ from typing import Union
import marshmallow import marshmallow
from marshmallow import Schema from marshmallow import Schema
from marshmallow_enum import EnumField # type: ignore from marshmallow_enum import EnumField # type: ignore
from SpiffWorkflow.task import TaskStateNames # type: ignore
class MultiInstanceType(enum.Enum): class MultiInstanceType(enum.Enum):

View File

@ -11,7 +11,7 @@ from flask import jsonify
from flask import make_response from flask import make_response
from flask import request from flask import request
from flask.wrappers import Response 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 and_
from sqlalchemy import or_ 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 import HumanTaskModel
from spiffworkflow_backend.models.human_task_user import HumanTaskUserModel from spiffworkflow_backend.models.human_task_user import HumanTaskUserModel
from spiffworkflow_backend.models.process_instance import ProcessInstanceApiSchema from spiffworkflow_backend.models.process_instance import ProcessInstanceApiSchema
from spiffworkflow_backend.models.task import Task
from spiffworkflow_backend.models.process_instance import ( from spiffworkflow_backend.models.process_instance import (
ProcessInstanceCannotBeDeletedError, 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.spec_reference import SpecReferenceNotFoundError
from spiffworkflow_backend.models.spiff_logging import SpiffLoggingModel from spiffworkflow_backend.models.spiff_logging import SpiffLoggingModel
from spiffworkflow_backend.models.spiff_step_details import SpiffStepDetailsModel 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.models.user import UserModel
from spiffworkflow_backend.routes.process_api_blueprint import ( from spiffworkflow_backend.routes.process_api_blueprint import (
_find_process_instance_by_id_or_raise, _find_process_instance_by_id_or_raise,
@ -583,33 +583,44 @@ def process_instance_task_list(
if task_data is None: if task_data is None:
task_data = {} task_data = {}
tasks[step_detail.task_id]["data"] = 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: else:
for subprocess_id, subprocess_info in subprocesses.items(): 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 = ( 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: if task_data is None:
task_data = {} task_data = {}
subprocess_info['tasks'][step_detail.task_id]["data"] = 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]["state"] = (
Task.task_state_name_to_int(step_detail.task_state)
)
subprocess_state_overrides[subprocess_id] = TaskState.WAITING subprocess_state_overrides[subprocess_id] = TaskState.WAITING
for subprocess_info in subprocesses.values(): 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: if spiff_task_id not in steps_by_id:
subprocess_info['tasks'][spiff_task_id]['data'] = {} 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]["state"] = (
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"] = {}
tasks[spiff_task_id]['state'] = subprocess_state_overrides.get(spiff_task_id, TaskState.FUTURE) tasks[spiff_task_id]["state"] = subprocess_state_overrides.get(
spiff_task_id, TaskState.FUTURE
)
process_instance.bpmn_json = json.dumps(bpmn_json) process_instance.bpmn_json = json.dumps(bpmn_json)
processor = ProcessInstanceProcessor(process_instance) 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: if spiff_task is not None:
spiff_task.complete() spiff_task.complete()

View File

@ -730,7 +730,9 @@ class ProcessInstanceProcessor:
"end_in_seconds": end_in_seconds, "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.""" """SaveSpiffStepDetails."""
details_mapping = self.spiff_step_details_mapping(spiff_task=spiff_task) details_mapping = self.spiff_step_details_mapping(spiff_task=spiff_task)
details_model = SpiffStepDetailsModel(**details_mapping) details_model = SpiffStepDetailsModel(**details_mapping)
@ -983,8 +985,12 @@ class ProcessInstanceProcessor:
db.session.add(human_task_user) db.session.add(human_task_user)
self.increment_spiff_step() 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_mapping = self.spiff_step_details_mapping(
spiff_step_detail = SpiffStepDetailsModel(**spiff_step_detail_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.add(spiff_step_detail)
db.session.commit() db.session.commit()
@ -1731,11 +1737,19 @@ class ProcessInstanceProcessor:
human_task.completed_by_user_id = user.id human_task.completed_by_user_id = user.id
human_task.completed = True human_task.completed = True
db.session.add(human_task) 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: if details_model is None:
raise SpiffStepDetailIsMissingError( raise SpiffStepDetailIsMissingError(
f"Cannot find a ready spiff_step_detail entry for process instance {self.process_instance_model.id} " "Cannot find a ready spiff_step_detail entry for process instance"
f"and task_id is {task.id}" f" {self.process_instance_model.id} and task_id is {task.id}"
) )
details_model.task_state = task.get_state_name() details_model.task_state = task.get_state_name()

View File

@ -243,7 +243,7 @@ export default function ProcessInstanceShow({ variant }: OwnProps) {
const spiffStepLink = (label: any, distance: number) => { const spiffStepLink = (label: any, distance: number) => {
const processIdentifier = searchParams.get('process_identifier'); const processIdentifier = searchParams.get('process_identifier');
const callActivityTaskId = searchParams.get('call_activity_task_id'); const callActivityTaskId = searchParams.get('call_activity_task_id');
let queryParamArray = []; const queryParamArray = [];
if (processIdentifier) { if (processIdentifier) {
queryParamArray.push(`process_identifier=${processIdentifier}`); queryParamArray.push(`process_identifier=${processIdentifier}`);
} }
@ -251,7 +251,7 @@ export default function ProcessInstanceShow({ variant }: OwnProps) {
queryParamArray.push(`call_activity_task_id=${callActivityTaskId}`); queryParamArray.push(`call_activity_task_id=${callActivityTaskId}`);
} }
let queryParams = ''; let queryParams = '';
if (queryParamArray.length > 0){ if (queryParamArray.length > 0) {
queryParams = `?${queryParamArray.join('&')}`; queryParams = `?${queryParamArray.join('&')}`;
} }
return ( return (