added all_tasks option to process-instance/tasks endpoint and cleaned process instance show endpoint

This commit is contained in:
jasquat 2022-07-25 16:46:10 -04:00
parent b0a87d12d5
commit 772e5352ff
3 changed files with 19 additions and 33 deletions

View File

@ -679,6 +679,12 @@ paths:
description: The unique id of an existing process instance. description: The unique id of an existing process instance.
schema: schema:
type: integer 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: get:
operationId: spiffworkflow_backend.routes.process_api_blueprint.process_instance_task_list operationId: spiffworkflow_backend.routes.process_api_blueprint.process_instance_task_list
summary: returns the list of all user tasks associated with process instance summary: returns the list of all user tasks associated with process instance

View File

@ -99,10 +99,7 @@ class ProcessInstanceModel(SpiffworkflowBaseDBModel):
created_at_in_seconds: int = db.Column(db.Integer) created_at_in_seconds: int = db.Column(db.Integer)
status: str = db.Column(db.String(50)) 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 bpmn_xml_file_contents: bytes | None = None
spiffworkflow_active_task_id: str | None = None
@property @property
def serialized(self) -> dict[str, Any]: def serialized(self) -> dict[str, Any]:
@ -116,14 +113,10 @@ class ProcessInstanceModel(SpiffworkflowBaseDBModel):
"process_model_identifier": self.process_model_identifier, "process_model_identifier": self.process_model_identifier,
"process_group_identifier": self.process_group_identifier, "process_group_identifier": self.process_group_identifier,
"status": self.status, "status": self.status,
"bpmn_json": self.bpmn_json,
"start_in_seconds": self.start_in_seconds, "start_in_seconds": self.start_in_seconds,
"end_in_seconds": self.end_in_seconds, "end_in_seconds": self.end_in_seconds,
"process_initiator_id": self.process_initiator_id, "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, "bpmn_xml_file_contents": local_bpmn_xml_file_contents,
"spiffworkflow_active_task_id": self.spiffworkflow_active_task_id,
} }
@property @property
@ -149,8 +142,6 @@ class ProcessInstanceModelSchema(Schema):
"process_model_identifier", "process_model_identifier",
"process_group_identifier", "process_group_identifier",
"process_initiator_id", "process_initiator_id",
# "process_initiator",
"bpmn_json",
"start_in_seconds", "start_in_seconds",
"end_in_seconds", "end_in_seconds",
"updated_at_in_seconds", "updated_at_in_seconds",

View File

@ -388,35 +388,18 @@ def process_instance_list(
def process_instance_show( 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: ) -> flask.wrappers.Response:
"""Create_process_instance.""" """Create_process_instance."""
process_instance = find_process_instance_by_id_or_raise(process_instance_id) process_instance = find_process_instance_by_id_or_raise(process_instance_id)
process_model = get_process_model(process_model_id, process_group_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: if process_model.primary_file_name:
bpmn_xml_file_contents = SpecFileService.get_data( bpmn_xml_file_contents = SpecFileService.get_data(
process_model, process_model.primary_file_name 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 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) 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) 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_task_list."""
process_instance = find_process_instance_by_id_or_raise(process_instance_id) process_instance = find_process_instance_by_id_or_raise(process_instance_id)
processor = ProcessInstanceProcessor(process_instance) processor = ProcessInstanceProcessor(process_instance)
all_spiff_user_tasks = processor.get_all_user_tasks()
tasks = [ spiff_tasks = None
ProcessInstanceService.spiff_task_to_api_task(spiff_task) if all_tasks:
for spiff_task in all_spiff_user_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) return make_response(jsonify(tasks), 200)