Search in sources :

Example 16 with SearchRequest

use of io.jans.scim.model.scim2.SearchRequest in project jans by JanssenProject.

the class SimpleSearchUserTest method searchNoMatches.

@Test(dependsOnMethods = "create", groups = "search")
public void searchNoMatches() {
    String nowIsoDateTimeString = Instant.ofEpochMilli(System.currentTimeMillis()).toString();
    SearchRequest sr = new SearchRequest();
    sr.setFilter(String.format("urn:ietf:params:scim:schemas:extension:gluu:2.0:User:scimCustomThird eq 1 and displayName eq \"%s\" " + "and addresses[postalCode ne null or type eq null] and meta.lastModified gt \"%s\"", "test", nowIsoDateTimeString));
    Response response = client.searchUsersPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse listResponse = response.readEntity(ListResponse.class);
    assertNull(listResponse.getResources());
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) SearchRequest(io.jans.scim.model.scim2.SearchRequest) ListResponse(io.jans.scim.model.scim2.ListResponse) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 17 with SearchRequest

use of io.jans.scim.model.scim2.SearchRequest in project jans by JanssenProject.

the class ComplexSearchUserTest method searchExcludedAttributesParam.

@Test
public void searchExcludedAttributesParam() {
    int count = 3;
    List<String> attrList = Arrays.asList("x509Certificates", "entitlements", "roles", "ims", "phoneNumbers", "addresses", "emails", "groups");
    logger.debug("Searching at most {} users using POST verb", count);
    logger.debug("Sorted by displayName ascending");
    logger.debug("Excluding the attributes {}", attrList);
    SearchRequest sr = new SearchRequest();
    sr.setFilter("displayName pr");
    sr.setSortBy("displayName");
    sr.setSortOrder("descending");
    // Generate a string with the attributes to exclude
    sr.setExcludedAttributes(attrList.toString().replaceFirst("\\[", "").replaceFirst("]", ""));
    sr.setCount(count);
    Response response = client.searchUsersPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse listResponse = response.readEntity(ListResponse.class);
    if (listResponse.getResources().size() < count)
        logger.warn("Less than {} users satisfying the criteria. TESTER please check manually", count);
    else {
        // Obtain an array of results
        UserResource[] users = listResponse.getResources().stream().map(usrClass::cast).collect(Collectors.toList()).toArray(new UserResource[0]);
        assertEquals(users.length, count);
        // Verify attributes were excluded
        for (UserResource u : users) {
            assertNull(u.getX509Certificates());
            assertNull(u.getEntitlements());
            assertNull(u.getRoles());
            assertNull(u.getIms());
            assertNull(u.getPhoneNumbers());
            assertNull(u.getAddresses());
            assertNull(u.getEmails());
        }
        boolean correctSorting = true;
        for (int i = 1; i < users.length && correctSorting; i++) {
            String displayName = users[i - 1].getDisplayName();
            String displayName2 = users[i].getDisplayName();
            // Check if second string is less or equal than first
            correctSorting = displayName.compareTo(displayName2) >= 0;
        }
        if (!correctSorting) {
            // LDAP may ignore case sensitivity, try again using lowercasing
            correctSorting = true;
            for (int i = 1; i < users.length && correctSorting; i++) {
                String displayName = users[i - 1].getDisplayName().toLowerCase();
                String displayName2 = users[i].getDisplayName().toLowerCase();
                // Check if second string is less or equal than first
                correctSorting = displayName.compareTo(displayName2) >= 0;
            }
        }
        assertTrue(correctSorting);
    }
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) SearchRequest(io.jans.scim.model.scim2.SearchRequest) ListResponse(io.jans.scim.model.scim2.ListResponse) UserResource(io.jans.scim.model.scim2.user.UserResource) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 18 with SearchRequest

use of io.jans.scim.model.scim2.SearchRequest in project jans by JanssenProject.

the class ComplexSearchUserTest method searchSortByDate.

// This test is disabled to avoid problems in attribute excludeMetaLastMod being inconsistent with updatedAt in testing server
// @Test
public void searchSortByDate() {
    SearchRequest sr = new SearchRequest();
    sr.setFilter("userName pr");
    sr.setSortBy("meta.lastModified");
    sr.setAttributes(Collections.singletonList(sr.getSortBy()));
    Response response = client.searchUsersPost(sr);
    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]);
    for (int i = 1; i < users.length; i++) {
        String lastMod1 = users[i - 1].getMeta() == null ? null : users[i - 1].getMeta().getLastModified();
        String lastMod2 = users[i].getMeta() == null ? null : users[i].getMeta().getLastModified();
        if (// Both being non null is OK
        lastMod1 != null)
            assertNotNull(lastMod2);
        if (// If second is null, first must be
        lastMod2 == null)
            assertNull(lastMod1);
        if (lastMod1 != null && lastMod2 != null) {
            ZonedDateTime dt1 = ZonedDateTime.parse(lastMod1);
            ZonedDateTime dt2 = ZonedDateTime.parse(lastMod2);
            assertTrue(dt1.isEqual(dt2) || dt1.isBefore(dt2));
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) SearchRequest(io.jans.scim.model.scim2.SearchRequest) ListResponse(io.jans.scim.model.scim2.ListResponse) ZonedDateTime(java.time.ZonedDateTime) UserResource(io.jans.scim.model.scim2.user.UserResource)

Example 19 with SearchRequest

use of io.jans.scim.model.scim2.SearchRequest in project java-retail by googleapis.

the class SearchSimpleQuery method getSearchResponse.

public static SearchResponse getSearchResponse(String defaultSearchPlacementName) throws IOException {
    // TRY DIFFERENT QUERY PHRASES HERE:
    String queryPhrase = "Hoodie";
    String visitorId = UUID.randomUUID().toString();
    int pageSize = 10;
    SearchRequest searchRequest = SearchRequest.newBuilder().setPlacement(defaultSearchPlacementName).setQuery(queryPhrase).setVisitorId(visitorId).setPageSize(pageSize).build();
    System.out.println("Search request: " + searchRequest);
    try (SearchServiceClient client = SearchServiceClient.create()) {
        SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse();
        System.out.println("Search response: " + searchResponse);
        return searchResponse;
    }
}
Also used : SearchServiceClient(com.google.cloud.retail.v2.SearchServiceClient) SearchRequest(com.google.cloud.retail.v2.SearchRequest) SearchResponse(com.google.cloud.retail.v2.SearchResponse)

Example 20 with SearchRequest

use of io.jans.scim.model.scim2.SearchRequest in project java-retail by googleapis.

the class SearchWithBoostSpec method getSearchResponse.

public static SearchResponse getSearchResponse(String defaultSearchPlacementName) throws IOException {
    // TRY DIFFERENT CONDITIONS HERE:
    String searchQuery = "Tee";
    String condition = "(colorFamilies: ANY(\"Blue\"))";
    float boost = 0.0f;
    int pageSize = 10;
    String visitorId = UUID.randomUUID().toString();
    BoostSpec boostSpec = BoostSpec.newBuilder().addConditionBoostSpecs(ConditionBoostSpec.newBuilder().setCondition(condition).setBoost(boost).build()).build();
    SearchRequest searchRequest = SearchRequest.newBuilder().setPlacement(defaultSearchPlacementName).setQuery(searchQuery).setVisitorId(visitorId).setBoostSpec(boostSpec).setPageSize(pageSize).build();
    System.out.println("Search request: " + searchRequest);
    try (SearchServiceClient client = SearchServiceClient.create()) {
        SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse();
        System.out.println("Search response: " + searchResponse);
        return searchResponse;
    }
}
Also used : SearchServiceClient(com.google.cloud.retail.v2.SearchServiceClient) SearchRequest(com.google.cloud.retail.v2.SearchRequest) BoostSpec(com.google.cloud.retail.v2.SearchRequest.BoostSpec) ConditionBoostSpec(com.google.cloud.retail.v2.SearchRequest.BoostSpec.ConditionBoostSpec) SearchResponse(com.google.cloud.retail.v2.SearchResponse)

Aggregations

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