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);
}
Aggregations