use of org.gluu.oxtrust.service.scim2.serialization.ListResponseJsonSerializer in project oxTrust by GluuFederation.
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 org.gluu.oxtrust.service.scim2.serialization.ListResponseJsonSerializer in project oxTrust by GluuFederation.
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
@RefAdjusted
@ApiOperation(value = "General search POST /.search", notes = "Returns a list of resources (https://tools.ietf.org/html/rfc7644#section-3.4.3)", response = ListResponse.class)
public Response search(@ApiParam(value = "SearchRequest", required = true) 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<JsonNode>();
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;
}
Aggregations