Search in sources :

Example 1 with CreatePresentationModelCommand

use of com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand in project dolphin-platform by canoo.

the class ServerModelStore method presentationModelCommand.

/**
 * Convenience method to let the client (!) dolphin create a presentation model as specified by the DTO.
 * The server model store remains untouched until the client has issued the notification.
 */
@Deprecated
public static void presentationModelCommand(final List<Command> response, final String id, final String presentationModelType, final DTO dto) {
    if (response == null) {
        return;
    }
    List<Map<String, Object>> list = new ArrayList<>();
    for (Slot slot : dto.getSlots()) {
        Map<String, Object> map = new HashMap<>();
        map.put("propertyName", slot.getPropertyName());
        map.put("value", slot.getValue());
        map.put("qualifier", slot.getQualifier());
        list.add(map);
    }
    response.add(new CreatePresentationModelCommand(id, presentationModelType, list));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with CreatePresentationModelCommand

use of com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand in project dolphin-platform by canoo.

the class BlindCommandBatcherTest method testMergeCreatePmAfterValueChange.

@Test
public void testMergeCreatePmAfterValueChange() {
    // given:
    batcher.setMergeValueChanges(true);
    List<CommandAndHandler> list = new ArrayList<CommandAndHandler>();
    ValueChangedCommand command = new ValueChangedCommand();
    command.setAttributeId("0");
    command.setNewValue(1);
    list.add(new CommandAndHandler(command));
    list.add(new CommandAndHandler(new CreatePresentationModelCommand()));
    // when:
    for (CommandAndHandler commandAndHandler : list) {
        batcher.batch(commandAndHandler);
    }
    // then:
    try {
        List<CommandAndHandler> nextBatch = batcher.getWaitingBatches().getVal();
        Assert.assertEquals(2, nextBatch.size());
        Assert.assertEquals(ValueChangedCommand.class, nextBatch.get(0).getCommand().getClass());
        Assert.assertEquals(CreatePresentationModelCommand.class, nextBatch.get(1).getCommand().getClass());
        Assert.assertTrue(batcher.isEmpty());
    } catch (InterruptedException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : CommandAndHandler(com.canoo.dp.impl.client.legacy.communication.CommandAndHandler) ArrayList(java.util.ArrayList) CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand) ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand) Test(org.testng.annotations.Test)

Example 3 with CreatePresentationModelCommand

use of com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand in project dolphin-platform by canoo.

the class ClientConnectorTests method testHandle_CreatePresentationModel_MergeAttributesToExistingModel.

@Test(expectedExceptions = IllegalStateException.class)
public void testHandle_CreatePresentationModel_MergeAttributesToExistingModel() {
    clientModelStore.createModel("p1", null);
    clientConnector.dispatchHandle(new CreatePresentationModelCommand("p1", "type", Collections.<Map<String, Object>>emptyList()));
}
Also used : CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 4 with CreatePresentationModelCommand

use of com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand in project dolphin-platform by canoo.

the class ClientConnectorTests method testHandle_CreatePresentationModel.

@Test
public void testHandle_CreatePresentationModel() {
    List<Map<String, Object>> attributes = new ArrayList<Map<String, Object>>();
    Map<String, Object> map = new HashMap<>();
    map.put("propertyName", "attr");
    map.put("value", "initialValue");
    map.put("qualifier", "qualifier");
    ((ArrayList<Map<String, Object>>) attributes).add(map);
    clientConnector.dispatchHandle(new CreatePresentationModelCommand("p1", "type", attributes));
    Assert.assertNotNull(clientModelStore.findPresentationModelById("p1"));
    Assert.assertNotNull(clientModelStore.findPresentationModelById("p1").getAttribute("attr"));
    Assert.assertEquals("initialValue", clientModelStore.findPresentationModelById("p1").getAttribute("attr").getValue());
    Assert.assertEquals("qualifier", clientModelStore.findPresentationModelById("p1").getAttribute("attr").getQualifier());
    syncAndWaitUntilDone();
    assertCommandsTransmitted(2);
    Assert.assertFalse(clientConnector.getTransmittedCommands().isEmpty());
    Assert.assertEquals(CreatePresentationModelCommand.class, clientConnector.getTransmittedCommands().get(0).getClass());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 5 with CreatePresentationModelCommand

use of com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand in project dolphin-platform by canoo.

the class ClientConnectorTests method testHandle_CreatePresentationModel_ClientSideOnly.

@Test
public void testHandle_CreatePresentationModel_ClientSideOnly() {
    List<Map<String, Object>> attributes = new ArrayList<Map<String, Object>>();
    Map map = new HashMap();
    map.put("propertyName", "attr");
    map.put("value", "initialValue");
    map.put("qualifier", "qualifier");
    ((ArrayList<Map<String, Object>>) attributes).add(map);
    clientConnector.dispatchHandle(new CreatePresentationModelCommand("p1", "type", attributes, true));
    Assert.assertNotNull(clientModelStore.findPresentationModelById("p1"));
    Assert.assertNotNull(clientModelStore.findPresentationModelById("p1").getAttribute("attr"));
    Assert.assertEquals("initialValue", clientModelStore.findPresentationModelById("p1").getAttribute("attr").getValue());
    Assert.assertEquals("qualifier", clientModelStore.findPresentationModelById("p1").getAttribute("attr").getQualifier());
    syncAndWaitUntilDone();
    assertOnlySyncCommandWasTransmitted();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Aggregations

CreatePresentationModelCommand (com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand)10 HashMap (java.util.HashMap)7 Test (org.testng.annotations.Test)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 DolphinPlatformHttpClientConnector (com.canoo.dp.impl.client.DolphinPlatformHttpClientConnector)1 ClientModelStore (com.canoo.dp.impl.client.legacy.ClientModelStore)1 DefaultModelSynchronizer (com.canoo.dp.impl.client.legacy.DefaultModelSynchronizer)1 CommandAndHandler (com.canoo.dp.impl.client.legacy.communication.CommandAndHandler)1 SimpleExceptionHandler (com.canoo.dp.impl.client.legacy.communication.SimpleExceptionHandler)1 CreateContextCommand (com.canoo.dp.impl.remoting.commands.CreateContextCommand)1 Command (com.canoo.dp.impl.remoting.legacy.communication.Command)1 JsonCodec (com.canoo.dp.impl.remoting.legacy.communication.JsonCodec)1 ValueChangedCommand (com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand)1 HeadlessToolkit (com.canoo.platform.client.HeadlessToolkit)1 HttpClient (com.canoo.platform.core.http.HttpClient)1 HttpURLConnectionFactory (com.canoo.platform.core.http.HttpURLConnectionFactory)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1