use of org.eclipse.hono.client.ClientErrorException in project hono by eclipse.
the class BaseTenantService method processUpdateRequest.
private Future<EventBusMessage> processUpdateRequest(final EventBusMessage request) {
final String tenantId = request.getTenant();
final JsonObject payload = getRequestPayload(request.getJsonPayload());
if (tenantId == null) {
log.debug("request does not contain mandatory property [{}]", MessageHelper.APP_PROPERTY_TENANT_ID);
return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
} else if (isValidRequestPayload(payload)) {
log.debug("updating tenant [{}]", tenantId);
final Future<TenantResult<JsonObject>> updateResult = Future.future();
addNotPresentFieldsWithDefaultValuesForTenant(payload);
update(tenantId, payload, updateResult.completer());
return updateResult.map(tr -> {
return request.getResponse(tr.getStatus()).setJsonPayload(tr.getPayload()).setCacheDirective(tr.getCacheDirective());
});
} else {
log.debug("request contains malformed payload");
return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
}
}
use of org.eclipse.hono.client.ClientErrorException in project hono by eclipse.
the class BaseTenantService method processRemoveRequest.
private Future<EventBusMessage> processRemoveRequest(final EventBusMessage request) {
final String tenantId = request.getTenant();
if (tenantId == null) {
log.debug("request does not contain mandatory property [{}]", MessageHelper.APP_PROPERTY_TENANT_ID);
return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
} else {
log.debug("deleting tenant [{}]", tenantId);
final Future<TenantResult<JsonObject>> removeResult = Future.future();
remove(tenantId, removeResult.completer());
return removeResult.map(tr -> {
return EventBusMessage.forStatusCode(tr.getStatus()).setJsonPayload(tr.getPayload()).setTenant(tenantId).setCacheDirective(tr.getCacheDirective());
});
}
}
Aggregations