Adds endpoint to retrieve all user tasks for a workflow, regardless of state

This commit is contained in:
Aaron Louie 2020-01-31 12:40:08 -05:00
parent 8d39a96606
commit e4b2a7a641
4 changed files with 49 additions and 4 deletions

View File

@ -465,10 +465,39 @@ paths:
responses: responses:
'204': '204':
description: The workflow was removed description: The workflow was removed
/workflow/{workflow_id}/all_tasks:
get:
operationId: crc.api.workflow.get_all_tasks
summary: Return a list of all tasks for this workflow
tags:
- Workflows and Tasks
parameters:
- name: workflow_id
in: path
required: true
description: The id of the workflow
schema:
type: integer
format: int32
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/Task"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
/workflow/{workflow_id}/tasks: /workflow/{workflow_id}/tasks:
get: get:
operationId: crc.api.workflow.get_tasks operationId: crc.api.workflow.get_ready_user_tasks
summary: Return a list of all tasks for this workflow summary: Returns the list of ready user tasks for this workflow
tags: tags:
- Workflows and Tasks - Workflows and Tasks
parameters: parameters:

View File

@ -76,7 +76,18 @@ def delete(workflow_id):
session.commit() session.commit()
3 3
def get_tasks(workflow_id):
def get_all_tasks(workflow_id):
workflow = session.query(WorkflowModel).filter_by(id=workflow_id).first()
processor = WorkflowProcessor(workflow.workflow_spec_id, workflow.bpmn_workflow_json)
spiff_tasks = processor.get_all_user_tasks()
tasks = []
for st in spiff_tasks:
tasks.append(Task.from_spiff(st))
return TaskSchema(many=True).dump(tasks)
def get_ready_user_tasks(workflow_id):
workflow = session.query(WorkflowModel).filter_by(id=workflow_id).first() workflow = session.query(WorkflowModel).filter_by(id=workflow_id).first()
processor = WorkflowProcessor(workflow.workflow_spec_id, workflow.bpmn_workflow_json) processor = WorkflowProcessor(workflow.workflow_spec_id, workflow.bpmn_workflow_json)
spiff_tasks = processor.get_ready_user_tasks() spiff_tasks = processor.get_ready_user_tasks()

View File

@ -60,8 +60,8 @@ class Task:
instance = cls(spiff_task.id, instance = cls(spiff_task.id,
spiff_task.task_spec.name, spiff_task.task_spec.name,
spiff_task.task_spec.description, spiff_task.task_spec.description,
spiff_task.get_state_name(),
"task", "task",
spiff_task.get_state_name(),
{}, {},
spiff_task.task_spec.documentation) spiff_task.task_spec.documentation)
if hasattr(spiff_task.task_spec, "form"): if hasattr(spiff_task.task_spec, "form"):

View File

@ -1,5 +1,6 @@
import xml.etree.ElementTree as ElementTree import xml.etree.ElementTree as ElementTree
from SpiffWorkflow import Task as SpiffTask
from SpiffWorkflow.bpmn.BpmnScriptEngine import BpmnScriptEngine from SpiffWorkflow.bpmn.BpmnScriptEngine import BpmnScriptEngine
from SpiffWorkflow.bpmn.parser.task_parsers import UserTaskParser from SpiffWorkflow.bpmn.parser.task_parsers import UserTaskParser
from SpiffWorkflow.bpmn.parser.util import full_tag from SpiffWorkflow.bpmn.parser.util import full_tag
@ -111,6 +112,10 @@ class WorkflowProcessor:
def get_ready_user_tasks(self): def get_ready_user_tasks(self):
return self.bpmn_workflow.get_ready_user_tasks() return self.bpmn_workflow.get_ready_user_tasks()
def get_all_user_tasks(self):
all_tasks = self.bpmn_workflow.get_tasks(SpiffTask.ANY_MASK)
return [t for t in all_tasks if not self.bpmn_workflow._is_engine_task(t.task_spec)]
@staticmethod @staticmethod
def __get_process_id(et_root: ElementTree.Element): def __get_process_id(et_root: ElementTree.Element):
process_elements = [] process_elements = []