Search in sources :

Example 1 with ListResponseJsonSerializer

use of io.jans.scim.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 io.jans.scim.service.scim2.serialization.ListResponseJsonSerializer 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);
}
Also used : ListResponse(io.jans.scim.model.scim2.ListResponse) ListResponseJsonSerializer(io.jans.scim.service.scim2.serialization.ListResponseJsonSerializer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Example 3 with ListResponseJsonSerializer

use of io.jans.scim.service.scim2.serialization.ListResponseJsonSerializer 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;
}
Also used : SearchRequest(io.jans.scim.model.scim2.SearchRequest) ListResponse(io.jans.scim.model.scim2.ListResponse) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ListResponseJsonSerializer(io.jans.scim.service.scim2.serialization.ListResponseJsonSerializer) URI(java.net.URI) Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(io.jans.scim.service.scim2.interceptor.RefAdjusted) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ProtectedApi(io.jans.scim.service.filter.ProtectedApi)

Example 4 with ListResponseJsonSerializer

use of io.jans.scim.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 (com.fasterxml.jackson.databind.ObjectMapper)2 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)2 ListResponse (io.jans.scim.model.scim2.ListResponse)2 ListResponseJsonSerializer (io.jans.scim.service.scim2.serialization.ListResponseJsonSerializer)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Response (javax.ws.rs.core.Response)2 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 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 SearchRequest (io.jans.scim.model.scim2.SearchRequest)1 ProtectedApi (io.jans.scim.service.filter.ProtectedApi)1 RefAdjusted (io.jans.scim.service.scim2.interceptor.RefAdjusted)1 Consumes (javax.ws.rs.Consumes)1 DefaultValue (javax.ws.rs.DefaultValue)1 HeaderParam (javax.ws.rs.HeaderParam)1 POST (javax.ws.rs.POST)1