use of org.eclipse.vorto.mapping.engine.MappingEngine in project vorto by eclipse.
the class Example method main.
public static void main(String[] args) throws Exception {
MappingEngine engine = MappingEngine.createFromInputStream(FileUtils.openInputStream(new File("src/test/resources/mappingspec.json")));
Map<String, Object> data = new HashMap<String, Object>();
data.put("distance", "100m");
InfomodelValue result = engine.mapSource(data);
if (result.validate().isValid()) {
JsonObject dittoPayloadToUpdateAllFeatures = TwinPayloadFactory.toDittoProtocol(result, "org.eclipse.vorto", "deviceid-123");
System.out.println(gson.toJson(dittoPayloadToUpdateAllFeatures));
JsonObject dittoPayloadToUpdateSingleFeature = TwinPayloadFactory.toDittoProtocol(result.get("distance"), "distance", "org.eclipse.vorto", "deviceid-123");
System.out.println(gson.toJson(dittoPayloadToUpdateSingleFeature));
} else {
System.err.println("Mapped data is not valid to Vorto Model");
}
}
use of org.eclipse.vorto.mapping.engine.MappingEngine in project vorto by eclipse.
the class Main method main.
public static void main(String[] args) throws Exception {
MappingEngine engine = MappingEngine.createFromInputStream(FileUtils.openInputStream(new File("src/test/resources/mappingspec.json")));
Map<String, Object> data = new HashMap<String, Object>();
data.put("distance", "100m");
InfomodelValue result = engine.mapSource(data);
if (result.validate().isValid()) {
JsonObject dittoPayloadToUpdateAllFeatures = TwinPayloadFactory.toDittoProtocol(result, "org.eclipse.vorto", "deviceid-123");
System.out.println(gson.toJson(dittoPayloadToUpdateAllFeatures));
JsonObject dittoPayloadToUpdateSingleFeature = TwinPayloadFactory.toDittoProtocol(result.get("distance"), "distance", "org.eclipse.vorto", "deviceid-123");
System.out.println(gson.toJson(dittoPayloadToUpdateSingleFeature));
} else {
System.err.println("Mapped data is not valid to Vorto Model");
}
}
Aggregations