TwinPayloadFactory { public static JsonObject toDittoProtocol(InfomodelValue infomodelData, String deviceId) { if (!deviceId.contains(DEVICE_ID_SEPARATOR)) { throw new IllegalArgumentException("Device ID must comply to pattern <namespace>:<suffix>"); } int separatorIndex = deviceId.indexOf(DEVICE_ID_SEPARATOR); return toDittoProtocol(infomodelData, deviceId.substring(0, separatorIndex), deviceId.substring(separatorIndex + 1)); }  static JsonObject toDittoProtocol(InfomodelValue infomodelData, String deviceId); static JsonObject toDittoProtocol(FunctionblockValue fbData, String featureId, String deviceId); static JsonObject toDittoProtocol(InfomodelValue infomodelData, String dittoNamespace,
      String dittoIdSuffix); static JsonObject toDittoProtocol(FunctionblockValue functionblockData, String featureId,
      String dittoNamespace, String dittoIdSuffix);  }
@Test public void testCreateRequestSingleFbPropertyforEntireInfomodel() { FunctionblockModel fbm = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Temperature:1.0.0")) .statusProperty(ModelProperty.createPrimitiveProperty("value", true, PrimitiveType.FLOAT)).build(); Infomodel infomodel = Infomodel.Builder(ModelId.fromPrettyFormat("com.acme:TemperatureSensor:1.0.0")) .withProperty(ModelProperty.Builder("temperature", fbm).build()).build(); FunctionblockValue fbValue = new FunctionblockValue(fbm); fbValue.withStatusProperty("value", 20.2); InfomodelValue infomodelValue = new InfomodelValue(infomodel); infomodelValue.withFunctionblock("temperature", fbValue); System.out.println(gson.toJson(TwinPayloadFactory.toDittoProtocol(infomodelValue, "com.acme:Sensor-1"))); }
@Test public void testCreateRequestSingleFbPropertyForFeature() { FunctionblockModel fbm = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Temperature:1.0.0")) .statusProperty(ModelProperty.createPrimitiveProperty("value", true, PrimitiveType.FLOAT)).build(); FunctionblockValue fbValue = new FunctionblockValue(fbm); fbValue.withStatusProperty("value", 20.2); System.out.println(gson.toJson(TwinPayloadFactory.toDittoProtocol(fbValue,"temperature", "com.acme:Sensor-1"))); }
@Test public void testCreateRequestSingleMultipleFbProperties() { FunctionblockModel fbm = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Temperature:1.0.0")) .statusProperty(ModelProperty.createPrimitiveProperty("value", true, PrimitiveType.FLOAT)).build(); Infomodel infomodel = Infomodel.Builder(ModelId.fromPrettyFormat("com.acme:TemperatureSensor:1.0.0")) .withProperty(ModelProperty.Builder("indoorTemperature", fbm).build()) .withProperty(ModelProperty.Builder("outdoorTemperature", fbm).build()) .build(); FunctionblockValue indoorTemperature = new FunctionblockValue(fbm); indoorTemperature.withStatusProperty("value", 20.2); FunctionblockValue outdoorTemperature = new FunctionblockValue(fbm); outdoorTemperature.withStatusProperty("value", 9.2); InfomodelValue infomodelValue = new InfomodelValue(infomodel); infomodelValue.withFunctionblock("indoorTemperature", indoorTemperature); infomodelValue.withFunctionblock("outdoorTemperature", outdoorTemperature); System.out.println(gson.toJson(TwinPayloadFactory.toDittoProtocol(infomodelValue, "com.acme:Sensor-1"))); }