Exemple #1
0
def post_acquisition_framework(uuid=None, id_user=None, id_organism=None):
    """ 
        Post an acquisition framwork from MTD XML
        Params:
            uuid (str): uuid of the acquisition framework
            id_user (int): the id of the user connected via CAS
            id_organism (int): the id of the organism user via CAS
    
    """
    xml_af = None
    xml_af = get_acquisition_framework(uuid)

    if xml_af:
        acquisition_framwork = parse_acquisition_framwork_xml(xml_af)
        actors = acquisition_framwork.pop("actors")
        new_af = TAcquisitionFramework(**acquisition_framwork)
        id_acquisition_framework = TAcquisitionFramework.get_id(uuid)
        # if the CA already exist in the DB
        if id_acquisition_framework:
            # delete cor_af_actor
            new_af.id_acquisition_framework = id_acquisition_framework

            delete_q = CorAcquisitionFrameworkActor.__table__.delete().where(
                CorAcquisitionFrameworkActor.id_acquisition_framework ==
                id_acquisition_framework)
            DB.session.execute(delete_q)
            DB.session.commit()
            create_cor_object_actors(actors, new_af)
            DB.session.merge(new_af)

        # its a new AF
        else:
            create_cor_object_actors(actors, new_af)
            # Add the new CA
            DB.session.add(new_af)
        # try to commit
        try:
            DB.session.commit()
        # TODO catch db error ?
        except SQLAlchemyError as e:
            DB.session.flush()
            DB.session.rollback()
            error_msg = "Error posting an aquisition framework\nTrace:\n{} \n\n ".format(
                e)
            log.error(error_msg)

        return new_af.as_dict()

    return {"message": "Not found"}, 404
Exemple #2
0
def post_acquisition_framework(uuid=None, id_user=None, id_organism=None):
    """ Post an acquisition framwork from MTD XML"""
    xml_af = None
    xml_af = get_acquisition_framework(uuid)


    if xml_af:
        acquisition_framwork = parse_acquisition_framwork_xml(xml_af)
        new_af = TAcquisitionFramework(**acquisition_framwork)
        actor = CorAcquisitionFrameworkActor(
            id_role=id_user,
            id_nomenclature_actor_role=func.ref_nomenclatures.get_id_nomenclature('ROLE_ACTEUR', '1')
        )
        new_af.cor_af_actor.append(actor)
        if id_organism:
            organism = CorAcquisitionFrameworkActor(
                id_organism=id_organism,
                id_nomenclature_actor_role=func.ref_nomenclatures.get_id_nomenclature('ROLE_ACTEUR', '1')
            )
            new_af.cor_af_actor.append(organism)
        # check if exist
        id_acquisition_framework = TAcquisitionFramework.get_id(uuid)
        try:
            if id_acquisition_framework:
                new_af.id_acquisition_framework = id_acquisition_framework[0]
                DB.session.merge(new_af)
            else:
                DB.session.add(new_af)
                DB.session.commit()
        # TODO catch db error ?
        except SQLAlchemyError as e:
            DB.session.rollback()
            error_msg = """
                Error posting an aquisition framework {} \n\n Trace: \n {}
                """.format(uuid, e)
            log.error(error_msg)

        return new_af.as_dict()

    return {'message': 'Not found'}, 404
Exemple #3
0
def post_acquisition_framework(uuid=None, id_user=None, id_organism=None):
    """ 
        Post an acquisition framwork from MTD XML
        Params:
            uuid (str): uuid of the acquisition framework
            id_user (int): the id of the user connected via CAS
            id_organism (int): the id of the organism user via CAS
    
    """
    xml_af = None
    xml_af = get_acquisition_framework(uuid)

    if xml_af:
        acquisition_framwork = parse_acquisition_framwork_xml(xml_af)
        new_af = TAcquisitionFramework(**acquisition_framwork)
        id_acquisition_framework = TAcquisitionFramework.get_id(uuid)
        # if the CA already exist in the DB
        if id_acquisition_framework:
            # check if actor role not already exist for this CA
            actor_role = CorAcquisitionFrameworkActor.get_actor(
                id_acquisition_framework=id_acquisition_framework,
                id_nomenclature_actor_role=func.ref_nomenclatures.
                get_id_nomenclature('ROLE_ACTEUR', '1'),
                id_role=id_user)

            # if no actor push it
            if actor_role is None:
                actor = CorAcquisitionFrameworkActor(
                    id_role=id_user,
                    id_nomenclature_actor_role=func.ref_nomenclatures.
                    get_id_nomenclature('ROLE_ACTEUR', '1'))
                new_af.cor_af_actor.append(actor)

            # # check if actor role not already exist for this CA
            actor_organism = None
            if id_organism:
                actor_organism = CorAcquisitionFrameworkActor.get_actor(
                    id_acquisition_framework=id_acquisition_framework,
                    id_nomenclature_actor_role=func.ref_nomenclatures.
                    get_id_nomenclature('ROLE_ACTEUR', '1'),
                    id_organism=id_organism)
            if actor_organism is None:
                organism = CorAcquisitionFrameworkActor(
                    id_organism=id_organism,
                    id_nomenclature_actor_role=func.ref_nomenclatures.
                    get_id_nomenclature('ROLE_ACTEUR', '1'))
                new_af.cor_af_actor.append(organism)

            # finnaly merge the CA
            new_af.id_acquisition_framework = id_acquisition_framework
            DB.session.merge(new_af)

        #its a new AF
        else:
            actor = CorAcquisitionFrameworkActor(
                id_role=id_user,
                id_nomenclature_actor_role=func.ref_nomenclatures.
                get_id_nomenclature('ROLE_ACTEUR', '1'))
            new_af.cor_af_actor.append(actor)
            if id_organism:
                organism = CorAcquisitionFrameworkActor(
                    id_organism=id_organism,
                    id_nomenclature_actor_role=func.ref_nomenclatures.
                    get_id_nomenclature('ROLE_ACTEUR', '1'))
                new_af.cor_af_actor.append(organism)

            # Add the new CA
            DB.session.add(new_af)
        # try to commit
        try:
            DB.session.commit()
        # TODO catch db error ?
        except SQLAlchemyError as e:
            DB.session.flush()
            DB.session.rollback()
            error_msg = """
                Error posting an aquisition framework {} \n\n Trace: \n {}
                """.format(uuid, e)
            log.error(error_msg)

        return new_af.as_dict()

    return {'message': 'Not found'}, 404
Exemple #4
0
def post_acquisition_framework(uuid=None, id_user=None, id_organism=None):
    """ 
        Post an acquisition framwork from MTD XML
        Params:
            uuid (str): uuid of the acquisition framework
            id_user (int): the id of the user connected via CAS
            id_organism (int): the id of the organism user via CAS
    
    """
    xml_af = None
    xml_af = get_acquisition_framework(uuid)

    if xml_af:
        acquisition_framwork = parse_acquisition_framwork_xml(xml_af)
        new_af = TAcquisitionFramework(**acquisition_framwork)
        id_acquisition_framework = TAcquisitionFramework.get_id(uuid)
        # if the CA already exist in the DB
        if id_acquisition_framework:
            # check if actor role not already exist for this CA
            actor_role = CorAcquisitionFrameworkActor.get_actor(
                id_acquisition_framework=id_acquisition_framework,
                id_nomenclature_actor_role=func.ref_nomenclatures.get_id_nomenclature('ROLE_ACTEUR', '1'),
                id_role=id_user
            )

            # if no actor push it
            if actor_role is None:
                actor = CorAcquisitionFrameworkActor(
                    id_role=id_user,
                    id_nomenclature_actor_role=func.ref_nomenclatures.get_id_nomenclature('ROLE_ACTEUR', '1')
                )
                new_af.cor_af_actor.append(actor)

            # # check if actor role not already exist for this CA
            actor_organism = None
            if id_organism:
                actor_organism = CorAcquisitionFrameworkActor.get_actor(
                    id_acquisition_framework=id_acquisition_framework,
                    id_nomenclature_actor_role=func.ref_nomenclatures.get_id_nomenclature('ROLE_ACTEUR', '1'),
                    id_organism=id_organism
                )
            if actor_organism is None:
                organism = CorAcquisitionFrameworkActor(
                    id_organism=id_organism,
                    id_nomenclature_actor_role=func.ref_nomenclatures.get_id_nomenclature('ROLE_ACTEUR', '1')
                )
                new_af.cor_af_actor.append(organism)

            # finnaly merge the CA
            new_af.id_acquisition_framework = id_acquisition_framework
            DB.session.merge(new_af)

        #its a new AF
        else:
            actor = CorAcquisitionFrameworkActor(
                id_role=id_user,
                id_nomenclature_actor_role=func.ref_nomenclatures.get_id_nomenclature('ROLE_ACTEUR', '1')
            )
            new_af.cor_af_actor.append(actor)
            if id_organism:
                organism = CorAcquisitionFrameworkActor(
                    id_organism=id_organism,
                    id_nomenclature_actor_role=func.ref_nomenclatures.get_id_nomenclature('ROLE_ACTEUR', '1')
                )
                new_af.cor_af_actor.append(organism)

            # Add the new CA
            DB.session.add(new_af)
        # try to commit
        try:
            DB.session.commit()
        # TODO catch db error ?
        except SQLAlchemyError as e:
            DB.session.flush()
            DB.session.rollback()
            error_msg = """
                Error posting an aquisition framework {} \n\n Trace: \n {}
                """.format(uuid, e)
            log.error(error_msg)

        return new_af.as_dict()

    return {'message': 'Not found'}, 404