Search in sources :

Example 1 with ListResponseJsonSerializer

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);
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) ListResponseJsonSerializer(org.gluu.oxtrust.service.scim2.serialization.ListResponseJsonSerializer) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule)

Example 2 with ListResponseJsonSerializer

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;
}
Also used : SearchRequest(org.gluu.oxtrust.model.scim2.SearchRequest) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) ArrayList(java.util.ArrayList) JsonNode(org.codehaus.jackson.JsonNode) ListResponseJsonSerializer(org.gluu.oxtrust.service.scim2.serialization.ListResponseJsonSerializer) URI(java.net.URI) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule) RefAdjusted(org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Aggregations

ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 SimpleModule (org.codehaus.jackson.map.module.SimpleModule)2 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)2 ListResponseJsonSerializer (org.gluu.oxtrust.service.scim2.serialization.ListResponseJsonSerializer)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Response (javax.ws.rs.core.Response)1 JsonNode (org.codehaus.jackson.JsonNode)1 SearchRequest (org.gluu.oxtrust.model.scim2.SearchRequest)1 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)1 RefAdjusted (org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted)1