Search in sources :

Example 1 with MappingEngine

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");
    }
}
Also used : HashMap(java.util.HashMap) MappingEngine(org.eclipse.vorto.mapping.engine.MappingEngine) JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) File(java.io.File)

Example 2 with MappingEngine

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");
    }
}
Also used : HashMap(java.util.HashMap) MappingEngine(org.eclipse.vorto.mapping.engine.MappingEngine) JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) File(java.io.File)

Aggregations

JsonObject (com.google.gson.JsonObject)2 File (java.io.File)2 HashMap (java.util.HashMap)2 MappingEngine (org.eclipse.vorto.mapping.engine.MappingEngine)2 InfomodelValue (org.eclipse.vorto.model.runtime.InfomodelValue)2