use of cz.metacentrum.perun.core.api.MemberGroupStatus in project perun by CESNET.
the class GroupsManagerEntryIntegrationTest method getTotalGroupStatusForMembers_notMembersOfGroup.
@Test
public void getTotalGroupStatusForMembers_notMembersOfGroup() throws Exception {
System.out.println(CLASS_NAME + "getTotalGroupStatusForMembers_notMembersOfGroup");
// set up member in group and vo
Vo vo = setUpVo();
Member member = setUpMember(vo);
groupsManagerBl.createGroup(sess, vo, group);
groupsManagerBl.createGroup(sess, vo, group2);
groupsManagerBl.addMember(sess, group, member);
Map<Integer, MemberGroupStatus> map = groupsManagerBl.getTotalGroupStatusForMembers(sess, group2, List.of(member));
assertTrue("There should be no relation between the group and the member", map.isEmpty());
}
use of cz.metacentrum.perun.core.api.MemberGroupStatus in project perun by CESNET.
the class GroupsManagerEntryIntegrationTest method getTotalGroupStatusForMembers.
@Test
public void getTotalGroupStatusForMembers() throws Exception {
System.out.println(CLASS_NAME + "getTotalGroupStatusForMembers");
// set up member in group and vo
Vo vo = setUpVo();
Member member = setUpMemberWithDifferentParam(vo, 111);
Member member2 = setUpMemberWithDifferentParam(vo, 222);
Member member3 = setUpMemberWithDifferentParam(vo, 333);
Member member4 = setUpMemberWithDifferentParam(vo, 444);
groupsManagerBl.createGroup(sess, vo, group);
groupsManagerBl.addMember(sess, group, member);
groupsManagerBl.addMember(sess, group, member2);
groupsManagerBl.addMember(sess, group, member3);
groupsManagerBl.addMember(sess, group, member4);
groupsManagerBl.expireMemberInGroup(sess, member, group);
groupsManagerBl.expireMemberInGroup(sess, member2, group);
Map<Integer, MemberGroupStatus> map = groupsManagerBl.getTotalGroupStatusForMembers(sess, group, List.of(member, member2, member3, member4));
assertEquals("Member's group status is not EXPIRED", MemberGroupStatus.EXPIRED, map.get(member.getId()));
assertEquals("Member's group status is not EXPIRED", MemberGroupStatus.EXPIRED, map.get(member2.getId()));
assertEquals("Member's group status is not VALID", MemberGroupStatus.VALID, map.get(member3.getId()));
assertEquals("Member's group status is not VALID", MemberGroupStatus.VALID, map.get(member4.getId()));
}
use of cz.metacentrum.perun.core.api.MemberGroupStatus in project perun by CESNET.
the class GroupsManagerBlImpl method validateMemberInGroup.
@Override
public void validateMemberInGroup(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 validate member in members group.");
}
if (member == null) {
throw new InternalErrorException("Member to validate can not be null");
}
MemberGroupStatus previousStatus = getDirectMemberGroupStatus(sess, member, group);
if (MemberGroupStatus.VALID.equals(previousStatus)) {
log.warn("Validating member in group where is already validated. Member: {}, Group: {}", member, group);
}
Map<Integer, Map<Integer, MemberGroupStatus>> previousIndirectStatuses = getPreviousStatuses(sess, group, List.of(member));
// validate member in given group
groupsManagerImpl.setDirectGroupStatus(sess, member, group, MemberGroupStatus.VALID);
recalculateMemberGroupStatusRecursively(sess, member, group, previousIndirectStatuses);
}
use of cz.metacentrum.perun.core.api.MemberGroupStatus in project perun by CESNET.
the class GroupsManagerEntryIntegrationTest method getTotalGroupStatusForMembers_memberValidThroughSubgroup.
@Test
public void getTotalGroupStatusForMembers_memberValidThroughSubgroup() throws Exception {
System.out.println(CLASS_NAME + "getTotalGroupStatusForMembers_memberValidThroughSubgroup");
// set up member in group and vo
Vo vo = setUpVo();
Member member = setUpMember(vo);
groupsManagerBl.createGroup(sess, vo, group);
groupsManagerBl.createGroup(sess, group, group2);
groupsManagerBl.addMember(sess, group, member);
groupsManagerBl.addMember(sess, group2, member);
groupsManagerBl.expireMemberInGroup(sess, member, group);
Map<Integer, MemberGroupStatus> map = groupsManagerBl.getTotalGroupStatusForMembers(sess, group, List.of(member));
assertEquals("Member's group status is not EXPIRED", MemberGroupStatus.VALID, map.get(member.getId()));
}
use of cz.metacentrum.perun.core.api.MemberGroupStatus in project perun by CESNET.
the class urn_perun_member_group_attribute_def_def_groupMembershipExpiration method changedAttributeHook.
@Override
public void changedAttributeHook(PerunSessionImpl session, Member member, Group group, Attribute attribute) {
String value = null;
if (attribute.getValue() != null)
value = (String) attribute.getValue();
// If there is some value and member is in status expired or disabled
// find out members status in given group
MemberGroupStatus status = session.getPerunBl().getGroupsManagerBl().getDirectMemberGroupStatus(session, member, group);
// status is null if member is not direct at the time -> changing value doesn't affect indirect membership
if (value != null && MemberGroupStatus.EXPIRED.equals(status)) {
Date expirationDate;
try {
expirationDate = BeansUtils.getDateFormatterWithoutTime().parse(value);
} catch (ParseException ex) {
throw new InternalErrorException("Date parsing failed in setHook, even if parsing in checkMethod was correct.", ex);
}
Date date = new Date();
if (expirationDate.compareTo(date) > 0) {
session.getPerunBl().getGroupsManagerBl().validateMemberInGroup(session, member, group);
}
}
}
Aggregations