Deleting all dependencies for a workflow

This commit is contained in:
Carlos Lopez 2020-08-10 07:42:56 -06:00
parent bf3dae1885
commit d3462d2e15
1 changed files with 22 additions and 5 deletions

View File

@ -9,13 +9,14 @@ from ldap3.core.exceptions import LDAPSocketOpenError
from crc import db, session, app from crc import db, session, app
from crc.api.common import ApiError from crc.api.common import ApiError
from crc.models.file import FileModel, FileModelSchema, File from crc.models.approval import ApprovalFile, ApprovalModel
from crc.models.file import FileDataModel, FileModel, FileModelSchema, File, LookupFileModel, LookupDataModel
from crc.models.ldap import LdapSchema from crc.models.ldap import LdapSchema
from crc.models.protocol_builder import ProtocolBuilderStudy, ProtocolBuilderStatus from crc.models.protocol_builder import ProtocolBuilderStudy, ProtocolBuilderStatus
from crc.models.study import StudyModel, Study, StudyStatus, Category, WorkflowMetadata from crc.models.study import StudyModel, Study, StudyStatus, Category, WorkflowMetadata
from crc.models.task_event import TaskEventModel, TaskEvent from crc.models.task_event import TaskEventModel, TaskEvent
from crc.models.workflow import WorkflowSpecCategoryModel, WorkflowModel, WorkflowSpecModel, WorkflowState, \ from crc.models.workflow import WorkflowSpecCategoryModel, WorkflowModel, WorkflowSpecModel, WorkflowState, \
WorkflowStatus WorkflowStatus, WorkflowSpecDependencyFile
from crc.services.approval_service import ApprovalService from crc.services.approval_service import ApprovalService
from crc.services.file_service import FileService from crc.services.file_service import FileService
from crc.services.ldap_service import LdapService from crc.services.ldap_service import LdapService
@ -83,13 +84,29 @@ class StudyService(object):
session.commit() session.commit()
@staticmethod @staticmethod
def delete_workflow(workflow): def delete_workflow(workflow_id):
for file in session.query(FileModel).filter_by(workflow_id=workflow.id).all(): workflow = session.query(WorkflowModel).get(workflow_id)
for file in session.query(FileModel).filter_by(workflow_id=workflow_id).all():
FileService.delete_file(file.id) FileService.delete_file(file.id)
for dep in workflow.dependencies: for dep in workflow.dependencies:
session.delete(dep) session.delete(dep)
session.query(TaskEventModel).filter_by(workflow_id=workflow.id).delete() session.query(TaskEventModel).filter_by(workflow_id=workflow.id).delete()
session.query(WorkflowModel).filter_by(id=workflow.id).delete() session.query(ApprovalFile).filter(ApprovalModel.workflow_id==workflow_id).delete(synchronize_session='fetch')
session.query(ApprovalModel).filter_by(workflow_id=workflow.id).delete()
session.query(LookupDataModel).filter(
LookupFileModel.workflow_spec_id==workflow.workflow_spec_id
).delete(synchronize_session='fetch')
session.query(LookupFileModel).filter_by(workflow_spec_id=workflow.workflow_spec_id).delete()
session.query(WorkflowSpecDependencyFile).filter(
FileDataModel.file_model_id==FileModel.id,
FileModel.workflow_id==workflow_id
).delete(synchronize_session='fetch')
session.query(FileDataModel).filter(FileModel.workflow_id==workflow_id).delete(synchronize_session='fetch')
session.query(FileModel).filter_by(workflow_id=workflow_id).delete()
session.delete(workflow)
session.commit() session.commit()
@staticmethod @staticmethod