Search in sources :

Example 1 with Paginated

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

the class MembersManagerBlImpl method getMembersPage.

@Override
public Paginated<RichMember> getMembersPage(PerunSession sess, Vo vo, MembersPageQuery query, List<String> attrNames) {
    Paginated<Member> paginatedMembers = membersManagerImpl.getMembersPage(sess, vo, query);
    List<RichMember> richMembers = convertMembersToRichMembers(sess, paginatedMembers.getData());
    List<AttributeDefinition> attrDefs = new ArrayList<>();
    for (String attrsName : attrNames) {
        try {
            attrDefs.add(getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, attrsName));
        } catch (AttributeNotExistsException e) {
        // pass
        }
    }
    if (query.getGroupId() == null) {
        richMembers = convertMembersToRichMembersWithAttributes(sess, richMembers, attrDefs);
    } else {
        try {
            richMembers = convertMembersToRichMembersWithAttributes(sess, perunBl.getGroupsManagerBl().getGroupById(sess, query.getGroupId()), richMembers, attrDefs);
        } catch (GroupNotExistsException | MemberGroupMismatchException e) {
            throw new InternalErrorException(e);
        }
    }
    return new Paginated<>(richMembers, paginatedMembers.getOffset(), paginatedMembers.getPageSize(), paginatedMembers.getTotalCount());
}
Also used : MemberGroupMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) ParentGroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) RichMember(cz.metacentrum.perun.core.api.RichMember) Paginated(cz.metacentrum.perun.core.api.Paginated) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member)

Example 2 with Paginated

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

the class AuditMessagesManagerEntryIntegrationTest method getMessagesPage_allEntries.

@Test
public void getMessagesPage_allEntries() throws Exception {
    System.out.println(CLASS_NAME + "getMessagesPage_allEntries");
    for (int i = 0; i < 5; i++) {
        perun.getAuditer().logWithoutTransaction(sess, new StringMessageEvent("Test cislo: " + i));
    }
    MessagesPageQuery query = new MessagesPageQuery(5, 0, SortingOrder.DESCENDING);
    Paginated<AuditMessage> messages = perun.getAuditMessagesManager().getMessagesPage(sess, query);
    assertThat(messages.getData().size()).isEqualTo(5);
    assertThat(messages.getData().stream().map(a -> a.getEvent().getMessage()).collect(Collectors.toList())).isEqualTo(List.of("Test cislo: 4", "Test cislo: 3", "Test cislo: 2", "Test cislo: 1", "Test cislo: 0"));
}
Also used : StringMessageEvent(cz.metacentrum.perun.audit.events.StringMessageEvent) MessagesPageQuery(cz.metacentrum.perun.core.api.MessagesPageQuery) Facility(cz.metacentrum.perun.core.api.Facility) WrongRangeOfCountException(cz.metacentrum.perun.core.api.exceptions.WrongRangeOfCountException) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) AuditMessage(cz.metacentrum.perun.core.api.AuditMessage) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AuditMessagesManagerImpl(cz.metacentrum.perun.core.impl.AuditMessagesManagerImpl) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Paginated(cz.metacentrum.perun.core.api.Paginated) Test(org.junit.Test) AuditMessagesManager(cz.metacentrum.perun.core.api.AuditMessagesManager) EnrichedSponsorship(cz.metacentrum.perun.core.api.EnrichedSponsorship) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) SponsorshipExpired(cz.metacentrum.perun.audit.events.ExpirationNotifScheduler.SponsorshipExpired) Collectors(java.util.stream.Collectors) List(java.util.List) SponsorshipEstablished(cz.metacentrum.perun.audit.events.MembersManagerEvents.SponsorshipEstablished) LocalDate(java.time.LocalDate) SortingOrder(cz.metacentrum.perun.core.api.SortingOrder) FacilityCreated(cz.metacentrum.perun.audit.events.FacilityManagerEvents.FacilityCreated) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) AuditMessage(cz.metacentrum.perun.core.api.AuditMessage) StringMessageEvent(cz.metacentrum.perun.audit.events.StringMessageEvent) MessagesPageQuery(cz.metacentrum.perun.core.api.MessagesPageQuery) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

Paginated (cz.metacentrum.perun.core.api.Paginated)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AuditEvent (cz.metacentrum.perun.audit.events.AuditEvent)1 SponsorshipExpired (cz.metacentrum.perun.audit.events.ExpirationNotifScheduler.SponsorshipExpired)1 FacilityCreated (cz.metacentrum.perun.audit.events.FacilityManagerEvents.FacilityCreated)1 SponsorshipEstablished (cz.metacentrum.perun.audit.events.MembersManagerEvents.SponsorshipEstablished)1 StringMessageEvent (cz.metacentrum.perun.audit.events.StringMessageEvent)1 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)1 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)1 AuditMessage (cz.metacentrum.perun.core.api.AuditMessage)1 AuditMessagesManager (cz.metacentrum.perun.core.api.AuditMessagesManager)1 EnrichedSponsorship (cz.metacentrum.perun.core.api.EnrichedSponsorship)1 Facility (cz.metacentrum.perun.core.api.Facility)1 Member (cz.metacentrum.perun.core.api.Member)1 MessagesPageQuery (cz.metacentrum.perun.core.api.MessagesPageQuery)1 RichMember (cz.metacentrum.perun.core.api.RichMember)1 SortingOrder (cz.metacentrum.perun.core.api.SortingOrder)1 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)1 GroupNotExistsException (cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1