use of cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup 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);
}
}
Aggregations