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);
});
}
}
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;
}
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);
}
Aggregations