Search in sources :

Example 16 with MemberGroupStatus

use of cz.metacentrum.perun.core.api.MemberGroupStatus in project perun by CESNET.

the class GroupsManagerBlImpl method getMemberGroupStatusesForGroupAndForMembersFromOtherGroup.

// /**
// * Returns map containing statuses for each group and for each member
// *
// * @param sess session
// * @param groups groups where statuses are calculated
// * @return Map containing groups with members and their statuses
// * @throws InternalErrorException internal error
// */
// private Map<Group, Map<Member, MemberGroupStatus>> getMemberGroupStatusesForGroups(PerunSession sess, List<Group> groups) throws InternalErrorException {
// Map<Group, Map<Member, MemberGroupStatus>> previousStatuses = new HashMap<>();
// for (Group previousResultGroup : groups) {
// previousStatuses.put(previousResultGroup, getMemberGroupStatusesForGroup(sess, previousResultGroup));
// }
// return previousStatuses;
// }
// 
// /**
// * Returns map containing statuses for each member in given group
// *
// * @param sess session
// * @param group group
// * @return map containing statuses for each member in given group
// * @throws InternalErrorException internal error
// */
// private Map<Member, MemberGroupStatus> getMemberGroupStatusesForGroup(PerunSession sess, Group group) throws InternalErrorException {
// return getMemberGroupStatusesForGroupAndForMembersFromOtherGroup(sess, group, group);
// }
/**
 * Returns map containing statuses for members from 'fromGroup' inside given group
 *
 * @param sess session
 * @param group group
 * @return map containing statuses for each member in given group
 * @throws InternalErrorException internal error
 */
private Map<Member, MemberGroupStatus> getMemberGroupStatusesForGroupAndForMembersFromOtherGroup(PerunSession sess, Group group, Group fromGroup) {
    Map<Member, MemberGroupStatus> groupStatuses = new HashMap<>();
    List<Member> groupMembers = getGroupMembers(sess, fromGroup);
    for (Member groupMember : groupMembers) {
        groupStatuses.put(groupMember, getTotalMemberGroupStatus(sess, groupMember, group));
    }
    return groupStatuses;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus)

Example 17 with MemberGroupStatus

use of cz.metacentrum.perun.core.api.MemberGroupStatus in project perun by CESNET.

the class GroupsManagerEntryIntegrationTest method getGroupMembersCountsByGroupStatus.

@Test
public void getGroupMembersCountsByGroupStatus() throws Exception {
    System.out.println(CLASS_NAME + "getGroupMembersCountsByGroupStatus");
    vo = setUpVo();
    setUpGroup(vo);
    Member member = setUpMember(vo);
    groupsManager.addMember(sess, group, member);
    Member expiredMember = setUpMember(vo);
    groupsManager.addMember(sess, group, expiredMember);
    groupsManager.setMemberGroupStatus(sess, expiredMember, group, MemberGroupStatus.EXPIRED);
    Map<MemberGroupStatus, Integer> counts = groupsManager.getGroupMembersCountsByGroupStatus(sess, group);
    assertThat(counts.get(MemberGroupStatus.VALID)).isEqualTo(1);
    assertThat(counts.get(MemberGroupStatus.EXPIRED)).isEqualTo(1);
}
Also used : RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 18 with MemberGroupStatus

use of cz.metacentrum.perun.core.api.MemberGroupStatus in project perun by CESNET.

the class ExpirationNotifScheduler method auditOldGroupExpirations.

/**
 * Logs expirations that happened a week ago for a group
 *
 * @param allowedStatuses allowed Statuses
 * @param group group
 * @throws InternalErrorException internal error
 */
private void auditOldGroupExpirations(List<Status> allowedStatuses, Group group) {
    // log message for all members which expired 7 days ago
    LocalDate expiredWeekAgo = getCurrentLocalDate().minusDays(7);
    List<Member> expired7DaysAgo = perun.getSearcherBl().getMembersByGroupExpiration(sess, group, "=", expiredWeekAgo);
    for (Member m : expired7DaysAgo) {
        if (allowedStatuses.contains(m.getStatus())) {
            MemberGroupStatus status = perun.getGroupsManagerBl().getDirectMemberGroupStatus(sess, m, group);
            // we don't notify members in indirect only relation
            if (status != null) {
                if (didntSubmitGroupExtensionApplication(m, group)) {
                    // still didn't apply for extension
                    getPerun().getAuditer().log(sess, new GroupMembershipExpired(m, 7, group));
                } else {
                    log.debug("{} not notified about expiration in {}, has submitted - pending application.", m, group);
                }
            } else {
                log.debug("{} not notified about expiration in {}, isn't DIRECT member but still has expiration set!", m, group);
            }
        } else {
            log.debug("{} not notified about expiration in {}, is not in VALID, SUSPENDED or EXPIRED state.", m, group);
        }
    }
}
Also used : LocalDate(java.time.LocalDate) Member(cz.metacentrum.perun.core.api.Member) GroupMembershipExpired(cz.metacentrum.perun.audit.events.ExpirationNotifScheduler.GroupMembershipExpired) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus)

Example 19 with MemberGroupStatus

use of cz.metacentrum.perun.core.api.MemberGroupStatus in project perun by CESNET.

the class urn_perun_member_group_attribute_def_virt_groupStatus method getAttributeValue.

@Override
public Attribute getAttributeValue(PerunSessionImpl sess, Member member, Group group, AttributeDefinition attribute) {
    // Source member object can't be trusted to hold correct group membership status, since we don't know in which context
    // it was originally retrieved. Hence we get member of a group once more.
    Attribute newAttribute = new Attribute(attribute);
    try {
        Member retrievedMember = sess.getPerunBl().getGroupsManagerBl().getGroupMemberById(sess, group, member.getId());
        MemberGroupStatus result = retrievedMember.getGroupStatus();
        newAttribute.setValue((result != null) ? result.toString() : null);
        return newAttribute;
    } catch (NotGroupMemberException e) {
        log.warn("{} is not member of a {} when retrieving member_group:virt:groupStatus attribute.", member, group);
    }
    return newAttribute;
}
Also used : NotGroupMemberException(cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException) Attribute(cz.metacentrum.perun.core.api.Attribute) Member(cz.metacentrum.perun.core.api.Member) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus)

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