Search in sources :

Example 1 with GroupCreatedAsSubgroup

use of cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupCreatedAsSubgroup in project perun by CESNET.

the class GroupsManagerBlImpl method createGroup.

@Override
public Group createGroup(PerunSession sess, Group parentGroup, Group group) throws GroupExistsException, GroupRelationNotAllowed, GroupRelationAlreadyExists {
    Vo vo = this.getVo(sess, parentGroup);
    group = getGroupsManagerImpl().createGroup(sess, vo, parentGroup, group);
    try {
        parentGroup = createGroupUnion(sess, parentGroup, group, true);
    // We catch those exceptions, but they should never be thrown, so we just log them.
    } catch (WrongAttributeValueException | WrongReferenceAttributeValueException e) {
        log.error("Exception thrown in createGroup method, while it shouldn't be thrown. Cause:{}", e);
    } catch (GroupNotExistsException e) {
        throw new ConsistencyErrorException("Database consistency error while creating group: {}", e);
    }
    getPerunBl().getAuditer().log(sess, new GroupCreatedAsSubgroup(group, vo, parentGroup));
    // check if new subgroup should be automatically assigned to resources
    List<AssignedResource> assignedResources = getPerunBl().getResourcesManagerBl().getResourceAssignments(sess, parentGroup, null).stream().filter(AssignedResource::isAutoAssignSubgroups).collect(toList());
    for (AssignedResource assignedResource : assignedResources) {
        try {
            Group sourceGroup = assignedResource.getSourceGroupId() == null ? parentGroup : getPerunBl().getGroupsManagerBl().getGroupById(sess, assignedResource.getSourceGroupId());
            getPerunBl().getResourcesManagerBl().assignAutomaticGroupToResource(sess, sourceGroup, group, assignedResource.getEnrichedResource().getResource());
        } catch (GroupResourceMismatchException | GroupNotExistsException | WrongReferenceAttributeValueException | WrongAttributeValueException e) {
        // silently skip, assignment will have to be repeated after failure cause is solved
        } catch (GroupAlreadyAssignedException e) {
        // skip, periodic checker might have assigned it already
        }
    }
    return group;
}
Also used : GroupCreatedAsSubgroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupCreatedAsSubgroup) 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) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) ParentGroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException) GroupAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) Vo(cz.metacentrum.perun.core.api.Vo) GroupCreatedInVo(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupCreatedInVo) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Aggregations

DirectMemberAddedToGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup)1 DirectMemberRemovedFromGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup)1 GroupCreatedAsSubgroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupCreatedAsSubgroup)1 GroupCreatedInVo (cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupCreatedInVo)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 AssignedResource (cz.metacentrum.perun.core.api.AssignedResource)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 RichGroup (cz.metacentrum.perun.core.api.RichGroup)1 Vo (cz.metacentrum.perun.core.api.Vo)1 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)1 GroupAlreadyAssignedException (cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException)1 GroupNotExistsException (cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException)1 GroupResourceMismatchException (cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)1 ParentGroupNotExistsException (cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException)1 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)1