updated method calls in workflow.py

except for reordering
This commit is contained in:
alicia pritchett 2022-02-04 15:31:36 -05:00
parent 2383c7d76d
commit 699d0ab797
2 changed files with 35 additions and 78 deletions

View File

@ -10,6 +10,7 @@ from crc.models.study import StudyModel, WorkflowMetadata, StudyStatus
from crc.models.task_event import TaskEventModel, TaskEvent, TaskEventSchema from crc.models.task_event import TaskEventModel, TaskEvent, TaskEventSchema
from crc.models.task_log import TaskLogModelSchema, TaskLogQuery, TaskLogQuerySchema from crc.models.task_log import TaskLogModelSchema, TaskLogQuery, TaskLogQuerySchema
from crc.models.workflow import WorkflowModel from crc.models.workflow import WorkflowModel
from crc.services import workflow_spec_service
from crc.services.error_service import ValidationErrorService from crc.services.error_service import ValidationErrorService
from crc.services.lookup_service import LookupService from crc.services.lookup_service import LookupService
from crc.services.spec_file_service import SpecFileService from crc.services.spec_file_service import SpecFileService
@ -42,36 +43,30 @@ def all_specifications(libraries=False,standalone=False):
def add_workflow_specification(body): def add_workflow_specification(body):
# TODO: change the category identifier to display_name category_id = body['display_name']
category_id = body['category_id'] # TODO: fix reordering
# TODO: modify this method to call out to filesystem # WorkflowService.cleanup_workflow_spec_display_order(category_id)
WorkflowService.cleanup_workflow_spec_display_order(category_id)
# TODO: why is the display_order coming from the body? alicia does not know # TODO: why is the display_order coming from the body? alicia does not know
count = session.query(WorkflowSpecModel).filter_by(category_id=category_id).count() # count = session.query(WorkflowSpecModel).filter_by(category_id=category_id).count()
body['display_order'] = count #body['display_order'] = count
# Libraries and standalone workflows don't get a category_id # Libraries and standalone workflows don't get a category_id
if body['library'] is True or body['standalone'] is True: if body['library'] is True or body['standalone'] is True:
body['category_id'] = None body['category_id'] = None
# TODO: modify this to workflow_spec_service.add_spec(body);
new_spec: WorkflowSpecModel = WorkflowSpecModelSchema().load(body, session=session) new_spec = workflow_spec_service.add_spec(body)
session.add(new_spec) return new_spec
session.commit()
return WorkflowSpecModelSchema().dump(new_spec)
def get_workflow_specification(spec_id): def get_workflow_specification(spec_id):
if spec_id is None: if spec_id is None:
raise ApiError('unknown_spec', 'Please provide a valid Workflow Specification ID.') raise ApiError('unknown_spec', 'Please provide a valid Workflow Specification ID.')
spec = workflow_spec_service.get_spec(spec_id)
# TODO: modify this to workflow_spec_service.get_spec(spec_id);
spec: WorkflowSpecModel = session.query(WorkflowSpecModel).filter_by(id=spec_id).first()
if spec is None: if spec is None:
raise ApiError('unknown_spec', 'The Workflow Specification "' + spec_id + '" is not recognized.') raise ApiError('unknown_spec', 'The Workflow Specification "' + spec_id + '" is not recognized.')
# TODO: return a spec return spec
return WorkflowSpecModelSchema().dump(spec)
def validate_spec_and_library(spec_id,library_id): def validate_spec_and_library(spec_id,library_id):
if spec_id is None: if spec_id is None:
@ -79,9 +74,8 @@ def validate_spec_and_library(spec_id,library_id):
if library_id is None: if library_id is None:
raise ApiError('unknown_spec', 'Please provide a valid Library Specification ID.') raise ApiError('unknown_spec', 'Please provide a valid Library Specification ID.')
# TODO: modify this to workflow_spec_service.get_spec(spec_id); spec = workflow_spec_service.get_spec(spec_id)
spec: WorkflowSpecModel = session.query(WorkflowSpecModel).filter_by(id=spec_id).first() library = workflow_spec_service.get_library(library_id);
library: WorkflowSpecModel = session.query(WorkflowSpecModel).filter_by(id=library_id).first()
if spec is None: if spec is None:
raise ApiError('unknown_spec', 'The Workflow Specification "' + spec_id + '" is not recognized.') raise ApiError('unknown_spec', 'The Workflow Specification "' + spec_id + '" is not recognized.')
if library is None: if library is None:
@ -92,28 +86,20 @@ def validate_spec_and_library(spec_id,library_id):
def add_workflow_spec_library(spec_id, library_id): def add_workflow_spec_library(spec_id, library_id):
validate_spec_and_library(spec_id, library_id) validate_spec_and_library(spec_id, library_id)
# TODO: modify to get_libraries() libraries: workflow_spec_service.get_libraries()
libraries: WorkflowLibraryModel = session.query(WorkflowLibraryModel).filter_by(workflow_spec_id=spec_id).all()
libraryids = [x.library_spec_id for x in libraries] libraryids = [x.library_spec_id for x in libraries]
if library_id in libraryids: if library_id in libraryids:
raise ApiError('unknown_spec', 'The Library Specification "' + spec_id + '" is already attached.') raise ApiError('unknown_spec', 'The Library Specification "' + spec_id + '" is already attached.')
# TODO: modify this to add_library(newlib) # TODO: this used to return all libraries. maybe we still want that here
newlib = WorkflowLibraryModel() newlib = workflow_spec_service.add_library(spec_id, library_id)
newlib.workflow_spec_id = spec_id return newlib
newlib.library_spec_id = library_id
session.add(newlib)
session.commit()
libraries: WorkflowLibraryModel = session.query(WorkflowLibraryModel).filter_by(workflow_spec_id=spec_id).all()
return WorkflowLibraryModelSchema(many=True).dump(libraries)
def drop_workflow_spec_library(spec_id,library_id): def drop_workflow_spec_library(spec_id,library_id):
# TODO: modify this to delete_library(newlib)
validate_spec_and_library(spec_id, library_id) validate_spec_and_library(spec_id, library_id)
session.query(WorkflowLibraryModel).filter_by(workflow_spec_id=spec_id,library_spec_id=library_id).delete() workflow_spec_service.delete_library(library_id)
session.commit() # TODO: this used to return all libraries. maybe we still want that here
libraries: WorkflowLibraryModel = session.query(WorkflowLibraryModel).filter_by(workflow_spec_id=spec_id).all() return workflow_spec_service.get_libraries()
return WorkflowLibraryModelSchema(many=True).dump(libraries)
def validate_workflow_specification(spec_id, study_id=None, test_until=None): def validate_workflow_specification(spec_id, study_id=None, test_until=None):
@ -131,9 +117,7 @@ def validate_workflow_specification(spec_id, study_id=None, test_until=None):
def update_workflow_specification(spec_id, body): def update_workflow_specification(spec_id, body):
if spec_id is None: if spec_id is None:
raise ApiError('unknown_spec', 'Please provide a valid Workflow Spec ID.') raise ApiError('unknown_spec', 'Please provide a valid Workflow Spec ID.')
spec = workflow_spec_service.get_spec(spec_id)
# TODO: replace this with a call to get_workflow_spec(spec_id);
spec = session.query(WorkflowSpecModel).filter_by(id=spec_id).first()
if spec is None: if spec is None:
raise ApiError('unknown_study', 'The spec "' + spec_id + '" is not recognized.') raise ApiError('unknown_study', 'The spec "' + spec_id + '" is not recognized.')
@ -146,20 +130,15 @@ def update_workflow_specification(spec_id, body):
if body['library'] is True or body['standalone'] is True: if body['library'] is True or body['standalone'] is True:
body['category_id'] = None body['category_id'] = None
# TODO: modify this to workflow_spec_service.update_spec(spec_id, body); spec = workflow_spec_service.update_spec(spec_id, body)
schema = WorkflowSpecModelSchema() return spec
spec = schema.load(body, session=session, instance=spec, partial=True)
session.add(spec)
session.commit()
return schema.dump(spec)
def delete_workflow_specification(spec_id): def delete_workflow_specification(spec_id):
if spec_id is None: if spec_id is None:
raise ApiError('unknown_spec', 'Please provide a valid Workflow Specification ID.') raise ApiError('unknown_spec', 'Please provide a valid Workflow Specification ID.')
# TODO: replace this with a call to get_workflow_spec(spec_id); spec = workflow_spec_service.get_spec(spec_id)
spec: WorkflowSpecModel = session.query(WorkflowSpecModel).filter_by(id=spec_id).first()
# TODO: replace this with category display name # TODO: replace this with category display name
category_id = spec.category_id category_id = spec.category_id
@ -353,35 +332,22 @@ def __update_task(processor, task, data, user):
def list_workflow_spec_categories(): def list_workflow_spec_categories():
# TODO: modify this to get_workflow_categories() return workflow_spec_service.get_workflow_categories()
schema = WorkflowSpecCategoryModelSchema(many=True)
return schema.dump(session.query(WorkflowSpecCategoryModel).order_by(WorkflowSpecCategoryModel.display_order).all())
def get_workflow_spec_category(cat_id): def get_workflow_spec_category(cat_id):
# TODO: modify this to get_workflow_category(category) return workflow_spec_service.get_workflow_category(cat_id)
schema = WorkflowSpecCategoryModelSchema()
return schema.dump(session.query(WorkflowSpecCategoryModel).filter_by(id=cat_id).first())
def add_workflow_spec_category(body): def add_workflow_spec_category(body):
# TODO: modify this to add_workflow_category(body) return workflow_spec_service.add_category(body)
WorkflowService.cleanup_workflow_spec_category_display_order()
count = session.query(WorkflowSpecCategoryModel).count()
body['display_order'] = count
schema = WorkflowSpecCategoryModelSchema()
new_cat: WorkflowSpecCategoryModel = schema.load(body, session=session)
session.add(new_cat)
session.commit()
return schema.dump(new_cat)
def update_workflow_spec_category(cat_id, body): def update_workflow_spec_category(cat_id, body):
if cat_id is None: if cat_id is None:
raise ApiError('unknown_category', 'Please provide a valid Workflow Spec Category ID.') raise ApiError('unknown_category', 'Please provide a valid Workflow Spec Category ID.')
# TODO: modify this to update_workflow_category(cat_id, body) category = workflow_spec_service.update_category(cat_id, body)
category = session.query(WorkflowSpecCategoryModel).filter_by(id=cat_id).first()
if category is None: if category is None:
raise ApiError('unknown_category', 'The category "' + cat_id + '" is not recognized.') raise ApiError('unknown_category', 'The category "' + cat_id + '" is not recognized.')
@ -390,20 +356,11 @@ def update_workflow_spec_category(cat_id, body):
# There is a separate endpoint for that # There is a separate endpoint for that
body['display_order'] = category.display_order body['display_order'] = category.display_order
schema = WorkflowSpecCategoryModelSchema() return category
category = schema.load(body, session=session, instance=category, partial=True)
session.add(category)
session.commit()
return schema.dump(category)
def delete_workflow_spec_category(cat_id): def delete_workflow_spec_category(cat_id):
# TODO: modify this to delete_workflow_category(category) workflow_spec_service.delete_category(cat_id)
session.query(WorkflowSpecCategoryModel).filter_by(id=cat_id).delete()
session.commit()
# Reorder the remaining categories
WorkflowService.cleanup_workflow_spec_category_display_order()
def reorder_workflow_spec_category(cat_id, direction): def reorder_workflow_spec_category(cat_id, direction):
# TODO: fix reordering here too # TODO: fix reordering here too

View File

@ -186,16 +186,16 @@ class WorkflowSpecService(FileSystemService):
return process_elements[0].attrib['id'] return process_elements[0].attrib['id']
# TODO Methods i would add... # TODO Methods i would add...
# delete_workflow_spec(spec_id) # delete_spec(spec_id)
# get_workflow_spec(spec_id) # get_spec(spec_id)
# update_spec(spec_id, body) # update_spec(spec_id, body)
# add_spec(body) # add_spec(body)
# Other methods i would add, maybe not here.. # Other methods i would add, maybe not here..
# add_library(body) # add_library(body)
# get_libraries() # get_libraries()
# get_library(library) # get_library(spec_id, library_id)
# delete_library(library) # delete_library(library_id)
# get_workflow_categories() # get_workflow_categories()
# get_workflow_category(category, body) # get_workflow_category(category, body)