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;
}
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()));
}
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);
}
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()));
}
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);
}
Aggregations