use of cz.metacentrum.perun.core.api.exceptions.GroupRelationDoesNotExist in project perun by CESNET.
the class GroupsManagerBlImpl method removeFormerGroupsWhileSynchronization.
/**
* remove groups which are not listed in extSource anymore
*
* If some problem occurs, add groupToRemove to skippedGroups and skip it.
*
* Method is used by group structure synchronization.
*
* @param sess
* @param baseGroup from which we will be removing groups
* @param groupsToRemove list of groups to be removed from baseGroup
*
* @return list of ids already removed groups
* @throws InternalErrorException if some internal error occurs
*/
private List<Integer> removeFormerGroupsWhileSynchronization(PerunSession sess, Group baseGroup, List<Group> groupsToRemove, List<String> skippedGroups) {
List<Integer> removedGroups = new ArrayList<>();
groupsToRemove.sort(reverseOrder(comparingInt(g -> g.getName().length())));
for (Group groupToRemove : groupsToRemove) {
try {
groupToRemove = moveSubGroupsUnderBaseGroup(sess, groupToRemove, baseGroup);
deleteGroup(sess, groupToRemove, true);
removedGroups.add(groupToRemove.getId());
log.info("Group structure synchronization {}: Group id {} removed.", baseGroup, groupToRemove.getId());
} catch (RelationExistsException e) {
log.warn("Can't remove group {} from baseGroup {} due to group relation exists exception {}.", groupToRemove, e);
skippedGroups.add("GroupEntry:[" + groupToRemove + "] was skipped because group relation exists: Exception: " + e.getName() + " => " + e.getMessage() + "]");
} catch (GroupAlreadyRemovedException | GroupAlreadyRemovedFromResourceException e) {
log.debug("Group {} was removed from group {} before removing process. Skip this group.", groupToRemove, baseGroup);
} catch (GroupNotExistsException e) {
log.warn("Can't remove group {} from baseGroup {} due to group not exists exception {}.", groupToRemove, e);
skippedGroups.add("GroupEntry:[" + groupToRemove + "] was skipped because group does not exists: Exception: " + e.getName() + " => " + e.getMessage() + "]");
} catch (GroupRelationDoesNotExist e) {
log.warn("Can't remove group {} from baseGroup {} due to group relation does not exists exception {}.", groupToRemove, e);
skippedGroups.add("GroupEntry:[" + groupToRemove + "] was skipped because group relation does not exists: Exception: " + e.getName() + " => " + e.getMessage() + "]");
} catch (GroupRelationCannotBeRemoved e) {
log.warn("Can't remove group {} from baseGroup {} due to group relation cannot be removed exception {}.", groupToRemove, e);
skippedGroups.add("GroupEntry:[" + groupToRemove + "] was skipped because group relation cannot be removed: Exception: " + e.getName() + " => " + e.getMessage() + "]");
} catch (GroupMoveNotAllowedException e) {
log.warn("Can't remove group {} from baseGroup {} due to group move not allowed exception {}.", groupToRemove, e);
skippedGroups.add("GroupEntry:[" + groupToRemove + "] was skipped because group move is not allowed: Exception: " + e.getName() + " => " + e.getMessage() + "]");
} catch (WrongAttributeValueException e) {
log.warn("Can't remove group {} from baseGroup {} due to wrong attribute value exception {}.", groupToRemove, e);
skippedGroups.add("GroupEntry:[" + groupToRemove + "] was skipped because wrong attribute value: Exception: " + e.getName() + " => " + e.getMessage() + "]");
} catch (WrongReferenceAttributeValueException e) {
log.warn("Can't remove group {} from baseGroup {} due to wrong reference attribute value exception {}.", groupToRemove, e);
skippedGroups.add("GroupEntry:[" + groupToRemove + "] was skipped because wrong reference attribute value: Exception: " + e.getName() + " => " + e.getMessage() + "]");
}
}
return removedGroups;
}
use of cz.metacentrum.perun.core.api.exceptions.GroupRelationDoesNotExist in project perun by CESNET.
the class GroupsManagerBlImpl method removeGroupUnion.
@Override
public void removeGroupUnion(PerunSession sess, Group resultGroup, Group operandGroup, boolean parentFlag) throws GroupRelationDoesNotExist, GroupRelationCannotBeRemoved, GroupNotExistsException {
if (!groupsManagerImpl.isOneWayRelationBetweenGroups(resultGroup, operandGroup)) {
throw new GroupRelationDoesNotExist("Union does not exist between result group " + resultGroup + " and operand group" + operandGroup + ".");
}
Map<Integer, Map<Integer, MemberGroupStatus>> previousStatuses = getPreviousStatuses(sess, operandGroup, getGroupMembers(sess, resultGroup));
if (parentFlag || groupsManagerImpl.isRelationRemovable(sess, resultGroup, operandGroup)) {
try {
removeRelationMembers(sess, resultGroup, getGroupMembers(sess, operandGroup), operandGroup.getId());
} catch (WrongAttributeValueException | WrongReferenceAttributeValueException ex) {
throw new InternalErrorException("Removing relation members failed. Cause: {}", ex);
} catch (NotGroupMemberException ex) {
throw new ConsistencyErrorException("Database inconsistency. Cause: {}", ex);
}
} else {
throw new GroupRelationCannotBeRemoved("Union between result group " + resultGroup + " and operand group" + operandGroup + " cannot be removed, because it's part of the hierarchical structure of the groups.");
}
groupsManagerImpl.removeGroupUnion(sess, resultGroup, operandGroup);
// recalculates statuses of members in result group
for (Member member : getGroupMembers(sess, resultGroup)) {
recalculateMemberGroupStatusRecursively(sess, member, resultGroup, previousStatuses);
}
}
Aggregations