mirror of
https://github.com/status-im/spiff-arena.git
synced 2025-01-15 04:34:16 +00:00
pyl
This commit is contained in:
parent
3bf1c49a75
commit
034201b01c
@ -1,5 +1,3 @@
|
|||||||
from __future__ import with_statement
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from logging.config import fileConfig
|
from logging.config import fileConfig
|
||||||
|
|
||||||
|
@ -80,7 +80,6 @@ class Task:
|
|||||||
|
|
||||||
HUMAN_TASK_TYPES = ["User Task", "Manual Task"]
|
HUMAN_TASK_TYPES = ["User Task", "Manual Task"]
|
||||||
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
id: str,
|
id: str,
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
"""APIs for dealing with process groups, process models, and process instances."""
|
"""APIs for dealing with process groups, process models, and process instances."""
|
||||||
import base64
|
import base64
|
||||||
from spiffworkflow_backend.services.task_service import TaskService
|
|
||||||
from sqlalchemy.orm import aliased
|
|
||||||
from spiffworkflow_backend.models.bpmn_process import BpmnProcessModel
|
|
||||||
import json
|
import json
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from uuid import UUID
|
|
||||||
|
|
||||||
import flask.wrappers
|
import flask.wrappers
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
@ -16,12 +12,12 @@ 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 Task as SpiffTask # type: ignore
|
|
||||||
from SpiffWorkflow.task import TaskState
|
|
||||||
from sqlalchemy import and_
|
from sqlalchemy import and_
|
||||||
from sqlalchemy import or_
|
from sqlalchemy import or_
|
||||||
|
from sqlalchemy.orm import aliased
|
||||||
|
|
||||||
from spiffworkflow_backend.exceptions.api_error import ApiError
|
from spiffworkflow_backend.exceptions.api_error import ApiError
|
||||||
|
from spiffworkflow_backend.models.bpmn_process import BpmnProcessModel
|
||||||
from spiffworkflow_backend.models.bpmn_process_definition import BpmnProcessDefinitionModel
|
from spiffworkflow_backend.models.bpmn_process_definition import BpmnProcessDefinitionModel
|
||||||
from spiffworkflow_backend.models.db import db
|
from spiffworkflow_backend.models.db import db
|
||||||
from spiffworkflow_backend.models.human_task import HumanTaskModel
|
from spiffworkflow_backend.models.human_task import HumanTaskModel
|
||||||
@ -46,7 +42,6 @@ from spiffworkflow_backend.models.process_model import ProcessModelInfo
|
|||||||
from spiffworkflow_backend.models.spec_reference import SpecReferenceCache
|
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_step_details import SpiffStepDetailsModel
|
from spiffworkflow_backend.models.spiff_step_details import SpiffStepDetailsModel
|
||||||
from spiffworkflow_backend.models.task import Task
|
|
||||||
from spiffworkflow_backend.models.task import TaskModel
|
from spiffworkflow_backend.models.task import TaskModel
|
||||||
from spiffworkflow_backend.models.task_definition import TaskDefinitionModel
|
from spiffworkflow_backend.models.task_definition import TaskDefinitionModel
|
||||||
from spiffworkflow_backend.models.user import UserModel
|
from spiffworkflow_backend.models.user import UserModel
|
||||||
@ -88,6 +83,7 @@ from spiffworkflow_backend.services.process_instance_service import (
|
|||||||
)
|
)
|
||||||
from spiffworkflow_backend.services.process_model_service import ProcessModelService
|
from spiffworkflow_backend.services.process_model_service import ProcessModelService
|
||||||
from spiffworkflow_backend.services.spec_file_service import SpecFileService
|
from spiffworkflow_backend.services.spec_file_service import SpecFileService
|
||||||
|
from spiffworkflow_backend.services.task_service import TaskService
|
||||||
|
|
||||||
|
|
||||||
def process_instance_create(
|
def process_instance_create(
|
||||||
@ -625,9 +621,7 @@ def process_instance_task_list(
|
|||||||
if to_task_model is None:
|
if to_task_model is None:
|
||||||
raise ApiError(
|
raise ApiError(
|
||||||
error_code="task_not_found",
|
error_code="task_not_found",
|
||||||
message=(
|
message=f"Cannot find a task with guid '{to_task_guid}' for process instance '{process_instance.id}'",
|
||||||
f"Cannot find a task with guid '{to_task_guid}' for process instance '{process_instance.id}'"
|
|
||||||
),
|
|
||||||
status_code=400,
|
status_code=400,
|
||||||
)
|
)
|
||||||
task_model_query = task_model_query.filter(TaskModel.end_in_seconds <= to_task_model.end_in_seconds)
|
task_model_query = task_model_query.filter(TaskModel.end_in_seconds <= to_task_model.end_in_seconds)
|
||||||
@ -637,13 +631,18 @@ def process_instance_task_list(
|
|||||||
direct_parent_bpmn_process_definition_alias = aliased(BpmnProcessDefinitionModel)
|
direct_parent_bpmn_process_definition_alias = aliased(BpmnProcessDefinitionModel)
|
||||||
|
|
||||||
task_model_query = (
|
task_model_query = (
|
||||||
task_model_query.order_by(
|
task_model_query.order_by(TaskModel.id.desc()) # type: ignore
|
||||||
TaskModel.id.desc() # type: ignore
|
|
||||||
)
|
|
||||||
.join(TaskDefinitionModel, TaskDefinitionModel.id == TaskModel.task_definition_id)
|
.join(TaskDefinitionModel, TaskDefinitionModel.id == TaskModel.task_definition_id)
|
||||||
.join(bpmn_process_alias, bpmn_process_alias.id == TaskModel.bpmn_process_id)
|
.join(bpmn_process_alias, bpmn_process_alias.id == TaskModel.bpmn_process_id)
|
||||||
.outerjoin(direct_parent_bpmn_process_alias, direct_parent_bpmn_process_alias.id == bpmn_process_alias.direct_parent_process_id)
|
.outerjoin(
|
||||||
.outerjoin(direct_parent_bpmn_process_definition_alias, direct_parent_bpmn_process_definition_alias.id == direct_parent_bpmn_process_alias.bpmn_process_definition_id)
|
direct_parent_bpmn_process_alias,
|
||||||
|
direct_parent_bpmn_process_alias.id == bpmn_process_alias.direct_parent_process_id,
|
||||||
|
)
|
||||||
|
.outerjoin(
|
||||||
|
direct_parent_bpmn_process_definition_alias,
|
||||||
|
direct_parent_bpmn_process_definition_alias.id
|
||||||
|
== direct_parent_bpmn_process_alias.bpmn_process_definition_id,
|
||||||
|
)
|
||||||
.join(
|
.join(
|
||||||
BpmnProcessDefinitionModel, BpmnProcessDefinitionModel.id == TaskDefinitionModel.bpmn_process_definition_id
|
BpmnProcessDefinitionModel, BpmnProcessDefinitionModel.id == TaskDefinitionModel.bpmn_process_definition_id
|
||||||
)
|
)
|
||||||
@ -651,28 +650,27 @@ def process_instance_task_list(
|
|||||||
BpmnProcessDefinitionModel.bpmn_identifier.label("bpmn_process_definition_identifier"), # type: ignore
|
BpmnProcessDefinitionModel.bpmn_identifier.label("bpmn_process_definition_identifier"), # type: ignore
|
||||||
BpmnProcessDefinitionModel.bpmn_name.label("bpmn_process_definition_name"), # type: ignore
|
BpmnProcessDefinitionModel.bpmn_name.label("bpmn_process_definition_name"), # type: ignore
|
||||||
direct_parent_bpmn_process_alias.guid.label("bpmn_process_direct_parent_guid"),
|
direct_parent_bpmn_process_alias.guid.label("bpmn_process_direct_parent_guid"),
|
||||||
direct_parent_bpmn_process_definition_alias.bpmn_identifier.label("bpmn_process_direct_parent_bpmn_identifier"),
|
direct_parent_bpmn_process_definition_alias.bpmn_identifier.label(
|
||||||
|
"bpmn_process_direct_parent_bpmn_identifier"
|
||||||
|
),
|
||||||
TaskDefinitionModel.bpmn_identifier,
|
TaskDefinitionModel.bpmn_identifier,
|
||||||
TaskDefinitionModel.bpmn_name,
|
TaskDefinitionModel.bpmn_name,
|
||||||
TaskDefinitionModel.typename,
|
TaskDefinitionModel.typename,
|
||||||
TaskDefinitionModel.properties_json.label('task_definition_properties_json'), # type: ignore
|
TaskDefinitionModel.properties_json.label("task_definition_properties_json"), # type: ignore
|
||||||
TaskModel.guid,
|
TaskModel.guid,
|
||||||
TaskModel.state,
|
TaskModel.state,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(bpmn_process_ids) > 0:
|
if len(bpmn_process_ids) > 0:
|
||||||
task_model_query = (
|
task_model_query = task_model_query.filter(bpmn_process_alias.id.in_(bpmn_process_ids))
|
||||||
task_model_query.filter(bpmn_process_alias.id.in_(bpmn_process_ids))
|
|
||||||
)
|
|
||||||
|
|
||||||
task_models = task_model_query.all()
|
task_models = task_model_query.all()
|
||||||
# import pdb; pdb.set_trace()
|
|
||||||
if to_task_guid is not None:
|
if to_task_guid is not None:
|
||||||
task_models_dict = json.loads(current_app.json.dumps(task_models))
|
task_models_dict = json.loads(current_app.json.dumps(task_models))
|
||||||
for task_model in task_models_dict:
|
for task_model in task_models_dict:
|
||||||
if task_model['guid'] == to_task_guid and task_model['state'] == "COMPLETED":
|
if task_model["guid"] == to_task_guid and task_model["state"] == "COMPLETED":
|
||||||
task_model['state'] = "READY"
|
task_model["state"] = "READY"
|
||||||
return make_response(jsonify(task_models_dict), 200)
|
return make_response(jsonify(task_models_dict), 200)
|
||||||
|
|
||||||
return make_response(jsonify(task_models), 200)
|
return make_response(jsonify(task_models), 200)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
"""APIs for dealing with process groups, process models, and process instances."""
|
"""APIs for dealing with process groups, process models, and process instances."""
|
||||||
import json
|
import json
|
||||||
from spiffworkflow_backend.models.task import TaskModel # noqa: F401
|
|
||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
from sys import exc_info
|
from sys import exc_info
|
||||||
@ -37,8 +36,8 @@ from spiffworkflow_backend.models.human_task_user import HumanTaskUserModel
|
|||||||
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
|
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
|
||||||
from spiffworkflow_backend.models.process_instance import ProcessInstanceStatus
|
from spiffworkflow_backend.models.process_instance import ProcessInstanceStatus
|
||||||
from spiffworkflow_backend.models.process_model import ProcessModelInfo
|
from spiffworkflow_backend.models.process_model import ProcessModelInfo
|
||||||
from spiffworkflow_backend.models.spiff_step_details import SpiffStepDetailsModel
|
|
||||||
from spiffworkflow_backend.models.task import Task
|
from spiffworkflow_backend.models.task import Task
|
||||||
|
from spiffworkflow_backend.models.task import TaskModel # noqa: F401
|
||||||
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_principal_or_raise,
|
_find_principal_or_raise,
|
||||||
@ -176,9 +175,7 @@ def task_data_show(
|
|||||||
if task_model is None:
|
if task_model is None:
|
||||||
raise ApiError(
|
raise ApiError(
|
||||||
error_code="task_not_found",
|
error_code="task_not_found",
|
||||||
message=(
|
message=f"Cannot find a task with guid '{task_guid}' for process instance '{process_instance_id}'",
|
||||||
f"Cannot find a task with guid '{task_guid}' for process instance '{process_instance_id}'"
|
|
||||||
),
|
|
||||||
status_code=400,
|
status_code=400,
|
||||||
)
|
)
|
||||||
task_model.data = task_model.json_data()
|
task_model.data = task_model.json_data()
|
||||||
|
@ -13,7 +13,8 @@ from SpiffWorkflow.task import TaskStateNames
|
|||||||
from sqlalchemy.dialects.mysql import insert as mysql_insert
|
from sqlalchemy.dialects.mysql import insert as mysql_insert
|
||||||
from sqlalchemy.dialects.postgresql import insert as postgres_insert
|
from sqlalchemy.dialects.postgresql import insert as postgres_insert
|
||||||
|
|
||||||
from spiffworkflow_backend.models.bpmn_process import BpmnProcessModel, BpmnProcessNotFoundError
|
from spiffworkflow_backend.models.bpmn_process import BpmnProcessModel
|
||||||
|
from spiffworkflow_backend.models.bpmn_process import BpmnProcessNotFoundError
|
||||||
from spiffworkflow_backend.models.db import db
|
from spiffworkflow_backend.models.db import db
|
||||||
from spiffworkflow_backend.models.json_data import JsonDataModel # noqa: F401
|
from spiffworkflow_backend.models.json_data import JsonDataModel # noqa: F401
|
||||||
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
|
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
|
||||||
@ -204,7 +205,9 @@ class TaskService:
|
|||||||
direct_bpmn_process_parent = top_level_process
|
direct_bpmn_process_parent = top_level_process
|
||||||
for subprocess_guid, subprocess in subprocesses.items():
|
for subprocess_guid, subprocess in subprocesses.items():
|
||||||
if subprocess == spiff_workflow.outer_workflow:
|
if subprocess == spiff_workflow.outer_workflow:
|
||||||
direct_bpmn_process_parent = BpmnProcessModel.query.filter_by(guid=str(subprocess_guid)).first()
|
direct_bpmn_process_parent = BpmnProcessModel.query.filter_by(
|
||||||
|
guid=str(subprocess_guid)
|
||||||
|
).first()
|
||||||
if direct_bpmn_process_parent is None:
|
if direct_bpmn_process_parent is None:
|
||||||
raise BpmnProcessNotFoundError(
|
raise BpmnProcessNotFoundError(
|
||||||
f"Could not find bpmn process with guid: {str(subprocess_guid)} "
|
f"Could not find bpmn process with guid: {str(subprocess_guid)} "
|
||||||
@ -212,7 +215,9 @@ class TaskService:
|
|||||||
)
|
)
|
||||||
|
|
||||||
if direct_bpmn_process_parent is None:
|
if direct_bpmn_process_parent is None:
|
||||||
raise BpmnProcessNotFoundError(f"Could not find a direct bpmn process parent for guid: {bpmn_process_guid}")
|
raise BpmnProcessNotFoundError(
|
||||||
|
f"Could not find a direct bpmn process parent for guid: {bpmn_process_guid}"
|
||||||
|
)
|
||||||
|
|
||||||
bpmn_process.direct_parent_process_id = direct_bpmn_process_parent.id
|
bpmn_process.direct_parent_process_id = direct_bpmn_process_parent.id
|
||||||
|
|
||||||
@ -305,7 +310,9 @@ class TaskService:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def bpmn_process_and_descendants(cls, bpmn_processes: list[BpmnProcessModel]) -> list[BpmnProcessModel]:
|
def bpmn_process_and_descendants(cls, bpmn_processes: list[BpmnProcessModel]) -> list[BpmnProcessModel]:
|
||||||
bpmn_process_ids = [p.id for p in bpmn_processes]
|
bpmn_process_ids = [p.id for p in bpmn_processes]
|
||||||
direct_children = BpmnProcessModel.query.filter(BpmnProcessModel.direct_parent_process_id.in_(bpmn_process_ids)).all() # type: ignore
|
direct_children = BpmnProcessModel.query.filter(
|
||||||
|
BpmnProcessModel.direct_parent_process_id.in_(bpmn_process_ids) # type: ignore
|
||||||
|
).all()
|
||||||
if len(direct_children) > 0:
|
if len(direct_children) > 0:
|
||||||
return bpmn_processes + cls.bpmn_process_and_descendants(direct_children)
|
return bpmn_processes + cls.bpmn_process_and_descendants(direct_children)
|
||||||
return bpmn_processes
|
return bpmn_processes
|
||||||
|
@ -365,7 +365,9 @@ class TestProcessInstanceProcessor(BaseTest):
|
|||||||
assert len(all_spiff_tasks) > 1
|
assert len(all_spiff_tasks) > 1
|
||||||
for spiff_task in all_spiff_tasks:
|
for spiff_task in all_spiff_tasks:
|
||||||
assert spiff_task.state == TaskState.COMPLETED
|
assert spiff_task.state == TaskState.COMPLETED
|
||||||
assert_spiff_task_is_in_process("test_process_to_call_subprocess_script", "test_process_to_call_subprocess")
|
assert_spiff_task_is_in_process(
|
||||||
|
"test_process_to_call_subprocess_script", "test_process_to_call_subprocess"
|
||||||
|
)
|
||||||
assert_spiff_task_is_in_process("top_level_subprocess_script", "top_level_subprocess")
|
assert_spiff_task_is_in_process("top_level_subprocess_script", "top_level_subprocess")
|
||||||
assert_spiff_task_is_in_process("top_level_script", "top_level_process")
|
assert_spiff_task_is_in_process("top_level_script", "top_level_process")
|
||||||
|
|
||||||
@ -389,7 +391,9 @@ class TestProcessInstanceProcessor(BaseTest):
|
|||||||
assert bpmn_process_definition is not None
|
assert bpmn_process_definition is not None
|
||||||
assert bpmn_process_definition.bpmn_identifier == "test_process_to_call_subprocess"
|
assert bpmn_process_definition.bpmn_identifier == "test_process_to_call_subprocess"
|
||||||
assert bpmn_process.direct_parent_process_id is not None
|
assert bpmn_process.direct_parent_process_id is not None
|
||||||
direct_parent_process = BpmnProcessModel.query.filter_by(id=bpmn_process.direct_parent_process_id).first()
|
direct_parent_process = BpmnProcessModel.query.filter_by(
|
||||||
|
id=bpmn_process.direct_parent_process_id
|
||||||
|
).first()
|
||||||
assert direct_parent_process is not None
|
assert direct_parent_process is not None
|
||||||
assert direct_parent_process.bpmn_process_definition.bpmn_identifier == "test_process_to_call"
|
assert direct_parent_process.bpmn_process_definition.bpmn_identifier == "test_process_to_call"
|
||||||
|
|
||||||
|
@ -7,12 +7,10 @@ import {
|
|||||||
useSearchParams,
|
useSearchParams,
|
||||||
} from 'react-router-dom';
|
} from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
CaretRight,
|
|
||||||
TrashCan,
|
TrashCan,
|
||||||
StopOutline,
|
StopOutline,
|
||||||
PauseOutline,
|
PauseOutline,
|
||||||
PlayOutline,
|
PlayOutline,
|
||||||
CaretLeft,
|
|
||||||
InProgress,
|
InProgress,
|
||||||
Checkmark,
|
Checkmark,
|
||||||
Warning,
|
Warning,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user