Search in sources :

Example 6 with DittoData

use of org.eclipse.vorto.service.mapping.ditto.DittoData in project vorto by eclipse.

the class JsonMappingTest method testMapDevicePayloadWithInitialValue.

@Test
public void testMapDevicePayloadWithInitialValue() {
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithCustomFunction()).buildDittoMapper();
    String json = "{\"clickType\" : \"DOUBLE\", \"batteryVoltage\": \"0mV\"}";
    DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromJson(json), MappingContext.empty());
    Feature buttonFeature = mappedDittoOutput.getFeatures().get("button");
    assertEquals(true, (Boolean) buttonFeature.getStatusProperties().get("digital_input_state"));
    assertEquals(2, buttonFeature.getStatusProperties().get("digital_input_count"));
    Feature voltageFeature = mappedDittoOutput.getFeatures().get("voltage");
    assertEquals(0f, voltageFeature.getStatusProperties().get("sensor_value"));
    assertEquals("mV", voltageFeature.getStatusProperties().get("sensor_units"));
    System.out.println(mappedDittoOutput.toJson());
}
Also used : SpecWithCustomFunction(org.eclipse.vorto.service.mapping.spec.SpecWithCustomFunction) Feature(org.eclipse.vorto.service.mapping.ditto.Feature) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData) Test(org.junit.Test)

Example 7 with DittoData

use of org.eclipse.vorto.service.mapping.ditto.DittoData in project vorto by eclipse.

the class JsonMappingTest method testMapSingleFunctionblockOfInfomodel2.

@Test
public void testMapSingleFunctionblockOfInfomodel2() {
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithConditionedRules()).buildDittoMapper();
    final String sampleHomeConnectRESTResponse = "{\"data\" : { \"key\" : \"DoorState\", \"value\" : \"Locked\"}}";
    DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromJson(sampleHomeConnectRESTResponse), MappingContext.empty());
    System.out.println(mappedDittoOutput.toJson());
    assertFalse(mappedDittoOutput.getFeatures().containsKey("operationState"));
    Feature doorStateFeature = mappedDittoOutput.getFeatures().get("doorState");
    assertEquals("Locked", (String) doorStateFeature.getStatusProperties().get("sensor_value"));
}
Also used : SpecWithConditionedRules(org.eclipse.vorto.service.mapping.spec.SpecWithConditionedRules) Feature(org.eclipse.vorto.service.mapping.ditto.Feature) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData) Test(org.junit.Test)

Example 8 with DittoData

use of org.eclipse.vorto.service.mapping.ditto.DittoData in project vorto by eclipse.

the class JsonMappingTest method testCreateDynamicMappingSpec.

@Test
public void testCreateDynamicMappingSpec() throws Exception {
    IMappingSpecification mappingSpecification = MappingSpecificationBuilder.create().infomodelId("com.bosch.BoschGLM100C:1.0.0").build();
    mappingSpecification.getFunctionBlock("distancesensor").getStatusProperty("distance").get().addStereotype(Stereotype.createWithXpath("/@dist"));
    mappingSpecification.getFunctionBlock("inclinesensor").getStatusProperty("degree").get().addStereotype(Stereotype.createWithXpath("/@incl"));
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(mappingSpecification).buildDittoMapper();
    Map<String, Object> input = new HashMap<String, Object>();
    input.put("dist", 5.3);
    input.put("incl", 38.8);
    DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromObject(input), MappingContext.empty());
    Feature distance = mappedDittoOutput.getFeatures().get("distancesensor");
    assertEquals(5.3, distance.getStatusProperties().get("distance"));
    Feature incline = mappedDittoOutput.getFeatures().get("inclinesensor");
    assertEquals(38.8, incline.getStatusProperties().get("degree"));
    System.out.println(mappedDittoOutput.toJson());
}
Also used : IMappingSpecification(org.eclipse.vorto.service.mapping.spec.IMappingSpecification) HashMap(java.util.HashMap) Feature(org.eclipse.vorto.service.mapping.ditto.Feature) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData) Test(org.junit.Test)

Example 9 with DittoData

use of org.eclipse.vorto.service.mapping.ditto.DittoData in project vorto by eclipse.

the class JsonMappingTest method testDittoMappingWithInfoModelUsingSameFunctionblock.

@Test
public void testDittoMappingWithInfoModelUsingSameFunctionblock() throws Exception {
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithSameFunctionblock()).buildDittoMapper();
    String json = "{\"btnvalue1\" : 2, \"btnvalue2\": 10}";
    DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromJson(json), MappingContext.empty());
    Feature buttonFeature = mappedDittoOutput.getFeatures().get("btn1");
    assertEquals(2, buttonFeature.getStatusProperties().get("sensor_value"));
    Feature button2Feature = mappedDittoOutput.getFeatures().get("btn2");
    assertEquals(10, button2Feature.getStatusProperties().get("sensor_value"));
    System.out.println(mappedDittoOutput.toJson());
}
Also used : SpecWithSameFunctionblock(org.eclipse.vorto.service.mapping.spec.SpecWithSameFunctionblock) Feature(org.eclipse.vorto.service.mapping.ditto.Feature) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData) Test(org.junit.Test)

Example 10 with DittoData

use of org.eclipse.vorto.service.mapping.ditto.DittoData in project vorto by eclipse.

the class DittoMapper method doMap.

@Override
protected DittoData doMap(InfomodelData input, MappingContext mappingContext) {
    DittoData output = new DittoData();
    for (FunctionblockData fbData : input.getFunctionblockData()) {
        FeatureBuilder featureBuilder = Feature.newBuilder(fbData.getId());
        featureBuilder.withStatus(fbData.getStatus());
        output.withFeature(featureBuilder.build());
    }
    return output;
}
Also used : FunctionblockData(org.eclipse.vorto.service.mapping.normalized.FunctionblockData) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData)

Aggregations

DittoData (org.eclipse.vorto.service.mapping.ditto.DittoData)20 Test (org.junit.Test)19 Feature (org.eclipse.vorto.service.mapping.ditto.Feature)15 SpecWithCustomFunction (org.eclipse.vorto.service.mapping.spec.SpecWithCustomFunction)4 IMappingSpecification (org.eclipse.vorto.service.mapping.spec.IMappingSpecification)3 HashMap (java.util.HashMap)2 Gson (com.google.gson.Gson)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 BleGattCharacteristic (org.eclipse.vorto.service.mapping.ble.BleGattCharacteristic)1 BleGattDevice (org.eclipse.vorto.service.mapping.ble.BleGattDevice)1 GattCharacteristic (org.eclipse.vorto.service.mapping.ble.json.GattCharacteristic)1 GattDevice (org.eclipse.vorto.service.mapping.ble.json.GattDevice)1 GattService (org.eclipse.vorto.service.mapping.ble.json.GattService)1 FunctionblockData (org.eclipse.vorto.service.mapping.normalized.FunctionblockData)1 SpecGattConverter (org.eclipse.vorto.service.mapping.spec.SpecGattConverter)1 SpecWithArrayPayload (org.eclipse.vorto.service.mapping.spec.SpecWithArrayPayload)1 SpecWithBase64Converter (org.eclipse.vorto.service.mapping.spec.SpecWithBase64Converter)1 SpecWithByteArrayConverter (org.eclipse.vorto.service.mapping.spec.SpecWithByteArrayConverter)1 SpecWithCondition (org.eclipse.vorto.service.mapping.spec.SpecWithCondition)1