Fixes for backend code after removing `name` column from `workflow_spec` and `workflow_spec_category` tables
This commit is contained in:
parent
fb660182aa
commit
572ca1db6b
|
@ -153,7 +153,7 @@ def create_or_update_local_spec(remote,workflow_spec_id):
|
|||
# Set the category
|
||||
if specdict['category'] is not None:
|
||||
local_category = session.query(WorkflowSpecCategoryModel).\
|
||||
filter(WorkflowSpecCategoryModel.name == specdict['category']['name']).first()
|
||||
filter(WorkflowSpecCategoryModel.id == specdict['category']['id']).first()
|
||||
local_category = WorkflowSpecCategoryModelSchema().load(specdict['category'], session=session,
|
||||
instance=local_category)
|
||||
session.add(local_category)
|
||||
|
|
|
@ -104,12 +104,11 @@ class StudyEvent(db.Model):
|
|||
|
||||
|
||||
class WorkflowMetadata(object):
|
||||
def __init__(self, id, name = None, display_name = None, description = None, spec_version = None,
|
||||
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):
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.display_name = display_name
|
||||
self.description = description
|
||||
self.spec_version = spec_version
|
||||
|
@ -128,8 +127,7 @@ class WorkflowMetadata(object):
|
|||
def from_workflow(cls, workflow: WorkflowModel):
|
||||
is_review = FileService.is_workflow_review(workflow.workflow_spec_id)
|
||||
instance = cls(
|
||||
id=workflow.id,
|
||||
name=workflow.workflow_spec.name,
|
||||
id=workflow.workflow_spec_id,
|
||||
display_name=workflow.workflow_spec.display_name,
|
||||
description=workflow.workflow_spec.description,
|
||||
spec_version=workflow.spec_version(),
|
||||
|
@ -150,7 +148,7 @@ class WorkflowMetadataSchema(ma.Schema):
|
|||
status = EnumField(WorkflowStatus)
|
||||
class Meta:
|
||||
model = WorkflowMetadata
|
||||
additional = ["id", "name", "display_name", "description",
|
||||
additional = ["id", "display_name", "description",
|
||||
"total_tasks", "completed_tasks", "display_order",
|
||||
"category_id", "is_review", "category_display_name", "state_message"]
|
||||
unknown = INCLUDE
|
||||
|
@ -159,7 +157,6 @@ class WorkflowMetadataSchema(ma.Schema):
|
|||
class Category(object):
|
||||
def __init__(self, model: WorkflowSpecCategoryModel):
|
||||
self.id = model.id
|
||||
self.name = model.name
|
||||
self.display_name = model.display_name
|
||||
self.display_order = model.display_order
|
||||
self.admin = model.admin
|
||||
|
@ -169,7 +166,7 @@ class CategorySchema(ma.Schema):
|
|||
workflows = fields.List(fields.Nested(WorkflowMetadataSchema), dump_only=True)
|
||||
class Meta:
|
||||
model = Category
|
||||
additional = ["id", "name", "display_name", "display_order", "admin"]
|
||||
additional = ["id", "display_name", "display_order", "admin"]
|
||||
unknown = INCLUDE
|
||||
|
||||
|
||||
|
|
|
@ -60,11 +60,9 @@ class WorkflowSpecModelSchema(SQLAlchemyAutoSchema):
|
|||
|
||||
category = marshmallow.fields.Nested(WorkflowSpecCategoryModelSchema, dump_only=True)
|
||||
libraries = marshmallow.fields.Function(lambda obj: [{'id':x.library.id,
|
||||
'name':x.library.name,
|
||||
'display_name':x.library.display_name} for x in
|
||||
obj.libraries] )
|
||||
parents = marshmallow.fields.Function(lambda obj: [{'id':x.parent.id,
|
||||
'name':x.parent.name,
|
||||
'display_name':x.parent.display_name} for x in
|
||||
obj.parents] )
|
||||
|
||||
|
|
|
@ -13,13 +13,13 @@ class ResetWorkflow(Script):
|
|||
I.e., a new PI"""
|
||||
|
||||
def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs):
|
||||
return hasattr(kwargs, 'workflow_name')
|
||||
return hasattr(kwargs, 'reset_id')
|
||||
|
||||
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
|
||||
|
||||
if 'workflow_name' in kwargs.keys():
|
||||
workflow_name = kwargs['workflow_name']
|
||||
workflow_spec: WorkflowSpecModel = session.query(WorkflowSpecModel).filter_by(name=workflow_name).first()
|
||||
if 'reset_id' in kwargs.keys():
|
||||
reset_id = kwargs['reset_id']
|
||||
workflow_spec: WorkflowSpecModel = session.query(WorkflowSpecModel).filter_by(id=reset_id).first()
|
||||
if workflow_spec:
|
||||
workflow_model: WorkflowModel = session.query(WorkflowModel).filter_by(
|
||||
workflow_spec_id=workflow_spec.id,
|
||||
|
@ -35,7 +35,7 @@ class ResetWorkflow(Script):
|
|||
else:
|
||||
raise ApiError(code='missing_workflow_spec',
|
||||
message=f'No WorkflowSpecModel returned. \
|
||||
name: {workflow_name}')
|
||||
id: {workflow_id}')
|
||||
else:
|
||||
raise ApiError(code='missing_workflow_name',
|
||||
message='Reset workflow requires a workflow name')
|
||||
raise ApiError(code='missing_workflow_id',
|
||||
message='Reset workflow requires a workflow id')
|
||||
|
|
|
@ -433,26 +433,26 @@ class StudyService(object):
|
|||
for wfm in workflow_metas:
|
||||
wfm.state_message = ''
|
||||
# do we have a status for you
|
||||
if wfm.name not in status.keys():
|
||||
warnings.append(ApiError("missing_status", "No status specified for workflow %s" % wfm.name))
|
||||
if wfm.id not in status.keys():
|
||||
warnings.append(ApiError("missing_status", "No status specified for workflow %s" % wfm.id))
|
||||
continue
|
||||
if not isinstance(status[wfm.name], dict):
|
||||
if not isinstance(status[wfm.id], dict):
|
||||
warnings.append(ApiError(code='invalid_status',
|
||||
message=f'Status must be a dictionary with "status" and "message" keys. Name is {wfm.name}. Status is {status[wfm.name]}'))
|
||||
message=f'Status must be a dictionary with "status" and "message" keys. Name is {wfm.id}. Status is {status[wfm.id]}'))
|
||||
continue
|
||||
if 'status' not in status[wfm.name].keys():
|
||||
if 'status' not in status[wfm.id].keys():
|
||||
warnings.append(ApiError("missing_status",
|
||||
"Workflow '%s' does not have a status setting" % wfm.name))
|
||||
"Workflow '%s' does not have a status setting" % wfm.id))
|
||||
continue
|
||||
if not WorkflowState.has_value(status[wfm.name]['status']):
|
||||
if not WorkflowState.has_value(status[wfm.id]['status']):
|
||||
warnings.append(ApiError("invalid_state",
|
||||
"Workflow '%s' can not be set to '%s', should be one of %s" % (
|
||||
wfm.name, status[wfm.name]['status'], ",".join(WorkflowState.list())
|
||||
wfm.id, status[wfm.id]['status'], ",".join(WorkflowState.list())
|
||||
)))
|
||||
continue
|
||||
wfm.state = WorkflowState[status[wfm.name]['status']]
|
||||
if 'message' in status[wfm.name].keys():
|
||||
wfm.state_message = status[wfm.name]['message']
|
||||
wfm.state = WorkflowState[status[wfm.id]['status']]
|
||||
if 'message' in status[wfm.id].keys():
|
||||
wfm.state_message = status[wfm.id]['message']
|
||||
return warnings
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -115,7 +115,7 @@ class WorkflowService(object):
|
|||
except Exception as e:
|
||||
app.logger.error(f"Error running waiting task for workflow #%i (%s) for study #%i. %s" %
|
||||
(workflow_model.id,
|
||||
workflow_model.workflow_spec.name,
|
||||
workflow_model.workflow_spec.id,
|
||||
workflow_model.study_id,
|
||||
str(e)))
|
||||
|
||||
|
@ -137,8 +137,8 @@ class WorkflowService(object):
|
|||
study_model = session.query(StudyModel).filter(StudyModel.id == validate_study_id).first()
|
||||
spec_model = session.query(WorkflowSpecModel).filter(WorkflowSpecModel.id == spec_id).first()
|
||||
status = StudyService._get_study_status(study_model)
|
||||
if spec_model.name in status and status[spec_model.name]['status'] == 'disabled':
|
||||
raise ApiError(code='disabled_workflow', message=f"This workflow is disabled. {status[spec_model.name]['message']}")
|
||||
if spec_model.id in status and status[spec_model.id]['status'] == 'disabled':
|
||||
raise ApiError(code='disabled_workflow', message=f"This workflow is disabled. {status[spec_model.id]['message']}")
|
||||
workflow_model = WorkflowService.make_test_workflow(spec_id, validate_study_id)
|
||||
try:
|
||||
processor = WorkflowProcessor(workflow_model, validate_only=True)
|
||||
|
@ -149,7 +149,7 @@ class WorkflowService(object):
|
|||
exit_task = processor.bpmn_workflow.do_engine_steps(exit_at=test_until)
|
||||
if (exit_task != None):
|
||||
raise ApiError.from_task("validation_break",
|
||||
f"The validation has been exited early on task '{exit_task.task_spec.name}' and was parented by ",
|
||||
f"The validation has been exited early on task '{exit_task.task_spec.id}' and was parented by ",
|
||||
exit_task.parent)
|
||||
tasks = processor.bpmn_workflow.get_tasks(SpiffTask.READY)
|
||||
for task in tasks:
|
||||
|
|
Loading…
Reference in New Issue