Search in sources :

Example 1 with MappingException

use of com.canoo.dp.impl.remoting.MappingException 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)

Example 2 with MappingException

use of com.canoo.dp.impl.remoting.MappingException in project dolphin-platform by canoo.

the class ListMapperImpl method processEvent.

@Override
public void processEvent(final PropertyInfo observableListInfo, final String sourceId, final ListChangeEvent<?> event) {
    final String attributeName = observableListInfo.getAttributeName();
    for (final ListChangeEvent.Change<?> change : event.getChanges()) {
        final int from = change.getFrom();
        final int to = from + change.getRemovedElements().size();
        final List<?> newElements = event.getSource().subList(from, change.getTo());
        final int count = newElements.size();
        final PresentationModelBuilder builder = builderFactory.createBuilder();
        builder.withType(PlatformRemotingConstants.LIST_SPLICE).withAttribute("source", sourceId).withAttribute("attribute", attributeName).withAttribute("from", from).withAttribute("to", to).withAttribute("count", count);
        int i = 0;
        for (final Object current : newElements) {
            try {
                builder.withAttribute(Integer.toString(i++), observableListInfo.convertToDolphin(current));
            } catch (Exception e) {
                throw new MappingException("Error in event processing!", e);
            }
        }
        builder.create();
    }
}
Also used : ListChangeEvent(com.canoo.platform.remoting.ListChangeEvent) PresentationModelBuilder(com.canoo.dp.impl.remoting.PresentationModelBuilder) MappingException(com.canoo.dp.impl.remoting.MappingException) MappingException(com.canoo.dp.impl.remoting.MappingException)

Example 3 with MappingException

use of com.canoo.dp.impl.remoting.MappingException in project dolphin-platform by canoo.

the class ServerControllerActionCallBean method getParam.

public Object getParam(String name, Class<?> type) {
    final String internalName = PARAM_PREFIX + name;
    final Attribute valueAttribute = pm.getAttribute(internalName);
    if (valueAttribute == null) {
        throw new IllegalArgumentException(String.format("Invoking RemotingAction requires parameter '%s', but it was not withContent", name));
    }
    try {
        return converters.getConverter(type).convertFromDolphin(valueAttribute.getValue());
    } catch (ValueConverterException e) {
        throw new MappingException("Error in conversion", e);
    }
}
Also used : Attribute(com.canoo.dp.impl.remoting.legacy.core.Attribute) ValueConverterException(com.canoo.platform.remoting.spi.converter.ValueConverterException) MappingException(com.canoo.dp.impl.remoting.MappingException)

Aggregations

MappingException (com.canoo.dp.impl.remoting.MappingException)3 ValueConverterException (com.canoo.platform.remoting.spi.converter.ValueConverterException)2 PresentationModelBuilder (com.canoo.dp.impl.remoting.PresentationModelBuilder)1 CallActionCommand (com.canoo.dp.impl.remoting.commands.CallActionCommand)1 Attribute (com.canoo.dp.impl.remoting.legacy.core.Attribute)1 ListChangeEvent (com.canoo.platform.remoting.ListChangeEvent)1 ControllerActionException (com.canoo.platform.remoting.client.ControllerActionException)1 Param (com.canoo.platform.remoting.client.Param)1 CompletableFuture (java.util.concurrent.CompletableFuture)1