This commit is contained in:
Dan Funk 2020-01-07 13:23:46 -05:00
parent 872f3fca1b
commit a3d7ba8114
3 changed files with 32 additions and 31 deletions

View File

@ -408,12 +408,7 @@ paths:
schema: schema:
$ref: "#/components/schemas/Error" $ref: "#/components/schemas/Error"
# /v1.0/workflow/0/task/0 # /v1.0/workflow/0/task/0
/workflow/{workflow_id}/task/{task_id}: /workflow/{workflow_id}/task/{task_name}:
get:
operationId: crc.api.workflow.get_task
summary: Get details of specific task in specific workflow instance
tags:
- Workflows and Tasks
parameters: parameters:
- name: workflow_id - name: workflow_id
in: path in: path
@ -422,12 +417,17 @@ paths:
schema: schema:
type: integer type: integer
format: int32 format: int32
- name: task_id - name: task_name
in: path in: path
required: true required: true
description: The id of the task description: The id of the task
schema: schema:
type: string type: string
get:
operationId: crc.api.workflow.get_task
summary: Get details of specific task in specific workflow instance
tags:
- Workflows and Tasks
responses: responses:
'200': '200':
description: Expected response to a valid request description: Expected response to a valid request
@ -452,19 +452,6 @@ paths:
name: task name: task
schema: schema:
$ref: '#/components/schemas/Task' $ref: '#/components/schemas/Task'
- name: workflow_id
in: path
required: true
description: The id of the workflow
schema:
type: integer
format: int32
- name: task_id
in: path
required: true
description: The id of the task
schema:
type: string
responses: responses:
'201': '201':
description: Null response description: Null response

View File

@ -35,9 +35,10 @@ def get_task(workflow_id, task_id):
return workflow.bpmn_workflow().get_task(task_id) return workflow.bpmn_workflow().get_task(task_id)
def update_task(workflow_id, task_id, body): def update_task(workflow_id, task_name, body):
workflow = db.session.query(WorkflowModel).filter_by(id=workflow_id).first() workflow = db.session.query(WorkflowModel).filter_by(id=workflow_id).first()
task = workflow.bpmn_workflow().get_task(task_id) processor = WorkflowProcessor(workflow.workflow_spec_id, workflow.bpmn_workflow_json)
task = processor.bpmn_workflow.get_tasks_from_spec_name(task_name)[0]
if workflow and task and body: if workflow and task and body:
print('workflow', workflow.id) print('workflow', workflow.id)
print('task', task.id) print('task', task.id)

View File

@ -133,6 +133,7 @@ class TestStudy(BaseTest, unittest.TestCase):
self.assertEqual(3, len(tasks[0].form["fields"][0]["options"])) self.assertEqual(3, len(tasks[0].form["fields"][0]["options"]))
def test_two_forms_task(self): def test_two_forms_task(self):
# Set up a new workfllow
self.load_example_data() self.load_example_data()
study = db.session.query(StudyModel).first() study = db.session.query(StudyModel).first()
spec = db.session.query(WorkflowSpecModel).filter_by(id='two_forms').first() spec = db.session.query(WorkflowSpecModel).filter_by(id='two_forms').first()
@ -141,13 +142,25 @@ class TestStudy(BaseTest, unittest.TestCase):
json_data = json.loads(rv.get_data(as_text=True)) json_data = json.loads(rv.get_data(as_text=True))
workflow = WorkflowModelSchema().load(json_data, session=db.session) workflow = WorkflowModelSchema().load(json_data, session=db.session)
# get the first from in the two form workflow.
rv = self.app.get('/v1.0/workflow/%i/tasks' % workflow.id, content_type="application/json") rv = self.app.get('/v1.0/workflow/%i/tasks' % workflow.id, content_type="application/json")
json_data = json.loads(rv.get_data(as_text=True)) json_data = json.loads(rv.get_data(as_text=True))
tasks = TaskSchema(many=True).load(json_data) tasks = TaskSchema(many=True).load(json_data)
self.assertEqual(1, len(tasks)) self.assertEqual(1, len(tasks))
self.assertIsNotNone(tasks[0].form) self.assertIsNotNone(tasks[0].form)
self.assertEqual("StepOne", tasks[0].name)
self.assertEqual(1, len(tasks[0].form['fields'])) self.assertEqual(1, len(tasks[0].form['fields']))
# Complete the form for Step one and post it.
tasks[0].form['fields'][0]['value']="Blue" tasks[0].form['fields'][0]['value']="Blue"
rv = self.app.put('/v1.0/workflow/%i/task/%s' % (workflow.id, tasks[0].id), content_type="application/json", rv = self.app.put('/v1.0/workflow/%i/task/%s' % (workflow.id, tasks[0].name), content_type="application/json",
data=json.dumps(TaskSchema().dump(tasks[0]))) data=json.dumps(TaskSchema().dump(tasks[0])))
self.assert_success(rv) self.assert_success(rv)
# Get the next Task
rv = self.app.get('/v1.0/workflow/%i/tasks' % study.id, content_type="application/json")
self.assert_success(rv)
json_data = json.loads(rv.get_data(as_text=True))
tasks = TaskSchema(many=True).load(json_data)
self.assertEqual("StepTwo", tasks[0].name)
self.assertEqual(3, len(tasks[0].form["fields"][0]["options"]))