mirror of
https://github.com/sartography/spiffworkflow-backend.git
synced 2025-02-24 13:28:31 +00:00
added all_tasks option to process-instance/tasks endpoint and cleaned process instance show endpoint
This commit is contained in:
parent
b0a87d12d5
commit
772e5352ff
@ -679,6 +679,12 @@ paths:
|
||||
description: The unique id of an existing process instance.
|
||||
schema:
|
||||
type: integer
|
||||
- name: all_tasks
|
||||
in: query
|
||||
required: false
|
||||
description: If true, this wil return all tasks associated with the process instance and not just user tasks.
|
||||
schema:
|
||||
type: boolean
|
||||
get:
|
||||
operationId: spiffworkflow_backend.routes.process_api_blueprint.process_instance_task_list
|
||||
summary: returns the list of all user tasks associated with process instance
|
||||
|
@ -99,10 +99,7 @@ class ProcessInstanceModel(SpiffworkflowBaseDBModel):
|
||||
created_at_in_seconds: int = db.Column(db.Integer)
|
||||
status: str = db.Column(db.String(50))
|
||||
|
||||
data: dict | None = None
|
||||
bpmn_xml_file_name: str | None = None
|
||||
bpmn_xml_file_contents: bytes | None = None
|
||||
spiffworkflow_active_task_id: str | None = None
|
||||
|
||||
@property
|
||||
def serialized(self) -> dict[str, Any]:
|
||||
@ -116,14 +113,10 @@ class ProcessInstanceModel(SpiffworkflowBaseDBModel):
|
||||
"process_model_identifier": self.process_model_identifier,
|
||||
"process_group_identifier": self.process_group_identifier,
|
||||
"status": self.status,
|
||||
"bpmn_json": self.bpmn_json,
|
||||
"start_in_seconds": self.start_in_seconds,
|
||||
"end_in_seconds": self.end_in_seconds,
|
||||
"process_initiator_id": self.process_initiator_id,
|
||||
"data": self.data,
|
||||
"bpmn_xml_file_name": self.bpmn_xml_file_name,
|
||||
"bpmn_xml_file_contents": local_bpmn_xml_file_contents,
|
||||
"spiffworkflow_active_task_id": self.spiffworkflow_active_task_id,
|
||||
}
|
||||
|
||||
@property
|
||||
@ -149,8 +142,6 @@ class ProcessInstanceModelSchema(Schema):
|
||||
"process_model_identifier",
|
||||
"process_group_identifier",
|
||||
"process_initiator_id",
|
||||
# "process_initiator",
|
||||
"bpmn_json",
|
||||
"start_in_seconds",
|
||||
"end_in_seconds",
|
||||
"updated_at_in_seconds",
|
||||
|
@ -388,35 +388,18 @@ def process_instance_list(
|
||||
|
||||
|
||||
def process_instance_show(
|
||||
process_group_id: str, process_model_id: str, process_instance_id: int
|
||||
process_group_id: str, process_model_id: str, process_instance_id: int
|
||||
) -> flask.wrappers.Response:
|
||||
"""Create_process_instance."""
|
||||
process_instance = find_process_instance_by_id_or_raise(process_instance_id)
|
||||
process_model = get_process_model(process_model_id, process_group_id)
|
||||
|
||||
processor = ProcessInstanceProcessor(process_instance)
|
||||
process_instance.data = processor.get_data()
|
||||
|
||||
if process_model.primary_file_name:
|
||||
bpmn_xml_file_contents = SpecFileService.get_data(
|
||||
process_model, process_model.primary_file_name
|
||||
)
|
||||
process_instance.bpmn_xml_file_name = process_model.primary_file_name
|
||||
process_instance.bpmn_xml_file_contents = bpmn_xml_file_contents
|
||||
|
||||
active_task = (
|
||||
ActiveTaskModel.query.filter_by(
|
||||
process_instance_id=process_instance_id
|
||||
).order_by(
|
||||
desc(ActiveTaskModel.id) # type: ignore
|
||||
)
|
||||
).first()
|
||||
|
||||
if active_task:
|
||||
process_instance.spiffworkflow_active_task_id = (
|
||||
active_task.spiffworkflow_task_id
|
||||
)
|
||||
|
||||
return make_response(jsonify(process_instance), 200)
|
||||
|
||||
|
||||
@ -576,16 +559,22 @@ def task_list_my_tasks(page: int = 1, per_page: int = 100) -> flask.wrappers.Res
|
||||
return make_response(jsonify(response_json), 200)
|
||||
|
||||
|
||||
def process_instance_task_list(process_instance_id: int) -> flask.wrappers.Response:
|
||||
def process_instance_task_list(process_instance_id: int, all_tasks: bool = False) -> flask.wrappers.Response:
|
||||
"""Process_instance_task_list."""
|
||||
process_instance = find_process_instance_by_id_or_raise(process_instance_id)
|
||||
processor = ProcessInstanceProcessor(process_instance)
|
||||
all_spiff_user_tasks = processor.get_all_user_tasks()
|
||||
|
||||
tasks = [
|
||||
ProcessInstanceService.spiff_task_to_api_task(spiff_task)
|
||||
for spiff_task in all_spiff_user_tasks
|
||||
]
|
||||
spiff_tasks = None
|
||||
if all_tasks:
|
||||
spiff_tasks = processor.bpmn_process_instance.get_tasks(TaskState.ANY_MASK)
|
||||
else:
|
||||
spiff_tasks = processor.get_all_user_tasks()
|
||||
|
||||
tasks = []
|
||||
for spiff_task in spiff_tasks:
|
||||
task = ProcessInstanceService.spiff_task_to_api_task(spiff_task)
|
||||
task.data = spiff_task.data
|
||||
tasks.append(task)
|
||||
|
||||
return make_response(jsonify(tasks), 200)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user