use of cz.metacentrum.perun.core.api.MemberGroupStatus in project perun by CESNET.
the class urn_perun_member_resource_attribute_def_virt_groupStatus method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, Member member, Resource resource, AttributeDefinition attributeDefinition) {
Attribute attribute = new Attribute(attributeDefinition);
MemberGroupStatus result = sess.getPerunBl().getMembersManagerBl().getUnifiedMemberGroupStatus(sess, member, resource);
attribute.setValue((result != null) ? result.toString() : null);
return attribute;
}
use of cz.metacentrum.perun.core.api.MemberGroupStatus in project perun by CESNET.
the class ExpirationNotifSchedulerTest method checkMembersGroupStateShouldExpireTodayDoesNotAffectOthers.
@Test
public void checkMembersGroupStateShouldExpireTodayDoesNotAffectOthers() throws Exception {
System.out.println(CLASS_NAME + "checkMembersGroupStateShouldExpireToday");
// setup expiration date to today
String today = LocalDate.now().toString();
// set up member in group
// set up member in group
Member member1 = setUpMember();
Member member2 = setUpMember();
Group group = setUpGroup();
perun.getGroupsManagerBl().addMember(session, group, member1);
perun.getGroupsManagerBl().addMember(session, group, member2);
// set group expiration for today
Attribute m1Expiration = new Attribute(perun.getAttributesManager().getAttributeDefinition(session, GROUP_EXPIRATION_URN));
m1Expiration.setValue(today);
perun.getAttributesManager().setAttribute(session, member1, group, m1Expiration);
// set group expiration for tomorrow
String tomorrow = LocalDate.now().plusDays(1).toString();
Attribute m2Expiration = new Attribute(perun.getAttributesManager().getAttributeDefinition(session, GROUP_EXPIRATION_URN));
m1Expiration.setValue(tomorrow);
perun.getAttributesManager().setAttribute(session, member2, group, m2Expiration);
scheduler.checkMembersState();
MemberGroupStatus memberGroupStatus = perun.getGroupsManagerBl().getDirectMemberGroupStatus(session, member2, group);
assertEquals("Member should not be expired!", MemberGroupStatus.VALID, memberGroupStatus);
}
use of cz.metacentrum.perun.core.api.MemberGroupStatus 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);
}
}
use of cz.metacentrum.perun.core.api.MemberGroupStatus in project perun by CESNET.
the class GroupsManagerBlImpl method getGroupMembersCountsByGroupStatus.
@Override
public Map<MemberGroupStatus, Integer> getGroupMembersCountsByGroupStatus(PerunSession sess, Group group) {
List<Member> members = this.getGroupMembers(sess, group);
Map<MemberGroupStatus, Integer> counts = new HashMap<>();
for (MemberGroupStatus status : MemberGroupStatus.values()) {
counts.put(status, 0);
}
members.forEach(member -> counts.computeIfPresent(member.getGroupStatus(), (key, value) -> value + 1));
return counts;
}
use of cz.metacentrum.perun.core.api.MemberGroupStatus in project perun by CESNET.
the class GroupsManagerBlImpl method expireMemberInGroup.
@Override
public void expireMemberInGroup(PerunSession sess, Member member, Group group) {
if (group == null) {
throw new InternalErrorException("Group can not be null.");
}
if (VosManager.MEMBERS_GROUP.equals(group.getName())) {
throw new InternalErrorException("Can not expire member in members group.");
}
if (member == null) {
throw new InternalErrorException("Member to expire can not be null");
}
MemberGroupStatus previousStatus = getDirectMemberGroupStatus(sess, member, group);
if (MemberGroupStatus.EXPIRED.equals(previousStatus)) {
log.warn("Expiring member in group where is already expired. Member: {}, Group: {}", member, group);
}
Map<Integer, Map<Integer, MemberGroupStatus>> previousIndirectStatuses = getPreviousStatuses(sess, group, List.of(member));
// expire in given group
groupsManagerImpl.setDirectGroupStatus(sess, member, group, MemberGroupStatus.EXPIRED);
recalculateMemberGroupStatusRecursively(sess, member, group, previousIndirectStatuses);
}
Aggregations