use of cz.metacentrum.perun.core.api.exceptions.BanNotExistsException in project perun by CESNET.
the class MembersManagerBlImpl method deleteMember.
public void deleteMember(PerunSession sess, Member member) throws InternalErrorException, MemberAlreadyRemovedException, GroupOperationsException {
Vo vo = this.getMemberVo(sess, member);
User user;
try {
user = getPerunBl().getUsersManagerBl().getUserById(sess, member.getUserId());
} catch (UserNotExistsException e1) {
throw new ConsistencyErrorException("Removing member who doesn't have corresponding user.", e1);
}
List<Facility> allowedFacilities = getPerunBl().getFacilitiesManagerBl().getAllowedFacilities(sess, user);
Map<Facility, List<Attribute>> requiredAttributesBeforeMemberRemove = new HashMap<Facility, List<Attribute>>();
for (Facility facility : allowedFacilities) {
// Get actually required attributes, they will be later compared with list of required attributes when the member will be removed from all resources in this VO
requiredAttributesBeforeMemberRemove.put(facility, getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, facility, user));
}
// Remove member from all groups
List<Group> memberGroups = getPerunBl().getGroupsManagerBl().getMemberDirectGroups(sess, member);
for (Group group : memberGroups) {
// Member must be removed from the members group using separate method
if (group.getName().equals(VosManager.MEMBERS_GROUP))
continue;
try {
getPerunBl().getGroupsManagerBl().removeMember(sess, group, member);
} catch (NotGroupMemberException e) {
throw new ConsistencyErrorException("getMemberGroups return group where the member is not member", e);
} catch (GroupNotExistsException e) {
throw new ConsistencyErrorException(e);
}
}
// Remove member from the VO members group
try {
Group g = getPerunBl().getGroupsManagerBl().getGroupByName(sess, vo, VosManager.MEMBERS_GROUP);
try {
getPerunBl().getGroupsManagerBl().removeMemberFromMembersOrAdministratorsGroup(sess, g, member);
} catch (NotGroupMemberException e) {
throw new ConsistencyErrorException("Member is not in the \"members\" group." + member + " " + g, e);
}
} catch (GroupNotExistsException e) {
throw new InternalErrorException(e);
}
// Remove member's attributes (namespaces: member and resource-member)
try {
getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, member);
List<Resource> resources = getPerunBl().getResourcesManagerBl().getResources(sess, vo);
for (Resource resource : resources) {
getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, resource, member);
}
} catch (AttributeValueException ex) {
throw new ConsistencyErrorException("Member is removed from all groups. There are no required attribute for this member. Member's attributes can be removed without problem.", ex);
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
}
// Remove user-facility attributes which are no longer required
for (Facility facility : allowedFacilities) {
List<Attribute> requiredAttributes = requiredAttributesBeforeMemberRemove.get(facility);
//remove currently required attributes from requiredAttributesBeforeMemberRemove
requiredAttributes.removeAll(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, facility, user));
//remove attributes which are no longer required
try {
getPerunBl().getAttributesManagerBl().removeAttributes(sess, facility, user, requiredAttributes);
} catch (AttributeValueException | WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
}
}
//Remove all members bans
List<BanOnResource> bansOnResource = getPerunBl().getResourcesManagerBl().getBansForMember(sess, member.getId());
for (BanOnResource banOnResource : bansOnResource) {
try {
getPerunBl().getResourcesManagerBl().removeBan(sess, banOnResource.getId());
} catch (BanNotExistsException ex) {
//it is ok, we just want to remove it anyway
}
}
/* TODO this can be used for future optimization. If the user is not asigned to the facility anymore all user-facility attributes (for this facility) can be safely removed.
for (Facility facility: facilitiesBeforeMemberRemove) {
// Remove user-facility attributes
try {
getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, facility, user);
log.debug("Removing user-facility attributes for facility {}", facility);
} catch (AttributeValueException e) {
throw new ConsistencyErrorException("Member is removed from all resources. There are no required attribute for this member. User-facility attributes can be removed without problem.", e);
}
}
*/
// Remove member from the DB
getMembersManagerImpl().deleteMember(sess, member);
getPerunBl().getAuditer().log(sess, "{} deleted.", member);
}
use of cz.metacentrum.perun.core.api.exceptions.BanNotExistsException in project perun by CESNET.
the class FacilitiesManagerBlImpl method deleteFacility.
public void deleteFacility(PerunSession sess, Facility facility) throws InternalErrorException, RelationExistsException, FacilityAlreadyRemovedException, HostAlreadyRemovedException, GroupAlreadyRemovedException, ResourceAlreadyRemovedException, GroupAlreadyRemovedFromResourceException {
if (getFacilitiesManagerImpl().getAssignedResources(sess, facility).size() > 0) {
throw new RelationExistsException("Facility is still used as a resource");
}
//remove hosts
List<Host> hosts = this.getHosts(sess, facility);
for (Host host : hosts) {
this.removeHost(sess, host);
}
//remove destinations
getPerunBl().getServicesManagerBl().removeAllDestinations(sess, facility);
// remove assigned security teams
List<SecurityTeam> teams = getAssignedSecurityTeams(sess, facility);
for (SecurityTeam team : teams) {
removeSecurityTeam(sess, facility, team);
}
// remove assigned facility contacts
List<ContactGroup> contacts = getFacilityContactGroups(sess, facility);
if (contacts != null && !contacts.isEmpty()) {
removeFacilityContacts(sess, contacts);
}
// remove associated attributes
try {
getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, facility);
} catch (WrongAttributeValueException e) {
throw new InternalErrorException(e);
} catch (WrongReferenceAttributeValueException e) {
throw new InternalErrorException(e);
}
//Remove all facility bans
List<BanOnFacility> bansOnFacility = this.getBansForFacility(sess, facility.getId());
for (BanOnFacility banOnFacility : bansOnFacility) {
try {
this.removeBan(sess, banOnFacility.getId());
} catch (BanNotExistsException ex) {
//it is ok, we just want to remove it anyway
}
}
// delete facility
getFacilitiesManagerImpl().deleteFacilityOwners(sess, facility);
getFacilitiesManagerImpl().deleteFacility(sess, facility);
getPerunBl().getAuditer().log(sess, "Facility deleted {}.", facility);
}
Aggregations