Search in sources :

Example 1 with PropertyValue

use of org.eclipse.vorto.model.runtime.PropertyValue in project vorto by eclipse.

the class ConfigurationMappingTest method testNotExistFunction.

@Test(expected = MappingException.class)
public void testNotExistFunction() throws Exception {
    IMappingSpecification spec = new SpecWithConfiguration();
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(spec).build();
    PropertyValue newValue = ModelValueFactory.createFBPropertyValue(spec.getFunctionBlock("button"), "enable", true);
    PropertyValue oldValue = ModelValueFactory.createFBPropertyValue(spec.getFunctionBlock("button"), "enable", false);
    Object mapped = mapper.mapTarget(newValue, Optional.of(oldValue), "button");
    assertEquals("1", mapped);
}
Also used : IMappingSpecification(org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) PropertyValue(org.eclipse.vorto.model.runtime.PropertyValue) SpecWithConfiguration(org.eclipse.vorto.service.mapping.spec.SpecWithConfiguration) Test(org.junit.Test)

Example 2 with PropertyValue

use of org.eclipse.vorto.model.runtime.PropertyValue in project vorto by eclipse.

the class ConfigurationMappingTest method testMapSimpleConfigValue.

@Test
public void testMapSimpleConfigValue() throws Exception {
    IMappingSpecification spec = new SpecWithConfiguration();
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(spec).registerConverterFunction(new ClassFunction("button", ConfigurationMappingTest.class)).build();
    PropertyValue newValue = ModelValueFactory.createFBPropertyValue(spec.getFunctionBlock("button"), "enable", true);
    PropertyValue oldValue = ModelValueFactory.createFBPropertyValue(spec.getFunctionBlock("button"), "enable", false);
    Object mapped = mapper.mapTarget(newValue, Optional.of(oldValue), "button");
    assertEquals("1", mapped);
}
Also used : IMappingSpecification(org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) ClassFunction(org.eclipse.vorto.mapping.engine.functions.ClassFunction) PropertyValue(org.eclipse.vorto.model.runtime.PropertyValue) SpecWithConfiguration(org.eclipse.vorto.service.mapping.spec.SpecWithConfiguration) Test(org.junit.Test)

Example 3 with PropertyValue

use of org.eclipse.vorto.model.runtime.PropertyValue in project vorto by eclipse.

the class TwinPayloadFactory method createFunctionBlockProperties.

private static Map<String, Object> createFunctionBlockProperties(FunctionblockValue fbData) {
    Map<String, Object> result = new HashMap<String, Object>();
    Map<String, Object> status = new HashMap<String, Object>();
    for (PropertyValue statusProperty : fbData.getStatus()) {
        status.put(statusProperty.getMeta().getName(), statusProperty.serialize());
    }
    if (!status.isEmpty()) {
        result.put("status", status);
    }
    Map<String, Object> config = new HashMap<String, Object>();
    for (PropertyValue configProperty : fbData.getConfiguration()) {
        config.put(configProperty.getMeta().getName(), configProperty.serialize());
    }
    if (!config.isEmpty()) {
        result.put("configuration", config);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) PropertyValue(org.eclipse.vorto.model.runtime.PropertyValue) JsonObject(com.google.gson.JsonObject)

Example 4 with PropertyValue

use of org.eclipse.vorto.model.runtime.PropertyValue in project vorto by eclipse.

the class TwinPayloadFactory method createFunctionBlockProperties.

private static Map<String, Object> createFunctionBlockProperties(FunctionblockValue fbData) {
    Map<String, Object> result = new HashMap<String, Object>();
    Map<String, Object> status = new HashMap<String, Object>();
    for (PropertyValue statusProperty : fbData.getStatus()) {
        status.put(statusProperty.getMeta().getName(), statusProperty.serialize());
    }
    if (!status.isEmpty()) {
        result.put("status", status);
    }
    Map<String, Object> config = new HashMap<String, Object>();
    for (PropertyValue configProperty : fbData.getConfiguration()) {
        config.put(configProperty.getMeta().getName(), configProperty.serialize());
    }
    if (!config.isEmpty()) {
        result.put("configuration", config);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) PropertyValue(org.eclipse.vorto.model.runtime.PropertyValue) JsonObject(com.google.gson.JsonObject)

Aggregations

PropertyValue (org.eclipse.vorto.model.runtime.PropertyValue)4 JsonObject (com.google.gson.JsonObject)2 HashMap (java.util.HashMap)2 IDataMapper (org.eclipse.vorto.mapping.engine.IDataMapper)2 IMappingSpecification (org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification)2 SpecWithConfiguration (org.eclipse.vorto.service.mapping.spec.SpecWithConfiguration)2 Test (org.junit.Test)2 ClassFunction (org.eclipse.vorto.mapping.engine.functions.ClassFunction)1