Search in sources :

Example 1 with OwnerAlreadyRemovedException

use of cz.metacentrum.perun.core.api.exceptions.OwnerAlreadyRemovedException in project perun by CESNET.

the class OwnersManagerBlImpl method deleteOwner.

public void deleteOwner(PerunSession sess, Owner owner, boolean forceDelete) throws InternalErrorException, RelationExistsException, OwnerAlreadyRemovedException {
    // Check if the owner is assigned to some facility
    List<Facility> facilities = getPerunBl().getFacilitiesManagerBl().getOwnerFacilities(sess, owner);
    if (facilities != null && facilities.size() > 0) {
        if (!forceDelete) {
            throw new RelationExistsException("Owner own " + facilities.size() + " facilities");
        } else {
            for (Facility facility : facilities) {
                try {
                    getPerunBl().getFacilitiesManagerBl().removeOwner(sess, facility, owner);
                } catch (OwnerAlreadyRemovedException e) {
                    throw new InternalErrorException(e);
                }
            }
        }
    }
    //Remove all information about owner on facilities (facilities contacts)
    List<ContactGroup> ownerContactGroups = getPerunBl().getFacilitiesManagerBl().getFacilityContactGroups(sess, owner);
    if (!ownerContactGroups.isEmpty()) {
        if (forceDelete) {
            getPerunBl().getFacilitiesManagerBl().removeAllOwnerContacts(sess, owner);
        } else {
            throw new RelationExistsException("Owner has still some facilities contacts : " + ownerContactGroups);
        }
    }
    getOwnersManagerImpl().deleteOwner(sess, owner);
    getPerunBl().getAuditer().log(sess, "{} deleted.", owner);
}
Also used : RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) Facility(cz.metacentrum.perun.core.api.Facility) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) OwnerAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.OwnerAlreadyRemovedException) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup)

Aggregations

ContactGroup (cz.metacentrum.perun.core.api.ContactGroup)1 Facility (cz.metacentrum.perun.core.api.Facility)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 OwnerAlreadyRemovedException (cz.metacentrum.perun.core.api.exceptions.OwnerAlreadyRemovedException)1 RelationExistsException (cz.metacentrum.perun.core.api.exceptions.RelationExistsException)1