Beispiel #1
0
def get_single(type_: str,
               api_name: str,
               session: scoped_session,
               path: str = None) -> Dict[str, Any]:
    """Get instance of classes with single objects.
    :param type_: type of object to be updated
    :param api_name: api name specified while starting server
    :param session: sqlalchemy scoped session
    :param path: endpoint
    :return: response containing information about a single object

    Raises:
        ClassNotFound: If `type_` does not represt a valid/defined RDFClass.
        InstanceNotFound: If no Instance with type `type_` exists.

    """
    instance = get_single_response(session, type_)
    object_ = get(instance.id,
                  type_,
                  session=session,
                  api_name=api_name,
                  path=path)
    if path is not None:
        object_["@id"] = f"/{api_name}/{path}"
    else:
        object_["@id"] = f"/{api_name}/{type_}"
    return object_
Beispiel #2
0
def update_single(object_: Dict[str, Any],
                  session: scoped_session,
                  api_name: str,
                  path: str = None) -> int:
    """Update instance of classes with single objects.
    :param object_: new object
    :param session: sqlalchemy scoped session
    :param api_name: api name specified while starting server
    :param path: endpoint
    :return: id of the updated object

    Raises:
        ClassNotFound: If `object['@type']` does not represt a valid/defined RDFClass.
        InstanceNotFound: If no Instance of the class exists.

    """
    type_ = object_["@type"]
    instance = get_single_response(session, type_)

    return update(id_=instance.id,
                  type_=type_,
                  object_=object_,
                  session=session,
                  api_name=api_name,
                  path=path)
Beispiel #3
0
def delete_single(type_: str, session: scoped_session) -> None:
    """Delete instance of classes with single objects.
    :param type_: type of object to be deleted
    :param session: sqlalchemy scoped session
    :return: None
    Raises:
        ClassNotFound: If `type_` does not represt a valid/defined RDFClass.
        InstanceNotFound: If no Instance of the class exists.
    """
    instance = get_single_response(session, type_)

    return delete(instance.id, type_, session=session)