Added workflow_spec_id to WorkflowMetadata model, because the id is the workflow id, not the workflow_spec id.

Then, we use workflow_spec_id in StudyService when looking for workflow status.
This commit is contained in:
mike cullerton 2021-10-07 10:02:13 -04:00
parent c36a76a8bc
commit 10abf51f70
2 changed files with 15 additions and 13 deletions

View File

@ -107,7 +107,7 @@ class WorkflowMetadata(object):
def __init__(self, id, display_name = None, description = None, spec_version = None,
category_id = None, category_display_name = None, state: WorkflowState = None,
status: WorkflowStatus = None, total_tasks = None, completed_tasks = None,
is_review=None,display_order = None, state_message = None):
is_review=None,display_order = None, state_message = None, workflow_spec_id=None):
self.id = id
self.display_name = display_name
self.description = description
@ -121,6 +121,7 @@ class WorkflowMetadata(object):
self.completed_tasks = completed_tasks
self.is_review = is_review
self.display_order = display_order
self.workflow_spec_id = workflow_spec_id
@classmethod
@ -138,7 +139,8 @@ class WorkflowMetadata(object):
total_tasks=workflow.total_tasks,
completed_tasks=workflow.completed_tasks,
is_review=is_review,
display_order=workflow.workflow_spec.display_order
display_order=workflow.workflow_spec.display_order,
workflow_spec_id=workflow.workflow_spec_id
)
return instance

View File

@ -433,26 +433,26 @@ class StudyService(object):
for wfm in workflow_metas:
wfm.state_message = ''
# do we have a status for you
if wfm.id not in status.keys():
warnings.append(ApiError("missing_status", "No status specified for workflow %s" % wfm.id))
if wfm.workflow_spec_id not in status.keys():
warnings.append(ApiError("missing_status", "No status specified for workflow %s" % wfm.workflow_spec_id))
continue
if not isinstance(status[wfm.id], dict):
if not isinstance(status[wfm.workflow_spec_id], dict):
warnings.append(ApiError(code='invalid_status',
message=f'Status must be a dictionary with "status" and "message" keys. Name is {wfm.id}. Status is {status[wfm.id]}'))
message=f'Status must be a dictionary with "status" and "message" keys. Name is {wfm.workflow_spec_id}. Status is {status[wfm.workflow_spec_id]}'))
continue
if 'status' not in status[wfm.id].keys():
if 'status' not in status[wfm.workflow_spec_id].keys():
warnings.append(ApiError("missing_status",
"Workflow '%s' does not have a status setting" % wfm.id))
"Workflow '%s' does not have a status setting" % wfm.workflow_spec_id))
continue
if not WorkflowState.has_value(status[wfm.id]['status']):
if not WorkflowState.has_value(status[wfm.workflow_spec_id]['status']):
warnings.append(ApiError("invalid_state",
"Workflow '%s' can not be set to '%s', should be one of %s" % (
wfm.id, status[wfm.id]['status'], ",".join(WorkflowState.list())
wfm.workflow_spec_id, status[wfm.workflow_spec_id]['status'], ",".join(WorkflowState.list())
)))
continue
wfm.state = WorkflowState[status[wfm.id]['status']]
if 'message' in status[wfm.id].keys():
wfm.state_message = status[wfm.id]['message']
wfm.state = WorkflowState[status[wfm.workflow_spec_id]['status']]
if 'message' in status[wfm.workflow_spec_id].keys():
wfm.state_message = status[wfm.workflow_spec_id]['message']
return warnings
@staticmethod