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());
}
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());
}
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();
})));
}
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();
}));
}
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();
}));
}
Aggregations