use of io.jans.scim.model.scim2.ListResponse in project jans by JanssenProject.
the class BaseScimWebService method getListResponseSerialized.
String getListResponseSerialized(int total, int startIndex, List<BaseScimResource> resources, String attrsList, String excludedAttrsList, boolean ignoreResults) throws IOException {
ListResponse listResponse = new ListResponse(startIndex, resources.size(), total);
listResponse.setResources(resources);
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule("ListResponseModule", Version.unknownVersion());
module.addSerializer(ListResponse.class, new ListResponseJsonSerializer(resourceSerializer, attrsList, excludedAttrsList, ignoreResults));
mapper.registerModule(module);
return mapper.writeValueAsString(listResponse);
}
use of io.jans.scim.model.scim2.ListResponse in project jans by JanssenProject.
the class SearchResourcesWebService method search.
@POST
@Consumes({ MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi(scopes = { "https://jans.io/scim/all-resources.search" })
@RefAdjusted
public Response search(SearchRequest searchRequest) {
SearchRequest searchReq = new SearchRequest();
Response response = prepareSearchRequest(searchRequest.getSchemas(), searchRequest.getFilter(), searchRequest.getSortBy(), searchRequest.getSortOrder(), searchRequest.getStartIndex(), searchRequest.getCount(), searchRequest.getAttributesStr(), searchRequest.getExcludedAttributesStr(), searchReq);
if (response == null) {
try {
List<JsonNode> resources = new ArrayList<>();
Pair<Integer, Integer> totals = computeResults(searchReq, resources);
ListResponseJsonSerializer custSerializer = new ListResponseJsonSerializer(resourceSerializer, searchReq.getAttributesStr(), searchReq.getExcludedAttributesStr(), searchReq.getCount() == 0);
if (resources.size() > 0)
custSerializer.setJsonResources(resources);
ObjectMapper objmapper = new ObjectMapper();
SimpleModule module = new SimpleModule("ListResponseModule", Version.unknownVersion());
module.addSerializer(ListResponse.class, custSerializer);
objmapper.registerModule(module);
// Provide to constructor original start index, and totals calculated in computeResults call
ListResponse listResponse = new ListResponse(searchReq.getStartIndex(), totals.getFirst(), totals.getSecond());
String json = objmapper.writeValueAsString(listResponse);
response = Response.ok(json).location(new URI(endpointUrl)).build();
} catch (Exception e) {
log.error("Failure at search method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
}
return response;
}
use of io.jans.scim.model.scim2.ListResponse in project jans by JanssenProject.
the class GroupAssignUserTest method getAdminId.
private String getAdminId() {
// Search the id of the admin user
SearchRequest sr = new SearchRequest();
sr.setFilter("userName eq \"admin\"");
Response response = client.searchUsersPost(sr);
assertEquals(response.getStatus(), OK.getStatusCode());
ListResponse lr = response.readEntity(ListResponse.class);
assertTrue(lr.getResources().size() > 0);
return lr.getResources().get(0).getId();
}
use of io.jans.scim.model.scim2.ListResponse in project jans by JanssenProject.
the class ComplexSearchUserTest method searchSortByExternalId.
@Test
public void searchSortByExternalId() {
Response response = client.searchUsers(null, null, null, "externalId", "descending", "externalId", null);
assertEquals(response.getStatus(), OK.getStatusCode());
ListResponse listResponse = response.readEntity(ListResponse.class);
UserResource[] users = listResponse.getResources().stream().map(usrClass::cast).collect(Collectors.toList()).toArray(new UserResource[0]);
assertEquals(listResponse.getStartIndex(), 1);
assertEquals(listResponse.getItemsPerPage(), users.length);
assertEquals(listResponse.getResources().size(), users.length);
for (int i = 1; i < users.length; i++) {
String exId1 = users[i - 1].getExternalId();
String exId2 = users[i].getExternalId();
if (exId2 != null)
assertNotNull(exId1);
if (exId1 == null)
assertNull(exId2);
if (// In descending order exId1 must be higher than exId2
exId1 != null && exId2 != null)
assertFalse(exId1.compareTo(exId2) < 0);
}
}
use of io.jans.scim.model.scim2.ListResponse in project jans by JanssenProject.
the class MultipleResourcesSearchTest method search5.
@Test(dependsOnMethods = "search4")
public void search5() {
// Means 1
sr.setStartIndex(null);
// Returns no resources, only total
sr.setCount(0);
Response response = client.searchResourcesPost(sr);
assertEquals(response.getStatus(), OK.getStatusCode());
ListResponse anotherLR = response.readEntity(ListResponse.class);
assertEquals(listResponse.getTotalResults(), anotherLR.getTotalResults());
assertNull(anotherLR.getResources());
// unassigned
assertEquals(anotherLR.getItemsPerPage(), 0);
// unassigned
assertEquals(anotherLR.getStartIndex(), 0);
}
Aggregations