How to use the sortinghat.exceptions.NotFoundError function in sortinghat

To help you get started, weā€™ve selected a few sortinghat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chaoss / grimoirelab-sortinghat / sortinghat / api.py View on Github external
Related information such as domains or enrollments are also removed.
    It checks first whether the organization is already on the registry.
    When it is found, the organization is removed. Otherwise,
    it will raise a 'NotFoundError'.

    :param db: database manager
    :param organization: name of the organization to remove

    :raises NotFoundError: raised when the organization does not exist
        in the registry.
    """
    with db.connect() as session:
        org = find_organization(session, organization)

        if not org:
            raise NotFoundError(entity=organization)

        delete_organization_db(session, org)
github chaoss / grimoirelab-sortinghat / sortinghat / api.py View on Github external
if not from_date:
        from_date = MIN_PERIOD_DATE
    if not to_date:
        to_date = MAX_PERIOD_DATE

    with db.connect() as session:
        uidentity = find_unique_identity(session, uuid)

        if not uidentity:
            raise NotFoundError(entity=uuid)

        org = find_organization(session, organization)

        if not org:
            raise NotFoundError(entity=organization)

        try:
            enroll_db(session, uidentity, org,
                      from_date=from_date, to_date=to_date)
        except ValueError as e:
            raise InvalidValueError(e)
github chaoss / grimoirelab-sortinghat / sortinghat / api.py View on Github external
When the given identity is not found in the registry a 'NotFoundError'
    exception is raised.

    :param db: database manager
    :param identity_id: identifier assigned to the identity that will
        be removed

    :raises NotFoundError: raised when the identity does not exist in the
        registry.
    """
    with db.connect() as session:
        identity = find_identity(session, identity_id)

        if not identity:
            raise NotFoundError(entity=identity_id)

        delete_identity_db(session, identity)
github chaoss / grimoirelab-sortinghat / sortinghat / api.py View on Github external
:returns: a list of organizations sorted by their name

    :raises NotFoundError: raised when the given term is not found on
        any organization from the registry
    """
    orgs = []

    with db.connect() as session:
        if term:
            orgs = session.query(Organization).\
                filter(Organization.name.like('%' + term + '%')).\
                order_by(Organization.name).all()

            if not orgs:
                raise NotFoundError(entity=term)
        else:
            orgs = session.query(Organization).\
                order_by(Organization.name).all()

        # Detach objects from the session
        session.expunge_all()

    return orgs
github chaoss / grimoirelab-sortinghat / sortinghat / cmd / load.py View on Github external
for org in orgs:
            try:
                api.add_organization(self.db, org.name)
            except ValueError as e:
                raise RuntimeError(str(e))
            except AlreadyExistsError as e:
                pass

            for dom in org.domains:
                try:
                    api.add_domain(self.db, org.name, dom.domain,
                                   is_top_domain=dom.is_top_domain,
                                   overwrite=overwrite)
                    self.display('load_domains.tmpl', domain=dom.domain,
                                 organization=org.name)
                except (ValueError, NotFoundError) as e:
                    raise RuntimeError(str(e))
                except AlreadyExistsError as e:
                    msg = "%s. Not updated." % str(e)
                    self.warning(msg)
github chaoss / grimoirelab-sortinghat / sortinghat / cmd / affiliate.py View on Github external
self.warning(msg)

                    organization = doms[0].organization.name

                    # Check enrollments to avoid insert affiliation twice
                    enrollments = api.enrollments(self.db, uid.uuid,
                                                  organization)

                    if enrollments:
                        continue

                    api.add_enrollment(self.db, uid.uuid, organization)

                    self.display('affiliate.tmpl', id=uid.uuid,
                                 email=identity.email, organization=organization)
        except (NotFoundError, InvalidValueError) as e:
            self.error(str(e))
            return e.code

        return CMD_SUCCESS
github chaoss / grimoirelab-sortinghat / sortinghat / api.py View on Github external
- 'gender_acc' : gender accuracy (range of 0 to 100; by default, set to 100)
       - 'is_bot' : boolean value to determine whether a unique identity is
             a bot or not. By default, this value is initialized to
             False.
       - 'country_code' : ISO-3166 country code

    :raises NotFoundError: raised when either the unique identity
        or the country code do not exist in the registry.
    :raises InvalidValueError: raised when is_bot does not have a boolean
        value.
    """
    with db.connect() as session:
        uidentity = find_unique_identity(session, uuid)

        if not uidentity:
            raise NotFoundError(entity=uuid)
        if not uidentity.profile:
            uidentity.profile = Profile()

        try:
            edit_profile_db(session, uidentity, **kwargs)
        except ValueError as e:
            raise InvalidValueError(e)
github chaoss / grimoirelab-sortinghat / sortinghat / api.py View on Github external
:raises NotFoundError: raised when either 'from_uuid' or 'to_uuid'
        do not exist in the registry
    """
    with db.connect() as session:
        fid = find_identity(session, from_id)
        tuid = find_unique_identity(session, to_uuid)

        if not fid:
            raise NotFoundError(entity=from_id)
        if not tuid:
            # Move identity to a new one
            if from_id == to_uuid:
                tuid = add_unique_identity_db(session, to_uuid)
            else:
                raise NotFoundError(entity=to_uuid)

        move_identity_db(session, fid, tuid)