Search in sources :

Example 11 with MemberGroupStatus

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);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus)

Example 12 with MemberGroupStatus

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;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus)

Example 13 with MemberGroupStatus

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);
}
Also used : Group(cz.metacentrum.perun.core.api.Group) Attribute(cz.metacentrum.perun.core.api.Attribute) Member(cz.metacentrum.perun.core.api.Member) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus) Test(org.junit.Test)

Example 14 with 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);
}
Also used : Group(cz.metacentrum.perun.core.api.Group) Attribute(cz.metacentrum.perun.core.api.Attribute) Member(cz.metacentrum.perun.core.api.Member) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus) Test(org.junit.Test)

Example 15 with 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);
}
Also used : Group(cz.metacentrum.perun.core.api.Group) Attribute(cz.metacentrum.perun.core.api.Attribute) Member(cz.metacentrum.perun.core.api.Member) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus) Test(org.junit.Test)

Aggregations

MemberGroupStatus (cz.metacentrum.perun.core.api.MemberGroupStatus)19 Member (cz.metacentrum.perun.core.api.Member)12 Attribute (cz.metacentrum.perun.core.api.Attribute)8 Test (org.junit.Test)8 Group (cz.metacentrum.perun.core.api.Group)6 RichMember (cz.metacentrum.perun.core.api.RichMember)6 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)6 HashMap (java.util.HashMap)5 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)4 LinkedHashMap (java.util.LinkedHashMap)4 Vo (cz.metacentrum.perun.core.api.Vo)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 DirectMemberAddedToGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup)2 DirectMemberRemovedFromGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup)2 IndirectMemberAddedToGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup)2 IndirectMemberRemovedFromGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup)2 MemberExpiredInGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup)2 MemberValidatedInGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup)2