Move some of the work in `crc.api.workflow.delete_workflow_specification` to separate workflow_service methods

Added a session.commit to `delete_workflow_spec_task_events`
This commit is contained in:
mike cullerton 2021-12-13 11:04:28 -05:00
parent 23fa28bc23
commit daebf42a30
2 changed files with 25 additions and 10 deletions

View File

@ -147,19 +147,18 @@ def delete_workflow_specification(spec_id):
if spec is None:
raise ApiError('unknown_spec', 'The Workflow Specification "' + spec_id + '" is not recognized.')
# Delete all items in the database related to the deleted workflow spec.
files = session.query(FileModel).filter_by(workflow_spec_id=spec_id).all()
for file in files:
FileService.delete_file(file.id)
# Delete all files related to this specification
WorkflowService.delete_workflow_spec_files(spec_id)
session.query(TaskEventModel).filter(TaskEventModel.workflow_spec_id == spec_id).delete()
# Delete all events related to this specification
WorkflowService.delete_workflow_spec_task_events(spec_id)
# Delete all workflow models related to this specification
WorkflowService.delete_workflow_spec_workflow_models(spec_id)
# Delete all events and workflow models related to this specification
for workflow in session.query(WorkflowModel).filter_by(workflow_spec_id=spec_id):
StudyService.delete_workflow(workflow.id)
# .delete() doesn't work when we need a cascade. Must grab the record, and explicitly delete
deleteSpec = session.query(WorkflowSpecModel).filter_by(id=spec_id).first()
session.delete(deleteSpec)
workflow_spec = session.query(WorkflowSpecModel).filter_by(id=spec_id).first()
session.delete(workflow_spec)
session.commit()
# Reorder the remaining specs

View File

@ -1101,3 +1101,19 @@ class WorkflowService(object):
session.add(category)
new_order += 1
session.commit()
@staticmethod
def delete_workflow_spec_files(spec_id):
files = session.query(FileModel).filter_by(workflow_spec_id=spec_id).all()
for file in files:
FileService.delete_file(file.id)
@staticmethod
def delete_workflow_spec_task_events(spec_id):
session.query(TaskEventModel).filter(TaskEventModel.workflow_spec_id == spec_id).delete()
session.commit()
@staticmethod
def delete_workflow_spec_workflow_models(spec_id):
for workflow in session.query(WorkflowModel).filter_by(workflow_spec_id=spec_id):
StudyService.delete_workflow(workflow.id)