Adds endpoint to retrieve all user tasks for a workflow, regardless of state
This commit is contained in:
parent
8d39a96606
commit
e4b2a7a641
33
crc/api.yml
33
crc/api.yml
|
@ -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:
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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"):
|
||||||
|
|
|
@ -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 = []
|
||||||
|
|
Loading…
Reference in New Issue