Search in sources :

Example 21 with InfomodelValue

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

the class DataMapperJxpath method map.

public InfomodelValue map(Object input, MappingContext mappingContext) {
    JXPathContext context = jxpathHelper.newContext(input);
    InfomodelValue normalized = new InfomodelValue(specification.getInfoModel());
    final Infomodel deviceInfoModel = specification.getInfoModel();
    for (ModelProperty fbProperty : deviceInfoModel.getFunctionblocks()) {
        FunctionblockValue mappedFb = mapFunctionBlock(fbProperty, context);
        if (mappedFb != null) {
            normalized.withFunctionblock(fbProperty.getName(), mappedFb);
        }
    }
    return normalized;
}
Also used : FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) JXPathContext(org.apache.commons.jxpath.JXPathContext) Infomodel(org.eclipse.vorto.model.Infomodel) ModelProperty(org.eclipse.vorto.model.ModelProperty) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue)

Example 22 with InfomodelValue

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

the class JsonMappingTest method testMapNestedEntityWithCustomFunction.

@Test
public void testMapNestedEntityWithCustomFunction() {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithNestedEntityAndCustomFunction()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
    String json = "{\"clickType\" : \"DOUBLE\"}";
    InfomodelValue mappedOutput = mapper.mapSource(gson.fromJson(json, Object.class));
    FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
    assertEquals(2, ((EntityPropertyValue) buttonFunctionblockData.getStatusProperty("count").get()).getValue().getPropertyValue("value").get().getValue());
    System.out.println(gson.toJson(mappedOutput.serialize()));
}
Also used : FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) EntityPropertyValue(org.eclipse.vorto.model.runtime.EntityPropertyValue) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) JavascriptEvalProvider(org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider) Test(org.junit.Test)

Example 23 with InfomodelValue

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

the class JsonMappingTest method testConfigMapping.

@Test
public void testConfigMapping() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithConfigMapping()).registerConverterFunction(TypeFunctionFactory.createFunctions()).registerConverterFunction(StringFunctionFactory.createFunctions()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
    String json = "{\"clickType\" : \"DOUBLE\", \"batteryVoltage\": \"2322mV\"}";
    InfomodelValue mappedOutput = mapper.mapSource(gson.fromJson(json, Object.class));
    System.out.println(mappedOutput);
}
Also used : IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) JavascriptEvalProvider(org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider) Test(org.junit.Test)

Example 24 with InfomodelValue

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

the class JsonMappingTest method testMapSingleFunctionblockOfInfomodel.

@Test
public void testMapSingleFunctionblockOfInfomodel() {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithCustomFunction()).registerConverterFunction(TypeFunctionFactory.createFunctions()).registerConverterFunction(StringFunctionFactory.createFunctions()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
    String json = "{\"clickType\" : \"DOUBLE\"}";
    InfomodelValue mappedOutput = mapper.mapSource(gson.fromJson(json, Object.class));
    FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
    assertEquals(true, (Boolean) buttonFunctionblockData.getStatusProperty("digital_input_state").get().getValue());
    assertEquals(2, buttonFunctionblockData.getStatusProperty("digital_input_count").get().getValue());
    FunctionblockValue voltageFunctionblockData = mappedOutput.get("voltage");
    assertNull(voltageFunctionblockData);
    System.out.println(gson.toJson(mappedOutput.serialize()));
}
Also used : FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) JavascriptEvalProvider(org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider) Test(org.junit.Test)

Example 25 with InfomodelValue

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

the class ConvertTest method testMappingTypeConversion.

@Test
public void testMappingTypeConversion() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithTypeConversion()).registerConverterFunction(TypeFunctionFactory.createFunctions()).build();
    String json = "[{\"lng\" : 0.002322},{\"lng\" : 0.002222}]";
    InfomodelValue mappedOutput = mapper.mapSource(gson.fromJson(json, Object.class));
    FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
    assertEquals("0.002322", buttonFunctionblockData.getStatusProperty("sensor_value").get().getValue());
    System.out.println(mappedOutput);
}
Also used : FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test)

Aggregations

InfomodelValue (org.eclipse.vorto.model.runtime.InfomodelValue)58 Test (org.junit.Test)54 FunctionblockValue (org.eclipse.vorto.model.runtime.FunctionblockValue)29 IDataMapper (org.eclipse.vorto.mapping.engine.IDataMapper)25 JUnitPerfTest (com.github.noconnor.junitperf.JUnitPerfTest)24 JavascriptEvalProvider (org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider)10 IPayloadDeserializer (org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer)10 JSONDeserializer (org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer)10 Random (java.util.Random)8 EntityPropertyValue (org.eclipse.vorto.model.runtime.EntityPropertyValue)8 Infomodel (org.eclipse.vorto.model.Infomodel)5 FunctionblockModel (org.eclipse.vorto.model.FunctionblockModel)4 HashMap (java.util.HashMap)3 IMappingSpecification (org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification)3 Gson (com.google.gson.Gson)2 JsonObject (com.google.gson.JsonObject)2 File (java.io.File)2 MappingEngine (org.eclipse.vorto.mapping.engine.MappingEngine)2 BinaryData (org.eclipse.vorto.mapping.engine.model.binary.BinaryData)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1