use of cz.metacentrum.perun.core.api.MemberGroupStatus in project perun by CESNET.
the class GroupsManagerImpl method getTotalGroupStatusForMembers.
@Override
public Map<Integer, MemberGroupStatus> getTotalGroupStatusForMembers(PerunSession session, Group group, List<Member> members) {
List<Integer> memberIds = new ArrayList<>();
members.forEach(member -> memberIds.add(member.getId()));
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("groupId", group.getId());
parameters.addValue("memberIds", memberIds);
try {
Map<Integer, List<Integer>> map = namedParameterJdbcTemplate.query("select member_id, source_group_status FROM groups_members" + " join members on groups_members.member_id=members.id where group_id=(:groupId) and member_id in (:memberIds)", parameters, MEMBERID_MEMBERGROUPSTATUS_EXTRACTOR);
Map<Integer, MemberGroupStatus> resultMap = new HashMap<>();
if (map == null) {
return null;
}
for (Integer memberId : map.keySet()) {
if (map.get(memberId).contains(0)) {
resultMap.put(memberId, MemberGroupStatus.VALID);
} else {
resultMap.put(memberId, MemberGroupStatus.EXPIRED);
}
}
return resultMap;
} catch (RuntimeException e) {
throw new InternalErrorException(e);
}
}
use of cz.metacentrum.perun.core.api.MemberGroupStatus in project perun by CESNET.
the class urn_perun_user_facility_attribute_def_virt_groupStatus method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, Facility facility, AttributeDefinition attributeDefinition) {
Attribute attribute = new Attribute(attributeDefinition);
MemberGroupStatus result = sess.getPerunBl().getMembersManagerBl().getUnifiedMemberGroupStatus(sess, user, facility);
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 checkMembersGroupStateShouldBeValidatedToday.
@Test
public void checkMembersGroupStateShouldBeValidatedToday() throws Exception {
System.out.println(CLASS_NAME + "checkMembersGroupStateShouldBeValidatedToday");
// setup expiration date
String tomorrow = LocalDate.now().plusDays(1).toString();
// set up member in group
Member member1 = setUpMember();
Group group = setUpGroup();
perun.getGroupsManagerBl().addMember(session, group, member1);
// set group expiration for tomorrow
Attribute expiration = new Attribute(perun.getAttributesManager().getAttributeDefinition(session, GROUP_EXPIRATION_URN));
expiration.setValue(tomorrow);
perun.getAttributesManager().setAttribute(session, member1, group, expiration);
perun.getGroupsManagerBl().expireMemberInGroup(session, member1, group);
// Check init state
MemberGroupStatus initMemberGroupStatus = perun.getGroupsManagerBl().getDirectMemberGroupStatus(session, member1, group);
assertEquals("Member should be set to expired state before testing!", MemberGroupStatus.EXPIRED, initMemberGroupStatus);
scheduler.checkMembersState();
// Check if state was switched
MemberGroupStatus memberGroupStatus = perun.getGroupsManagerBl().getDirectMemberGroupStatus(session, member1, group);
assertEquals("Member should be valid now (from expired)!", MemberGroupStatus.VALID, memberGroupStatus);
}
use of cz.metacentrum.perun.core.api.MemberGroupStatus in project perun by CESNET.
the class ExpirationNotifSchedulerTest method checkMembersGroupStateShouldBeValidatedTodayDoesNotAffectOthers.
@Test
public void checkMembersGroupStateShouldBeValidatedTodayDoesNotAffectOthers() throws Exception {
System.out.println(CLASS_NAME + "checkMembersGroupStateShouldBeValidatedToday");
// setup expiration date
String tomorrow = LocalDate.now().plusDays(1).toString();
// 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 tomorrow
Attribute m1Expiration = new Attribute(perun.getAttributesManager().getAttributeDefinition(session, GROUP_EXPIRATION_URN));
m1Expiration.setValue(tomorrow);
perun.getAttributesManager().setAttribute(session, member1, group, m1Expiration);
// set group expiration for yesterday
String yesterday = LocalDate.now().minusDays(1).toString();
Attribute m2Expiration = new Attribute(perun.getAttributesManager().getAttributeDefinition(session, GROUP_EXPIRATION_URN));
m2Expiration.setValue(yesterday);
perun.getAttributesManager().setAttribute(session, member2, group, m2Expiration);
perun.getGroupsManagerBl().expireMemberInGroup(session, member1, group);
perun.getGroupsManagerBl().expireMemberInGroup(session, member2, group);
scheduler.checkMembersState();
// Check if state was not switched
MemberGroupStatus memberGroupStatus = perun.getGroupsManagerBl().getDirectMemberGroupStatus(session, member2, group);
assertEquals("Member should not be validated!", MemberGroupStatus.EXPIRED, memberGroupStatus);
}
use of cz.metacentrum.perun.core.api.MemberGroupStatus in project perun by CESNET.
the class ExpirationNotifSchedulerTest method checkMembersGroupStateShouldExpireToday.
@Test
public void checkMembersGroupStateShouldExpireToday() throws Exception {
System.out.println(CLASS_NAME + "checkMembersGroupStateShouldExpireToday");
// setup expiration date to today
String today = LocalDate.now().toString();
// set up member in group
Member member1 = setUpMember();
Group group = setUpGroup();
perun.getGroupsManagerBl().addMember(session, group, member1);
// set group expiration for today
Attribute expiration = new Attribute(perun.getAttributesManager().getAttributeDefinition(session, GROUP_EXPIRATION_URN));
expiration.setValue(today);
perun.getAttributesManager().setAttribute(session, member1, group, expiration);
scheduler.checkMembersState();
MemberGroupStatus memberGroupStatus = perun.getGroupsManagerBl().getDirectMemberGroupStatus(session, member1, group);
assertEquals("Member should be expired now (from valid)!", MemberGroupStatus.EXPIRED, memberGroupStatus);
}
Aggregations