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