Search in sources :

Example 1 with PagedConnObjectTOResult

use of org.apache.syncope.common.lib.to.PagedConnObjectTOResult in project syncope by apache.

the class ResourceITCase method listConnObjects.

@Test
public void listConnObjects() {
    List<String> groupKeys = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        GroupTO group = GroupITCase.getSampleTO("group");
        group.getResources().add(RESOURCE_NAME_LDAP);
        group = createGroup(group).getEntity();
        groupKeys.add(group.getKey());
    }
    int totalRead = 0;
    Set<String> read = new HashSet<>();
    try {
        ConnObjectTOListQuery.Builder builder = new ConnObjectTOListQuery.Builder().size(10);
        PagedConnObjectTOResult list;
        do {
            list = null;
            boolean succeeded = false;
            // needed because ApacheDS seems to randomly fail when searching with cookie
            for (int i = 0; i < 5 && !succeeded; i++) {
                try {
                    list = resourceService.listConnObjects(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), builder.build());
                    succeeded = true;
                } catch (SyncopeClientException e) {
                    assertEquals(ClientExceptionType.ConnectorException, e.getType());
                }
            }
            assertNotNull(list);
            totalRead += list.getResult().size();
            read.addAll(list.getResult().stream().map(input -> input.getAttr(ConnIdSpecialName.NAME).get().getValues().get(0)).collect(Collectors.toList()));
            if (list.getPagedResultsCookie() != null) {
                builder.pagedResultsCookie(list.getPagedResultsCookie());
            }
        } while (list.getPagedResultsCookie() != null);
        assertEquals(totalRead, read.size());
        assertTrue(totalRead >= 10);
    } finally {
        groupKeys.forEach(key -> {
            groupService.delete(key);
        });
    }
}
Also used : ArrayList(java.util.ArrayList) ConnObjectTOListQuery(org.apache.syncope.common.rest.api.beans.ConnObjectTOListQuery) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PagedConnObjectTOResult(org.apache.syncope.common.lib.to.PagedConnObjectTOResult) GroupTO(org.apache.syncope.common.lib.to.GroupTO) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 2 with PagedConnObjectTOResult

use of org.apache.syncope.common.lib.to.PagedConnObjectTOResult in project syncope by apache.

the class ResourceServiceImpl method listConnObjects.

@Override
public PagedConnObjectTOResult listConnObjects(final String key, final String anyTypeKey, final ConnObjectTOListQuery listQuery) {
    Pair<SearchResult, List<ConnObjectTO>> list = logic.listConnObjects(key, anyTypeKey, listQuery.getSize(), listQuery.getPagedResultsCookie(), getOrderByClauses(listQuery.getOrderBy()));
    PagedConnObjectTOResult result = new PagedConnObjectTOResult();
    if (list.getLeft() != null) {
        result.setAllResultsReturned(list.getLeft().isAllResultsReturned());
        result.setPagedResultsCookie(list.getLeft().getPagedResultsCookie());
        result.setRemainingPagedResults(list.getLeft().getRemainingPagedResults());
    }
    result.getResult().addAll(list.getRight());
    UriBuilder builder = uriInfo.getAbsolutePathBuilder();
    MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
    for (Map.Entry<String, List<String>> queryParam : queryParams.entrySet()) {
        builder = builder.queryParam(queryParam.getKey(), queryParam.getValue().toArray());
    }
    if (StringUtils.isNotBlank(result.getPagedResultsCookie())) {
        result.setNext(builder.replaceQueryParam(PARAM_CONNID_PAGED_RESULTS_COOKIE, result.getPagedResultsCookie()).replaceQueryParam(PARAM_SIZE, listQuery.getSize()).build());
    }
    return result;
}
Also used : SearchResult(org.identityconnectors.framework.common.objects.SearchResult) List(java.util.List) UriBuilder(javax.ws.rs.core.UriBuilder) Map(java.util.Map) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) PagedConnObjectTOResult(org.apache.syncope.common.lib.to.PagedConnObjectTOResult)

Example 3 with PagedConnObjectTOResult

use of org.apache.syncope.common.lib.to.PagedConnObjectTOResult in project syncope by apache.

the class ResourceRestClient method listConnObjects.

public Pair<String, List<ConnObjectTO>> listConnObjects(final String resource, final String anyTypeKey, final int size, final String pagedResultCookie, final SortParam<String> sort) {
    ConnObjectTOListQuery.Builder builder = new ConnObjectTOListQuery.Builder().pagedResultsCookie(pagedResultCookie).size(size).orderBy(toOrderBy(sort));
    final List<ConnObjectTO> result = new ArrayList<>();
    String nextPageResultCookie = null;
    PagedConnObjectTOResult list;
    try {
        list = getService(ResourceService.class).listConnObjects(resource, anyTypeKey, builder.build());
        result.addAll(list.getResult());
        nextPageResultCookie = list.getPagedResultsCookie();
    } catch (Exception e) {
        LOG.error("While listing objects on {} for any type {}", resource, anyTypeKey, e);
    }
    return Pair.of(nextPageResultCookie, result);
}
Also used : ConnObjectTOListQuery(org.apache.syncope.common.rest.api.beans.ConnObjectTOListQuery) ArrayList(java.util.ArrayList) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) PagedConnObjectTOResult(org.apache.syncope.common.lib.to.PagedConnObjectTOResult)

Aggregations

PagedConnObjectTOResult (org.apache.syncope.common.lib.to.PagedConnObjectTOResult)3 ArrayList (java.util.ArrayList)2 ConnObjectTOListQuery (org.apache.syncope.common.rest.api.beans.ConnObjectTOListQuery)2 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)1 GroupTO (org.apache.syncope.common.lib.to.GroupTO)1 SearchResult (org.identityconnectors.framework.common.objects.SearchResult)1 Test (org.junit.jupiter.api.Test)1