Search in sources :

Example 1 with GroupRelationDoesNotExist

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;
}
Also used : EnrichedGroup(cz.metacentrum.perun.core.api.EnrichedGroup) IndirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup) CandidateGroup(cz.metacentrum.perun.core.api.CandidateGroup) RichGroup(cz.metacentrum.perun.core.api.RichGroup) MemberExpiredInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup) MemberValidatedInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup) DirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup) Group(cz.metacentrum.perun.core.api.Group) DirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup) IndirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup) GroupRelationCannotBeRemoved(cz.metacentrum.perun.core.api.exceptions.GroupRelationCannotBeRemoved) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) ParentGroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException) GroupMoveNotAllowedException(cz.metacentrum.perun.core.api.exceptions.GroupMoveNotAllowedException) GroupRelationDoesNotExist(cz.metacentrum.perun.core.api.exceptions.GroupRelationDoesNotExist) ArrayList(java.util.ArrayList) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) GroupAlreadyRemovedFromResourceException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) GroupAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedException)

Example 2 with GroupRelationDoesNotExist

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);
    }
}
Also used : NotGroupMemberException(cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException) GroupRelationCannotBeRemoved(cz.metacentrum.perun.core.api.exceptions.GroupRelationCannotBeRemoved) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) GroupRelationDoesNotExist(cz.metacentrum.perun.core.api.exceptions.GroupRelationDoesNotExist) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member)

Aggregations

GroupRelationCannotBeRemoved (cz.metacentrum.perun.core.api.exceptions.GroupRelationCannotBeRemoved)2 GroupRelationDoesNotExist (cz.metacentrum.perun.core.api.exceptions.GroupRelationDoesNotExist)2 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)2 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)2 DirectMemberAddedToGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup)1 DirectMemberRemovedFromGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup)1 IndirectMemberAddedToGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup)1 IndirectMemberRemovedFromGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup)1 MemberExpiredInGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup)1 MemberValidatedInGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup)1 CandidateGroup (cz.metacentrum.perun.core.api.CandidateGroup)1 EnrichedGroup (cz.metacentrum.perun.core.api.EnrichedGroup)1 Group (cz.metacentrum.perun.core.api.Group)1 Member (cz.metacentrum.perun.core.api.Member)1 RichGroup (cz.metacentrum.perun.core.api.RichGroup)1 RichMember (cz.metacentrum.perun.core.api.RichMember)1 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)1 GroupAlreadyRemovedException (cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedException)1 GroupAlreadyRemovedFromResourceException (cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException)1 GroupMoveNotAllowedException (cz.metacentrum.perun.core.api.exceptions.GroupMoveNotAllowedException)1