Search in sources :

Example 1 with MemberValidatedInGroup

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

the class GroupsManagerBlImpl method recalculateMemberGroupStatusRecursively.

/**
 * Calculates the state of given member in given group and if
 * it differs from given 'previousState' calls this method recursively
 * for all parent groups.
 *
 * @param member member
 * @param group group
 * @param previousStatus previousStatus
 * @throws InternalErrorException internal error
 */
@Override
public void recalculateMemberGroupStatusRecursively(PerunSession sess, Member member, Group group, Map<Integer, Map<Integer, MemberGroupStatus>> previousStatus) {
    if (member == null) {
        throw new InternalErrorException("Member, which should be checked, can not be null.");
    }
    if (group == null) {
        throw new InternalErrorException("Group, where members status should be recalculated, can not be null.");
    }
    // skip members group where all members are valid all the time
    if (group.getName().equals(VosManager.MEMBERS_GROUP)) {
        return;
    }
    MemberGroupStatus newStatus = getTotalMemberGroupStatus(sess, member, group);
    boolean saveStatuses = true;
    // but we can not save statuses because the relations should be already removed
    if (newStatus == null) {
        saveStatuses = false;
    }
    // get all possibly affected groups and member's statuses for them
    List<Group> affectedGroups = new ArrayList<>(groupsManagerImpl.getResultGroups(sess, group.getId()));
    // if the new status is not null, update statuses received from the group to other groups
    if (saveStatuses) {
        groupsManagerImpl.setIndirectGroupStatus(sess, member, group, newStatus);
        if (previousStatus.get(group.getId()) == null || previousStatus.get(group.getId()).isEmpty() || !newStatus.equals(previousStatus.get(group.getId()).get(member.getId()))) {
            if (newStatus.equals(MemberGroupStatus.EXPIRED)) {
                getPerunBl().getAuditer().log(sess, new MemberExpiredInGroup(member, group));
            } else if (newStatus.equals(MemberGroupStatus.VALID)) {
                getPerunBl().getAuditer().log(sess, new MemberValidatedInGroup(member, group));
            }
        }
    }
    // check recursively all parent groups
    for (Group affectedGroup : affectedGroups) {
        recalculateMemberGroupStatusRecursively(sess, member, affectedGroup, previousStatus);
    }
}
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) ArrayList(java.util.ArrayList) MemberExpiredInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup) MemberValidatedInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus)

Aggregations

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 MemberGroupStatus (cz.metacentrum.perun.core.api.MemberGroupStatus)1 RichGroup (cz.metacentrum.perun.core.api.RichGroup)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 ArrayList (java.util.ArrayList)1