Beispiel #1
0
def update_tr(session: SQLAlchemySession,
              transformation_revision: TransformationRevision) -> None:
    try:
        db_model = transformation_revision.to_orm_model()
        session.execute(
            update(TransformationRevisionDBModel).where(
                TransformationRevisionDBModel.id == db_model.id).values(
                    revision_group_id=db_model.revision_group_id,
                    name=db_model.name,
                    description=db_model.description,
                    category=db_model.category,
                    version_tag=db_model.version_tag,
                    state=db_model.state,
                    type=db_model.type,
                    documentation=db_model.documentation,
                    workflow_content=db_model.workflow_content,
                    component_code=db_model.component_code,
                    io_interface=db_model.io_interface,
                    test_wiring=db_model.test_wiring,
                    released_timestamp=db_model.released_timestamp,
                    disabled_timestamp=db_model.disabled_timestamp,
                ))

    except IntegrityError as e:
        msg = (
            f"Integrity Error while trying to update "
            f"transformation revision with id {transformation_revision.id}.\n"
            f"Error was:\n{str(e)}")
        logger.error(msg)
        raise DBIntegrityError(msg) from e
Beispiel #2
0
def add_tr(session: SQLAlchemySession,
           transformation_revision: TransformationRevision) -> None:
    try:
        db_model = transformation_revision.to_orm_model()
        session.add(db_model)
    except IntegrityError as e:
        msg = (
            f"Integrity Error while trying to store transformation revision "
            f"with id {transformation_revision.id}. Error was:\n{str(e)}")
        logger.error(msg)
        raise DBIntegrityError(msg) from e
Beispiel #3
0
def delete_single_nesting(
    session: SQLAlchemySession,
    workflow_id: UUID,
    via_operator_id: UUID,
    nested_operator_id: UUID,
) -> None:
    session.execute(
        delete(NestingDBModel).where(
            and_(
                NestingDBModel.workflow_id == workflow_id,
                NestingDBModel.via_operator_id == via_operator_id,
                NestingDBModel.nested_operator_id == nested_operator_id,
            )))
Beispiel #4
0
def add_single_nesting(session: SQLAlchemySession,
                       nesting: NestingDBModel) -> None:
    logger.debug(
        "add nesting of transformation revision %s in workflow %s",
        str(nesting.nested_transformation_id),
        str(nesting.workflow_id),
    )
    try:
        session.merge(nesting)
    except IntegrityError as e:
        msg = (f"Integrity Error while trying to store nesting for"
               f" transformation revision with id {nesting.workflow_id}."
               f" Error was:\n{str(e)}")
        logger.error(msg)
        raise DBIntegrityError(msg) from e
Beispiel #5
0
def find_all_nesting_transformation_revisions(
        session: SQLAlchemySession,
        nested_transformation_id: UUID) -> List[NestingDBModel]:
    result = session.execute(
        select(NestingDBModel).where(NestingDBModel.nested_transformation_id ==
                                     nested_transformation_id))

    return [row[0] for row in result.all()]
Beispiel #6
0
def select_tr_by_id(session: SQLAlchemySession,
                    id: UUID,
                    log_error: bool = True) -> TransformationRevision:

    result = session.execute(
        select(TransformationRevisionDBModel).where(
            TransformationRevisionDBModel.id == id)).scalar_one_or_none()

    if result is None:
        msg = f"Found no transformation revision in database with id {id}"
        if log_error:
            logger.error(msg)
        raise DBNotFoundError(msg)

    return TransformationRevision.from_orm_model(result)
Beispiel #7
0
def find_all_nested_transformation_revisions(
        session: SQLAlchemySession, workflow_id: UUID) -> List[Descendant]:
    result = session.execute(
        select(
            NestingDBModel.depth,
            NestingDBModel.nested_transformation_id,
            NestingDBModel.nested_operator_id,
        ).where(NestingDBModel.workflow_id == workflow_id))

    descendants = [
        Descendant(row.depth, row.nested_transformation_id,
                   row.nested_operator_id) for row in result.all()
    ]

    for descendant in descendants:
        logger.debug(
            "transformation revision %s is descendant of workflow %s",
            str(descendant.transformation_id),
            str(workflow_id),
        )

    return descendants
Beispiel #8
0
def delete_own_nestings(session: SQLAlchemySession, workflow_id: UUID) -> None:
    logger.debug("delete own nestings of workflow %s", str(workflow_id))
    session.execute(
        delete(NestingDBModel).where(
            NestingDBModel.workflow_id == workflow_id))