Search in sources :

Example 1 with OwnerDeleted

use of cz.metacentrum.perun.audit.events.OwnersManagerEvents.OwnerDeleted in project perun by CESNET.

the class OwnersManagerBlImpl method deleteOwner.

@Override
public void deleteOwner(PerunSession sess, Owner owner, boolean forceDelete) throws 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);
                }
            }
        }
    }
    getOwnersManagerImpl().deleteOwner(sess, owner);
    getPerunBl().getAuditer().log(sess, new OwnerDeleted(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) OwnerDeleted(cz.metacentrum.perun.audit.events.OwnersManagerEvents.OwnerDeleted)

Aggregations

OwnerDeleted (cz.metacentrum.perun.audit.events.OwnersManagerEvents.OwnerDeleted)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