Search in sources :

Example 1 with SearchRequest

use of com.google.cloud.retail.v2.SearchRequest in project oxTrust by GluuFederation.

the class FidoDeviceWebServiceDecorator method searchDevices.

public Response searchDevices(String userId, String filter, Integer startIndex, Integer count, String sortBy, String sortOrder, String attrsList, String excludedAttrsList) {
    SearchRequest searchReq = new SearchRequest();
    Response response = prepareSearchRequest(searchReq.getSchemas(), filter, sortBy, sortOrder, startIndex, count, attrsList, excludedAttrsList, searchReq);
    if (response == null) {
        response = validateExistenceOfUser(userId);
        if (response == null) {
            response = service.searchDevices(userId, searchReq.getFilter(), searchReq.getStartIndex(), searchReq.getCount(), searchReq.getSortBy(), searchReq.getSortOrder(), searchReq.getAttributesStr(), searchReq.getExcludedAttributesStr());
        }
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) SearchRequest(org.gluu.oxtrust.model.scim2.SearchRequest)

Example 2 with SearchRequest

use of com.google.cloud.retail.v2.SearchRequest in project oxTrust by GluuFederation.

the class GroupWebServiceDecorator method searchGroups.

public Response searchGroups(String filter, Integer startIndex, Integer count, String sortBy, String sortOrder, String attrsList, String excludedAttrsList) {
    SearchRequest searchReq = new SearchRequest();
    Response response = prepareSearchRequest(searchReq.getSchemas(), filter, sortBy, sortOrder, startIndex, count, attrsList, excludedAttrsList, searchReq);
    if (response == null) {
        response = service.searchGroups(searchReq.getFilter(), searchReq.getStartIndex(), searchReq.getCount(), searchReq.getSortBy(), searchReq.getSortOrder(), searchReq.getAttributesStr(), searchReq.getExcludedAttributesStr());
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) SearchRequest(org.gluu.oxtrust.model.scim2.SearchRequest)

Example 3 with SearchRequest

use of com.google.cloud.retail.v2.SearchRequest in project oxTrust by GluuFederation.

the class ReferenceURIInterceptor method manage.

@AroundInvoke
public Object manage(InvocationContext ctx) throws Exception {
    Object[] params = ctx.getParameters();
    Annotation[][] annotations = ctx.getMethod().getParameterAnnotations();
    for (int i = 0; i < annotations.length; i++) {
        // Iterate over annotations found at every parameter
        for (Annotation annotation : annotations[i]) {
            if (annotation instanceof QueryParam) {
                String paramName = ((QueryParam) annotation).value();
                if ((paramName.equals(QUERY_PARAM_FILTER) || paramName.equals(QUERY_PARAM_ATTRIBUTES) || paramName.equals(QUERY_PARAM_EXCLUDED_ATTRS))) {
                    log.trace("Removing '$' char (if any) from {} param", paramName);
                    params[i] = dropDollar(params[i]);
                }
            }
        }
        if (params[i] != null && params[i] instanceof SearchRequest) {
            log.trace("Removing '$' char (if any) from SearchRequest object");
            SearchRequest sr = (SearchRequest) params[i];
            sr.setAttributes(dropDollar(sr.getAttributesStr()));
            sr.setExcludedAttributes(dropDollar(sr.getExcludedAttributesStr()));
            sr.setFilter(dropDollar(sr.getFilter()));
        }
    }
    log.debug("ReferenceURIInterceptor. manage exit");
    return ctx.proceed();
}
Also used : SearchRequest(org.gluu.oxtrust.model.scim2.SearchRequest) QueryParam(javax.ws.rs.QueryParam) Annotation(java.lang.annotation.Annotation) AroundInvoke(javax.interceptor.AroundInvoke)

Example 4 with SearchRequest

use of com.google.cloud.retail.v2.SearchRequest 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 5 with SearchRequest

use of com.google.cloud.retail.v2.SearchRequest in project jans by JanssenProject.

the class SpecialCharsTest method containabilityAll.

@SkipTest(databases = { "spanner", "couchbase" })
@Test
public void containabilityAll() {
    // Builds a long "and" based clause
    String filter = specialFilterLdapChars.stream().reduce("", (partial, next) -> partial + String.format(" and userName co \"%s\"", next));
    SearchRequest sr = new SearchRequest();
    // Drop beginning (namely " and ")
    sr.setFilter(filter.substring(4));
    sr.setAttributes("userName");
    // Search users whose usernames contain ALL the chars
    Response response = client.searchUsersPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    List<UserResource> resources = response.readEntity(ListResponse.class).getResources().stream().map(UserResource.class::cast).collect(Collectors.toList());
    String userName = resources.get(0).getUserName();
    assertEquals(resources.size(), 1);
    assertTrue(Stream.of(SPECIAL_CHARS).allMatch(userName::contains));
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) SearchRequest(io.jans.scim.model.scim2.SearchRequest) UserResource(io.jans.scim.model.scim2.user.UserResource) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test) SkipTest(io.jans.scim2.listener.SkipTest) BeforeTest(org.testng.annotations.BeforeTest) SkipTest(io.jans.scim2.listener.SkipTest)

Aggregations

Response (javax.ws.rs.core.Response)27 SearchRequest (io.jans.scim.model.scim2.SearchRequest)23 ListResponse (io.jans.scim.model.scim2.ListResponse)19 Test (org.testng.annotations.Test)14 UserBaseTest (io.jans.scim2.client.UserBaseTest)13 UserResource (io.jans.scim.model.scim2.user.UserResource)12 SearchRequest (com.google.cloud.retail.v2.SearchRequest)7 SearchResponse (com.google.cloud.retail.v2.SearchResponse)7 SearchServiceClient (com.google.cloud.retail.v2.SearchServiceClient)7 SearchRequest (org.gluu.oxtrust.model.scim2.SearchRequest)6 BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)5 SkipTest (io.jans.scim2.listener.SkipTest)5 URI (java.net.URI)5 BeforeTest (org.testng.annotations.BeforeTest)4 SCIMException (io.jans.scim.model.exception.SCIMException)3 URISyntaxException (java.net.URISyntaxException)3 ArrayList (java.util.ArrayList)3 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)3 DuplicateEntryException (io.jans.orm.exception.operation.DuplicateEntryException)2 GroupResource (io.jans.scim.model.scim2.group.GroupResource)2