Search in sources :

Example 1 with ValueConverterException

use of com.canoo.platform.remoting.spi.converter.ValueConverterException 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 ValueConverterException

use of com.canoo.platform.remoting.spi.converter.ValueConverterException in project dolphin-platform by canoo.

the class DurationConverterFactoryTest method testReconversion.

private void testReconversion(Converter converter, Duration duration) {
    try {
        Object dolphinObject = converter.convertToDolphin(duration);
        assertNotNull(dolphinObject);
        Object reconvertedObject = converter.convertFromDolphin(dolphinObject);
        assertNotNull(reconvertedObject);
        assertEquals(reconvertedObject.getClass(), Duration.class);
        Duration reconvertedDuration = (Duration) reconvertedObject;
        assertEquals(reconvertedDuration, duration);
    } catch (ValueConverterException e) {
        fail("Error in conversion", e);
    }
}
Also used : Duration(java.time.Duration) ValueConverterException(com.canoo.platform.remoting.spi.converter.ValueConverterException)

Example 3 with ValueConverterException

use of com.canoo.platform.remoting.spi.converter.ValueConverterException in project dolphin-platform by canoo.

the class DurationConverterFactoryTest method testNullValues.

@Test
public void testNullValues(@Mocked BeanRepository beanRepository) {
    // Given
    Converters converters = new Converters(beanRepository);
    // When
    Converter converter = converters.getConverter(Duration.class);
    // Then
    try {
        assertEquals(converter.convertFromDolphin(null), null);
        assertEquals(converter.convertToDolphin(null), null);
    } catch (ValueConverterException e) {
        fail("Error in conversion");
    }
}
Also used : Converters(com.canoo.dp.impl.remoting.Converters) Converter(com.canoo.platform.remoting.spi.converter.Converter) ValueConverterException(com.canoo.platform.remoting.spi.converter.ValueConverterException) Test(org.testng.annotations.Test)

Example 4 with ValueConverterException

use of com.canoo.platform.remoting.spi.converter.ValueConverterException in project dolphin-platform by canoo.

the class LocalDateConverterFactoryTest method testReconversion.

private void testReconversion(Converter converter, LocalDate time) {
    try {
        Object dolphinObject = converter.convertToDolphin(time);
        assertNotNull(dolphinObject);
        TimeZone.setDefault(TimeZone.getTimeZone(ZoneId.of("UTC-3")));
        Object reconvertedObject = converter.convertFromDolphin(dolphinObject);
        assertNotNull(reconvertedObject);
        assertEquals(reconvertedObject.getClass(), LocalDate.class);
        LocalDate reverted = (LocalDate) reconvertedObject;
        assertEquals(reverted, time);
    } catch (ValueConverterException e) {
        fail("Error in conversion");
    }
}
Also used : ValueConverterException(com.canoo.platform.remoting.spi.converter.ValueConverterException) LocalDate(java.time.LocalDate)

Example 5 with ValueConverterException

use of com.canoo.platform.remoting.spi.converter.ValueConverterException in project dolphin-platform by canoo.

the class LocalDateConverterFactoryTest method testNullValues.

@Test
public void testNullValues(@Mocked BeanRepository beanRepository) {
    // Given
    Converters converters = new Converters(beanRepository);
    // When
    Converter converter = converters.getConverter(LocalDate.class);
    // Then
    try {
        assertEquals(converter.convertFromDolphin(null), null);
        assertEquals(converter.convertToDolphin(null), null);
    } catch (ValueConverterException e) {
        fail("Error in conversion", e);
    }
}
Also used : Converters(com.canoo.dp.impl.remoting.Converters) Converter(com.canoo.platform.remoting.spi.converter.Converter) ValueConverterException(com.canoo.platform.remoting.spi.converter.ValueConverterException) Test(org.testng.annotations.Test)

Aggregations

ValueConverterException (com.canoo.platform.remoting.spi.converter.ValueConverterException)12 Converters (com.canoo.dp.impl.remoting.Converters)5 Converter (com.canoo.platform.remoting.spi.converter.Converter)5 Test (org.testng.annotations.Test)5 MappingException (com.canoo.dp.impl.remoting.MappingException)2 CallActionCommand (com.canoo.dp.impl.remoting.commands.CallActionCommand)1 Attribute (com.canoo.dp.impl.remoting.legacy.core.Attribute)1 ControllerActionException (com.canoo.platform.remoting.client.ControllerActionException)1 Param (com.canoo.platform.remoting.client.Param)1 Duration (java.time.Duration)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 Period (java.time.Period)1 ZonedDateTime (java.time.ZonedDateTime)1 CompletableFuture (java.util.concurrent.CompletableFuture)1