Search in sources :

Example 1 with HttpValidationCallback

use of org.thingsboard.server.controller.HttpValidationCallback in project thingsboard by thingsboard.

the class AccessValidator method validateEntityAndCallback.

public DeferredResult<ResponseEntity> validateEntityAndCallback(SecurityUser currentUser, Operation operation, EntityId entityId, ThreeConsumer<DeferredResult<ResponseEntity>, TenantId, EntityId> onSuccess, BiConsumer<DeferredResult<ResponseEntity>, Throwable> onFailure) throws ThingsboardException {
    final DeferredResult<ResponseEntity> response = new DeferredResult<>();
    validate(currentUser, operation, entityId, new HttpValidationCallback(response, new FutureCallback<DeferredResult<ResponseEntity>>() {

        @Override
        public void onSuccess(@Nullable DeferredResult<ResponseEntity> result) {
            try {
                onSuccess.accept(response, currentUser.getTenantId(), entityId);
            } catch (Exception e) {
                onFailure(e);
            }
        }

        @Override
        public void onFailure(Throwable t) {
            onFailure.accept(response, t);
        }
    }));
    return response;
}
Also used : ToErrorResponseEntity(org.thingsboard.server.service.telemetry.exception.ToErrorResponseEntity) ResponseEntity(org.springframework.http.ResponseEntity) HttpValidationCallback(org.thingsboard.server.controller.HttpValidationCallback) FutureCallback(com.google.common.util.concurrent.FutureCallback) Nullable(javax.annotation.Nullable) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) DeferredResult(org.springframework.web.context.request.async.DeferredResult)

Aggregations

FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Nullable (javax.annotation.Nullable)1 ResponseEntity (org.springframework.http.ResponseEntity)1 DeferredResult (org.springframework.web.context.request.async.DeferredResult)1 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)1 HttpValidationCallback (org.thingsboard.server.controller.HttpValidationCallback)1 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)1 ToErrorResponseEntity (org.thingsboard.server.service.telemetry.exception.ToErrorResponseEntity)1