Search in sources :

Example 1 with Sort

use of org.eclipse.hono.service.management.Sort in project hono by eclipse.

the class DelegatingTenantManagementHttpEndpoint method searchTenants.

private void searchTenants(final RoutingContext ctx) {
    final Span span = TracingHelper.buildServerChildSpan(tracer, TracingHandler.serverSpanContext(ctx), SPAN_NAME_SEARCH_TENANT, getClass().getSimpleName()).start();
    final Future<Integer> pageSize = getRequestParameter(ctx, RegistryManagementConstants.PARAM_PAGE_SIZE, DEFAULT_PAGE_SIZE, CONVERTER_INT, value -> value >= MIN_PAGE_SIZE && value <= MAX_PAGE_SIZE);
    final Future<Integer> pageOffset = getRequestParameter(ctx, RegistryManagementConstants.PARAM_PAGE_OFFSET, DEFAULT_PAGE_OFFSET, CONVERTER_INT, value -> value >= MIN_PAGE_OFFSET);
    final Future<List<Filter>> filters = decodeJsonFromRequestParameter(ctx, RegistryManagementConstants.PARAM_FILTER_JSON, Filter.class);
    final Future<List<Sort>> sortOptions = decodeJsonFromRequestParameter(ctx, RegistryManagementConstants.PARAM_SORT_JSON, Sort.class);
    CompositeFuture.all(pageSize, pageOffset, filters, sortOptions).compose(ok -> getService().searchTenants(pageSize.result(), pageOffset.result(), filters.result(), sortOptions.result(), span)).onSuccess(operationResult -> writeResponse(ctx, operationResult, span)).onFailure(t -> failRequest(ctx, t, span)).onComplete(s -> span.finish());
}
Also used : HttpURLConnection(java.net.HttpURLConnection) DecodeException(io.vertx.core.json.DecodeException) AbstractDelegatingRegistryHttpEndpoint(org.eclipse.hono.service.management.AbstractDelegatingRegistryHttpEndpoint) Filter(org.eclipse.hono.service.management.Filter) Router(io.vertx.ext.web.Router) ClientErrorException(org.eclipse.hono.client.ClientErrorException) RoutingContext(io.vertx.ext.web.RoutingContext) BodyHandler(io.vertx.ext.web.handler.BodyHandler) ServiceConfigProperties(org.eclipse.hono.config.ServiceConfigProperties) TracingHandler(org.eclipse.hono.service.http.TracingHandler) CompositeFuture(io.vertx.core.CompositeFuture) Sort(org.eclipse.hono.service.management.Sort) JsonObject(io.vertx.core.json.JsonObject) TracingHelper(org.eclipse.hono.tracing.TracingHelper) RegistryManagementConstants(org.eclipse.hono.util.RegistryManagementConstants) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Set(java.util.Set) HttpHeaders(io.vertx.core.http.HttpHeaders) Future(io.vertx.core.Future) Objects(java.util.Objects) List(java.util.List) HttpMethod(io.vertx.core.http.HttpMethod) Optional(java.util.Optional) Span(io.opentracing.Span) Id(org.eclipse.hono.service.management.Id) List(java.util.List) Span(io.opentracing.Span)

Example 2 with Sort

use of org.eclipse.hono.service.management.Sort in project hono by eclipse.

the class DelegatingDeviceManagementHttpEndpoint method doSearchDevices.

private void doSearchDevices(final RoutingContext ctx) {
    final Span span = TracingHelper.buildServerChildSpan(tracer, TracingHandler.serverSpanContext(ctx), SPAN_NAME_SEARCH_DEVICES, getClass().getSimpleName()).start();
    final String tenantId = getTenantParam(ctx);
    final Future<Integer> pageSize = getRequestParameter(ctx, RegistryManagementConstants.PARAM_PAGE_SIZE, DEFAULT_PAGE_SIZE, CONVERTER_INT, value -> value >= MIN_PAGE_SIZE && value <= MAX_PAGE_SIZE);
    final Future<Integer> pageOffset = getRequestParameter(ctx, RegistryManagementConstants.PARAM_PAGE_OFFSET, DEFAULT_PAGE_OFFSET, CONVERTER_INT, value -> value >= MIN_PAGE_OFFSET);
    final Future<List<Filter>> filters = decodeJsonFromRequestParameter(ctx, RegistryManagementConstants.PARAM_FILTER_JSON, Filter.class);
    final Future<List<Sort>> sortOptions = decodeJsonFromRequestParameter(ctx, RegistryManagementConstants.PARAM_SORT_JSON, Sort.class);
    CompositeFuture.all(pageSize, pageOffset, filters, sortOptions).onSuccess(ok -> TracingHelper.TAG_TENANT_ID.set(span, tenantId)).compose(ok -> getService().searchDevices(tenantId, pageSize.result(), pageOffset.result(), filters.result(), sortOptions.result(), span)).onSuccess(operationResult -> writeResponse(ctx, operationResult, span)).onFailure(t -> failRequest(ctx, t, span)).onComplete(s -> span.finish());
}
Also used : HttpURLConnection(java.net.HttpURLConnection) DecodeException(io.vertx.core.json.DecodeException) AbstractDelegatingRegistryHttpEndpoint(org.eclipse.hono.service.management.AbstractDelegatingRegistryHttpEndpoint) Filter(org.eclipse.hono.service.management.Filter) Router(io.vertx.ext.web.Router) ClientErrorException(org.eclipse.hono.client.ClientErrorException) RoutingContext(io.vertx.ext.web.RoutingContext) BodyHandler(io.vertx.ext.web.handler.BodyHandler) ServiceConfigProperties(org.eclipse.hono.config.ServiceConfigProperties) TracingHandler(org.eclipse.hono.service.http.TracingHandler) CompositeFuture(io.vertx.core.CompositeFuture) Sort(org.eclipse.hono.service.management.Sort) JsonObject(io.vertx.core.json.JsonObject) TracingHelper(org.eclipse.hono.tracing.TracingHelper) RegistryManagementConstants(org.eclipse.hono.util.RegistryManagementConstants) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Set(java.util.Set) HttpHeaders(io.vertx.core.http.HttpHeaders) Future(io.vertx.core.Future) Objects(java.util.Objects) List(java.util.List) HttpMethod(io.vertx.core.http.HttpMethod) Optional(java.util.Optional) Span(io.opentracing.Span) Id(org.eclipse.hono.service.management.Id) List(java.util.List) Span(io.opentracing.Span)

Example 3 with Sort

use of org.eclipse.hono.service.management.Sort in project hono by eclipse.

the class AbstractDeviceManagementSearchDevicesTest method testSearchDevicesWithPageOffset.

/**
 * Verifies that a request to search devices with valid page offset succeeds and the result is in accordance with
 * the specified page offset.
 *
 * @param ctx The vert.x test context.
 */
@Test
default void testSearchDevicesWithPageOffset(final VertxTestContext ctx) {
    final String tenantId = DeviceRegistryUtils.getUniqueIdentifier();
    final int pageSize = 1;
    final int pageOffset = 1;
    final Filter filter = new Filter("/enabled", true);
    final Sort sortOption = new Sort("/id");
    sortOption.setDirection(Sort.Direction.DESC);
    createDevices(tenantId, Map.of("testDevice1", new Device().setEnabled(true), "testDevice2", new Device().setEnabled(true))).compose(ok -> getDeviceManagementService().searchDevices(tenantId, pageSize, pageOffset, List.of(filter), List.of(sortOption), NoopSpan.INSTANCE).onComplete(ctx.succeeding(s -> {
        ctx.verify(() -> {
            assertThat(s.getStatus()).isEqualTo(HttpURLConnection.HTTP_OK);
            final SearchResult<DeviceWithId> searchResult = s.getPayload();
            assertThat(searchResult.getTotal()).isEqualTo(2);
            assertThat(searchResult.getResult()).hasSize(1);
            assertThat(searchResult.getResult().get(0).getId()).isEqualTo("testDevice1");
        });
        ctx.completeNow();
    })));
}
Also used : Filter(org.eclipse.hono.service.management.Filter) Sort(org.eclipse.hono.service.management.Sort) Test(org.junit.jupiter.api.Test)

Example 4 with Sort

use of org.eclipse.hono.service.management.Sort in project hono by eclipse.

the class AbstractTenantManagementSearchTenantsTest method testSearchTenantsWithSortOptions.

/**
 * Verifies that a request to search tenants with a sort option succeeds and the result is in accordance with the
 * specified sort option.
 *
 * @param ctx The vert.x test context.
 */
@Test
default void testSearchTenantsWithSortOptions(final VertxTestContext ctx) {
    final String tenantId1 = DeviceRegistryUtils.getUniqueIdentifier();
    final String tenantId2 = DeviceRegistryUtils.getUniqueIdentifier();
    final String tenantId3 = DeviceRegistryUtils.getUniqueIdentifier();
    final int pageSize = 1;
    final int pageOffset = 0;
    final Filter filter = new Filter("/enabled", true);
    final Sort sortOption1 = new Sort("/ext/group");
    final Sort sortOption2 = new Sort("/ext/id");
    sortOption1.setDirection(Sort.Direction.DESC);
    sortOption2.setDirection(Sort.Direction.ASC);
    createTenants(Map.of(tenantId1, new Tenant().setEnabled(false).setExtensions(Map.of("id", "1", "group", "B")), tenantId2, new Tenant().setEnabled(true).setExtensions(Map.of("id", "2", "group", "B")), tenantId3, new Tenant().setEnabled(true).setExtensions(Map.of("id", "3", "group", "B")))).onFailure(ctx::failNow).compose(ok -> getTenantManagementService().searchTenants(pageSize, pageOffset, List.of(filter), List.of(sortOption1, sortOption2), NoopSpan.INSTANCE)).onComplete(ctx.succeeding(s -> {
        ctx.verify(() -> {
            assertThat(s.getStatus()).isEqualTo(HttpURLConnection.HTTP_OK);
            final SearchResult<TenantWithId> searchResult = s.getPayload();
            assertThat(searchResult.getTotal()).isEqualTo(2);
            assertThat(searchResult.getResult()).hasSize(1);
            assertThat(searchResult.getResult().get(0).getId()).isEqualTo(tenantId2);
        });
        ctx.completeNow();
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) Filter(org.eclipse.hono.service.management.Filter) Truth.assertThat(com.google.common.truth.Truth.assertThat) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) Collectors(java.util.stream.Collectors) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) CompositeFuture(io.vertx.core.CompositeFuture) List(java.util.List) Sort(org.eclipse.hono.service.management.Sort) Adapter(org.eclipse.hono.util.Adapter) SearchResult(org.eclipse.hono.service.management.SearchResult) Map(java.util.Map) Optional(java.util.Optional) NoopSpan(io.opentracing.noop.NoopSpan) DeviceRegistryUtils(org.eclipse.hono.deviceregistry.util.DeviceRegistryUtils) Filter(org.eclipse.hono.service.management.Filter) Sort(org.eclipse.hono.service.management.Sort) SearchResult(org.eclipse.hono.service.management.SearchResult) Test(org.junit.jupiter.api.Test)

Example 5 with Sort

use of org.eclipse.hono.service.management.Sort in project hono by eclipse.

the class AbstractTenantManagementSearchTenantsTest method testSearchTenantsWithCardToMatchSingleCharacter.

/**
 * Verifies that a request to search tenants with filters containing the wildcard character '?'
 * and matching tenants are found.
 *
 * @param ctx The vert.x test context.
 */
@Test
default void testSearchTenantsWithCardToMatchSingleCharacter(final VertxTestContext ctx) {
    final String tenantId1 = DeviceRegistryUtils.getUniqueIdentifier();
    final String tenantId2 = DeviceRegistryUtils.getUniqueIdentifier();
    final String tenantId3 = DeviceRegistryUtils.getUniqueIdentifier();
    final int pageSize = 1;
    final int pageOffset = 0;
    final Filter filter1 = new Filter("/ext/id", "testTenant-?");
    final Filter filter2 = new Filter("/ext/value", "test$?Value");
    final Sort sortOption = new Sort("/ext/id");
    sortOption.setDirection(Sort.Direction.DESC);
    createTenants(Map.of(tenantId1, new Tenant().setEnabled(false).setExtensions(Map.of("id", "testTenant-x", "value", "test$Value")), tenantId2, new Tenant().setEnabled(true).setExtensions(Map.of("id", "testTenant-2", "value", "test$2Value")), tenantId3, new Tenant().setEnabled(true).setExtensions(Map.of("id", "testTenant-3", "value", "test$3Value")))).onFailure(ctx::failNow).compose(ok -> getTenantManagementService().searchTenants(pageSize, pageOffset, List.of(filter1, filter2), List.of(sortOption), NoopSpan.INSTANCE)).onComplete(ctx.succeeding(s -> {
        ctx.verify(() -> {
            assertThat(s.getStatus()).isEqualTo(HttpURLConnection.HTTP_OK);
            final SearchResult<TenantWithId> searchResult = s.getPayload();
            assertThat(searchResult.getTotal()).isEqualTo(2);
            assertThat(searchResult.getResult()).hasSize(1);
            assertThat(searchResult.getResult().get(0).getId()).isEqualTo(tenantId3);
        });
        ctx.completeNow();
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) Filter(org.eclipse.hono.service.management.Filter) Truth.assertThat(com.google.common.truth.Truth.assertThat) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) Collectors(java.util.stream.Collectors) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) CompositeFuture(io.vertx.core.CompositeFuture) List(java.util.List) Sort(org.eclipse.hono.service.management.Sort) Adapter(org.eclipse.hono.util.Adapter) SearchResult(org.eclipse.hono.service.management.SearchResult) Map(java.util.Map) Optional(java.util.Optional) NoopSpan(io.opentracing.noop.NoopSpan) DeviceRegistryUtils(org.eclipse.hono.deviceregistry.util.DeviceRegistryUtils) Filter(org.eclipse.hono.service.management.Filter) Sort(org.eclipse.hono.service.management.Sort) SearchResult(org.eclipse.hono.service.management.SearchResult) Test(org.junit.jupiter.api.Test)

Aggregations

Filter (org.eclipse.hono.service.management.Filter)13 Sort (org.eclipse.hono.service.management.Sort)13 Future (io.vertx.core.Future)10 HttpURLConnection (java.net.HttpURLConnection)10 List (java.util.List)10 Optional (java.util.Optional)10 Test (org.junit.jupiter.api.Test)9 SearchResult (org.eclipse.hono.service.management.SearchResult)7 Truth.assertThat (com.google.common.truth.Truth.assertThat)6 CompositeFuture (io.vertx.core.CompositeFuture)6 Collectors (java.util.stream.Collectors)6 Span (io.opentracing.Span)5 NoopSpan (io.opentracing.noop.NoopSpan)5 JsonObject (io.vertx.core.json.JsonObject)5 VertxTestContext (io.vertx.junit5.VertxTestContext)5 Map (java.util.Map)5 DeviceRegistryUtils (org.eclipse.hono.deviceregistry.util.DeviceRegistryUtils)5 RegistryManagementConstants (org.eclipse.hono.util.RegistryManagementConstants)5 Promise (io.vertx.core.Promise)4 Objects (java.util.Objects)4