Search in sources :

Example 1 with ControllerActionException

use of com.canoo.platform.remoting.client.ControllerActionException in project dolphin-platform by canoo.

the class ControllerProxyImpl method invoke.

@Override
public CompletableFuture<Void> invoke(final String actionName, final Param... params) {
    if (destroyed) {
        throw new IllegalStateException("The controller was already destroyed");
    }
    final ClientControllerActionCallBean bean = platformBeanRepository.createControllerActionCallBean(controllerId, actionName, params);
    final CallActionCommand callActionCommand = new CallActionCommand();
    callActionCommand.setControllerId(controllerId);
    callActionCommand.setActionName(actionName);
    if (params != null) {
        for (Param param : params) {
            Object value = param.getValue();
            if (value == null) {
                callActionCommand.addParam(param.getName(), null);
            } else {
                try {
                    callActionCommand.addParam(param.getName(), converters.getConverter(value.getClass()).convertToDolphin(value));
                } catch (ValueConverterException e) {
                    throw new MappingException("Error in value conversion of param '" + param.getName() + "' for action '" + actionName + "'", e);
                }
            }
        }
    }
    final CompletableFuture<Void> result = new CompletableFuture<>();
    clientConnector.send(callActionCommand, () -> {
        if (bean.isError()) {
            result.completeExceptionally(new ControllerActionException("Error on calling action on the server. Please check the server log."));
        } else {
            result.complete(null);
        }
        bean.unregister();
    });
    return result;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ControllerActionException(com.canoo.platform.remoting.client.ControllerActionException) CallActionCommand(com.canoo.dp.impl.remoting.commands.CallActionCommand) Param(com.canoo.platform.remoting.client.Param) ValueConverterException(com.canoo.platform.remoting.spi.converter.ValueConverterException) MappingException(com.canoo.dp.impl.remoting.MappingException)

Aggregations

MappingException (com.canoo.dp.impl.remoting.MappingException)1 CallActionCommand (com.canoo.dp.impl.remoting.commands.CallActionCommand)1 ControllerActionException (com.canoo.platform.remoting.client.ControllerActionException)1 Param (com.canoo.platform.remoting.client.Param)1 ValueConverterException (com.canoo.platform.remoting.spi.converter.ValueConverterException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1