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