Search in sources :

Example 11 with FunctionblockValue

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

the class BinaryMappingLoadTest method tripleNestedConverter4.

@Test
@JUnitPerfTest(threads = THREAD_AMOUNT_4, durationMs = TEST_DURATION_4, rampUpPeriodMs = RAMP_PERIOD, warmUpMs = WARMUP_DURATION_4, maxExecutionsPerSecond = EXECUTIONS_PER_SECOND_4)
public void tripleNestedConverter4() throws Exception {
    InfomodelValue mappedDittoOutput = testCaseThreeMapper.mapSource(gson.fromJson(testCaseThreeJson, Object.class));
    FunctionblockValue button = mappedDittoOutput.get("button");
    assertEquals(2, button.getStatusProperty("sensor_value").get().getValue());
}
Also used : FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test) JUnitPerfTest(com.github.noconnor.junitperf.JUnitPerfTest) JUnitPerfTest(com.github.noconnor.junitperf.JUnitPerfTest)

Example 12 with FunctionblockValue

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

the class JsonMappingTest method testMapDevicePayloadWithInitialValue.

@Test
public void testMapDevicePayloadWithInitialValue() {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithCustomFunction()).registerConverterFunction(TypeFunctionFactory.createFunctions()).registerConverterFunction(StringFunctionFactory.createFunctions()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
    String json = "{\"clickType\" : \"DOUBLE\", \"batteryVoltage\": \"0mV\"}";
    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");
    assertEquals(0f, voltageFunctionblockData.getStatusProperty("sensor_value").get().getValue());
    assertEquals("mV", voltageFunctionblockData.getStatusProperty("sensor_units").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) JavascriptEvalProvider(org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider) Test(org.junit.Test)

Example 13 with FunctionblockValue

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

the class BinaryMappingTest method testMappingWithBinary.

@Test
public void testMappingWithBinary() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithByteArrayConverter()).registerConverterFunction(StringFunctionFactory.createFunctions()).registerConverterFunction(TypeFunctionFactory.createFunctions()).registerConverterFunction(BinaryFunctionFactory.createFunctions()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
    String x = "4f00630063007500700061006e0063007900200002";
    String json = "{\"data\" : \"" + x + "\"}";
    InfomodelValue mappedDittoOutput = mapper.mapSource(gson.fromJson(json, Object.class));
    FunctionblockValue button = mappedDittoOutput.get("button");
    assertEquals(2, button.getStatusProperty("sensor_value").get().getValue());
    System.out.println(mappedDittoOutput);
}
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 14 with FunctionblockValue

use of org.eclipse.vorto.model.runtime.FunctionblockValue 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 15 with FunctionblockValue

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

the class DataMapperJxpath method mapFunctionBlock.

private FunctionblockValue mapFunctionBlock(ModelProperty fbProperty, JXPathContext context) {
    FunctionblockModel fbModel = specification.getFunctionBlock(fbProperty.getName());
    if (!matchesCondition(fbModel, context)) {
        return null;
    }
    FunctionblockValue fbData = new FunctionblockValue(fbModel);
    for (ModelProperty statusProperty : fbModel.getStatusProperties()) {
        try {
            Object mapped = this.mapProperty(fbModel, statusProperty, context);
            if (mapped != null) {
                fbData.withStatusProperty(statusProperty.getName(), mapped);
            }
        } catch (JXPathNotFoundException ex) {
            if (statusProperty.isMandatory()) {
                return null;
            }
        } catch (JXPathInvalidAccessException ex) {
            if (ex.getCause() instanceof JXPathNotFoundException) {
                if (statusProperty.isMandatory()) {
                    return null;
                }
            }
            throw new MappingException("A problem occured during mapping", ex);
        }
    }
    for (ModelProperty configProperty : fbModel.getConfigurationProperties()) {
        try {
            Object mapped = this.mapProperty(fbModel, configProperty, context);
            if (mapped != null) {
                fbData.withConfigurationProperty(configProperty.getName(), mapped);
            }
        } catch (JXPathNotFoundException ex) {
            if (configProperty.isMandatory()) {
                return null;
            }
        } catch (JXPathInvalidAccessException ex) {
            if (ex.getCause() instanceof JXPathNotFoundException) {
                if (configProperty.isMandatory()) {
                    return null;
                }
            }
            throw new MappingException("A problem occured during mapping", ex);
        }
    }
    return onlyReturnIfPopulated(fbData);
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) JXPathNotFoundException(org.apache.commons.jxpath.JXPathNotFoundException) ModelProperty(org.eclipse.vorto.model.ModelProperty) JXPathInvalidAccessException(org.apache.commons.jxpath.JXPathInvalidAccessException) MappingException(org.eclipse.vorto.mapping.engine.MappingException)

Aggregations

FunctionblockValue (org.eclipse.vorto.model.runtime.FunctionblockValue)32 InfomodelValue (org.eclipse.vorto.model.runtime.InfomodelValue)29 Test (org.junit.Test)29 JUnitPerfTest (com.github.noconnor.junitperf.JUnitPerfTest)12 IDataMapper (org.eclipse.vorto.mapping.engine.IDataMapper)12 JavascriptEvalProvider (org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider)7 FunctionblockModel (org.eclipse.vorto.model.FunctionblockModel)6 Infomodel (org.eclipse.vorto.model.Infomodel)5 Random (java.util.Random)4 IPayloadDeserializer (org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer)3 JSONDeserializer (org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer)3 ModelProperty (org.eclipse.vorto.model.ModelProperty)2 Date (java.util.Date)1 JXPathContext (org.apache.commons.jxpath.JXPathContext)1 JXPathInvalidAccessException (org.apache.commons.jxpath.JXPathInvalidAccessException)1 JXPathNotFoundException (org.apache.commons.jxpath.JXPathNotFoundException)1 MappingException (org.eclipse.vorto.mapping.engine.MappingException)1 BinaryData (org.eclipse.vorto.mapping.engine.model.binary.BinaryData)1 EntityPropertyValue (org.eclipse.vorto.model.runtime.EntityPropertyValue)1 SpecWithArrayPayload (org.eclipse.vorto.service.mapping.spec.SpecWithArrayPayload)1