use of org.eclipse.hono.service.management.OperationResult in project hono by eclipse.
the class AbstractDeviceManagementService method updateDevice.
@Override
public final Future<OperationResult<Id>> updateDevice(final String tenantId, final String deviceId, final Device device, final Optional<String> resourceVersion, final Span span) {
Objects.requireNonNull(tenantId);
Objects.requireNonNull(deviceId);
Objects.requireNonNull(device);
Objects.requireNonNull(resourceVersion);
Objects.requireNonNull(span);
return this.tenantInformationService.tenantExists(tenantId, span).compose(result -> result.isError() ? Future.failedFuture(ServiceInvocationException.create(tenantId, result.getStatus(), "tenant does not exist", null)) : processUpdateDevice(DeviceKey.from(result.getPayload(), deviceId), device, resourceVersion, span)).onSuccess(result -> NotificationEventBusSupport.sendNotification(vertx, new DeviceChangeNotification(LifecycleChange.UPDATE, tenantId, deviceId, Instant.now(), device.isEnabled()))).recover(t -> DeviceRegistryUtils.mapError(t, tenantId));
}
use of org.eclipse.hono.service.management.OperationResult in project hono by eclipse.
the class DelegatingCredentialsManagementHttpEndpoint method getCredentialsForDevice.
private void getCredentialsForDevice(final RoutingContext ctx) {
final Span span = TracingHelper.buildServerChildSpan(tracer, TracingHandler.serverSpanContext(ctx), SPAN_NAME_GET_CREDENTIALS, getClass().getSimpleName()).start();
final Future<String> tenantId = getRequestParameter(ctx, PARAM_TENANT_ID, getPredicate(config.getTenantIdPattern(), false));
final Future<String> deviceId = getRequestParameter(ctx, PARAM_DEVICE_ID, getPredicate(config.getDeviceIdPattern(), false));
CompositeFuture.all(tenantId, deviceId).compose(ok -> {
TracingHelper.setDeviceTags(span, tenantId.result(), deviceId.result());
logger.debug("getting credentials [tenant: {}, device-id: {}]]", tenantId.result(), deviceId.result());
return getService().readCredentials(tenantId.result(), deviceId.result(), span);
}).map(operationResult -> {
if (operationResult.isOk()) {
// we need to map the payload from List to JsonArray because
// Jackson does not include the credential's type property in the
// JSON when serializing a plain java List<?> object.
final JsonArray credentialsArray = operationResult.getPayload().stream().map(credentials -> JsonObject.mapFrom(credentials)).collect(JsonArray::new, JsonArray::add, JsonArray::addAll);
return OperationResult.ok(operationResult.getStatus(), credentialsArray, operationResult.getCacheDirective(), operationResult.getResourceVersion());
} else {
return operationResult;
}
}).onSuccess(operationResult -> writeResponse(ctx, operationResult, span)).onFailure(t -> failRequest(ctx, t, span)).onComplete(s -> span.finish());
}
Aggregations