use of org.apache.syncope.ext.scimv2.api.data.ListResponse in project syncope by apache.
the class SCIMITCase method list.
@Test
public void list() throws IOException {
assumeTrue(SCIMDetector.isSCIMAvailable(webClient()));
Response response = webClient().path("Groups").query("count", 1100000).get();
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
SCIMError error = response.readEntity(SCIMError.class);
assertEquals(ErrorType.tooMany, error.getScimType());
response = webClient().path("Groups").query("sortBy", "displayName").query("count", 11).get();
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
assertEquals(SCIMConstants.APPLICATION_SCIM_JSON, StringUtils.substringBefore(response.getHeaderString(HttpHeaders.CONTENT_TYPE), ";"));
ListResponse<SCIMGroup> result = response.readEntity(new GenericType<ListResponse<SCIMGroup>>() {
});
assertNotNull(result);
assertTrue(result.getTotalResults() > 0);
assertEquals(11, result.getItemsPerPage());
assertFalse(result.getResources().isEmpty());
result.getResources().forEach(group -> {
assertNotNull(group.getId());
assertNotNull(group.getDisplayName());
});
}
use of org.apache.syncope.ext.scimv2.api.data.ListResponse in project syncope by apache.
the class AbstractService method doSearch.
@SuppressWarnings("unchecked")
protected ListResponse<R> doSearch(final Resource type, final SCIMSearchRequest request) {
if (type == null) {
throw new UnsupportedOperationException();
}
if (request.getCount() > confManager().get().getFilterMaxResults()) {
throw new BadRequestException(ErrorType.tooMany, "Too many results requested");
}
SearchCondVisitor visitor = new SearchCondVisitor(type, confManager().get());
int startIndex = request.getStartIndex() <= 1 ? 1 : (request.getStartIndex() / AnyDAO.DEFAULT_PAGE_SIZE) + 1;
int itemsPerPage = request.getCount() <= 1 ? AnyDAO.DEFAULT_PAGE_SIZE : request.getCount();
List<OrderByClause> sort;
if (request.getSortBy() == null) {
sort = Collections.<OrderByClause>emptyList();
} else {
OrderByClause clause = new OrderByClause();
clause.setField(visitor.createAttributeCond(request.getSortBy()).getSchema());
clause.setDirection(request.getSortOrder() == null || request.getSortOrder() == SortOrder.ascending ? OrderByClause.Direction.ASC : OrderByClause.Direction.DESC);
sort = Collections.singletonList(clause);
}
Pair<Integer, ? extends List<? extends AnyTO>> result = anyLogic(type).search(StringUtils.isBlank(request.getFilter()) ? null : SearchCondConverter.convert(visitor, request.getFilter()), startIndex, itemsPerPage, sort, SyncopeConstants.ROOT_REALM, false);
if (result.getLeft() > confManager().get().getFilterMaxResults()) {
throw new BadRequestException(ErrorType.tooMany, "Too many results found");
}
ListResponse<R> response = new ListResponse<>(result.getLeft(), startIndex == 1 ? 1 : startIndex - 1, itemsPerPage);
result.getRight().forEach(anyTO -> {
SCIMResource resource = null;
if (anyTO instanceof UserTO) {
resource = binder().toSCIMUser((UserTO) anyTO, uriInfo.getAbsolutePathBuilder().path(anyTO.getKey()).build().toASCIIString(), request.getAttributes(), request.getExcludedAttributes());
} else if (anyTO instanceof GroupTO) {
resource = binder().toSCIMGroup((GroupTO) anyTO, uriInfo.getAbsolutePathBuilder().path(anyTO.getKey()).build().toASCIIString(), request.getAttributes(), request.getExcludedAttributes());
}
if (resource != null) {
response.getResources().add((R) resource);
}
});
return response;
}
use of org.apache.syncope.ext.scimv2.api.data.ListResponse in project syncope by apache.
the class SCIMITCase method search.
@Test
public void search() {
assumeTrue(SCIMDetector.isSCIMAvailable(webClient()));
// invalid filter
Response response = webClient().path("Groups").query("filter", "invalid").get();
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
SCIMError error = response.readEntity(SCIMError.class);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), error.getStatus());
assertEquals(ErrorType.invalidFilter, error.getScimType());
// eq
response = webClient().path("Groups").query("filter", "displayName eq \"additional\"").get();
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
assertEquals(SCIMConstants.APPLICATION_SCIM_JSON, StringUtils.substringBefore(response.getHeaderString(HttpHeaders.CONTENT_TYPE), ";"));
ListResponse<SCIMGroup> groups = response.readEntity(new GenericType<ListResponse<SCIMGroup>>() {
});
assertNotNull(groups);
assertEquals(1, groups.getTotalResults());
SCIMGroup additional = groups.getResources().get(0);
assertEquals("additional", additional.getDisplayName());
// eq via POST
SCIMSearchRequest request = new SCIMSearchRequest("displayName eq \"additional\"", null, null, null, null);
response = webClient().path("Groups").path("/.search").post(request);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
assertEquals(SCIMConstants.APPLICATION_SCIM_JSON, StringUtils.substringBefore(response.getHeaderString(HttpHeaders.CONTENT_TYPE), ";"));
groups = response.readEntity(new GenericType<ListResponse<SCIMGroup>>() {
});
assertNotNull(groups);
assertEquals(1, groups.getTotalResults());
additional = groups.getResources().get(0);
assertEquals("additional", additional.getDisplayName());
// gt
UserTO newUser = userService.create(UserITCase.getUniqueSampleTO("scimsearch@syncope.apache.org"), true).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
}).getEntity();
Date value = new Date(newUser.getCreationDate().getTime() - 1000);
response = webClient().path("Users").query("filter", "meta.created gt \"" + DATE_FORMAT.get().format(value) + "\"").get();
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
assertEquals(SCIMConstants.APPLICATION_SCIM_JSON, StringUtils.substringBefore(response.getHeaderString(HttpHeaders.CONTENT_TYPE), ";"));
ListResponse<SCIMUser> users = response.readEntity(new GenericType<ListResponse<SCIMUser>>() {
});
assertNotNull(users);
assertEquals(1, users.getTotalResults());
SCIMUser newSCIMUser = users.getResources().get(0);
assertEquals(newUser.getUsername(), newSCIMUser.getUserName());
}
Aggregations