From cdb668861d4feb05117582b5c51d5e7c46af4ba1 Mon Sep 17 00:00:00 2001 From: Sascha Doemer Date: Fri, 1 Mar 2024 21:45:42 +0100 Subject: [PATCH 1/3] Introduce DateTimeFormatter in DeviceMeasurementBuilder This commit introduces a DateTimeFormatter within the DeviceMeasurementBuilder for accurate date-time formatting. Changes also include updated attribute naming for 'location' and 'dateObserved', adhering to the FIWARE Context Broker's supported format. --- .../model/builder/DeviceMeasurementBuilder.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/app/fivegla/fiware/model/builder/DeviceMeasurementBuilder.java b/src/main/java/de/app/fivegla/fiware/model/builder/DeviceMeasurementBuilder.java index 8f2ecbf..f8670e2 100644 --- a/src/main/java/de/app/fivegla/fiware/model/builder/DeviceMeasurementBuilder.java +++ b/src/main/java/de/app/fivegla/fiware/model/builder/DeviceMeasurementBuilder.java @@ -7,6 +7,8 @@ import de.app.fivegla.fiware.model.generic.Metadata; import java.time.Instant; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; /** @@ -16,6 +18,11 @@ public final class DeviceMeasurementBuilder { private final DeviceMeasurement deviceMeasurement; + private final DateTimeFormatter formatter = DateTimeFormatter + // The supported format for the FIWARE Context Broker is "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'". + // 2017-06-17T07:21:24.238Z + .ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + .withZone(ZoneId.systemDefault()); /** * The DeviceMeasurementBuilder class is responsible for building instances of the DeviceMeasurement class. @@ -46,8 +53,9 @@ public DeviceMeasurementBuilder withId(String id) { */ public DeviceMeasurementBuilder withLocation(double latitude, double longitude) { var attribute = new Attribute(); - attribute.setValue("{\"type\":\"Point\",\"coordinates\":[" + longitude + "," + latitude + "]}"); + attribute.setName("location"); attribute.setType(FiwareTypes.GEO_POINT.getKey()); + attribute.setValue("{\"type\":\"Point\",\"coordinates\":[" + longitude + "," + latitude + "]}"); deviceMeasurement.setLocation(attribute); return this; } @@ -68,9 +76,9 @@ public DeviceMeasurementBuilder withMeasurement(String name, String type, String measurement.setValue(value); var metadata = new ArrayList(); var dateObservedMetadata = new Metadata(); - dateObservedMetadata.setName("dateObservedMetadata"); + dateObservedMetadata.setName("dateObserved"); dateObservedMetadata.setType(FiwareTypes.DATE_TIME.getKey()); - dateObservedMetadata.setValue(dateObservedMetadata.toString()); + dateObservedMetadata.setValue(formatter.format(dateObserved)); metadata.add(dateObservedMetadata); if (null != metadataEntries && metadataEntries.length > 0) { for (var metadataEntry : metadataEntries) { From 495a44b99bb7fe035d7ac994ff3e42395e5f3d17 Mon Sep 17 00:00:00 2001 From: Sascha Doemer Date: Fri, 1 Mar 2024 21:46:38 +0100 Subject: [PATCH 2/3] Modify JSON formatting in Metadata class This commit changes the JSON string formatting method in the Metadata class. The value variable is now enclosed within quotation marks, ensuring proper JSON output irrespective of the value's data type. --- src/main/java/de/app/fivegla/fiware/model/generic/Metadata.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/app/fivegla/fiware/model/generic/Metadata.java b/src/main/java/de/app/fivegla/fiware/model/generic/Metadata.java index e9add85..7edbe14 100644 --- a/src/main/java/de/app/fivegla/fiware/model/generic/Metadata.java +++ b/src/main/java/de/app/fivegla/fiware/model/generic/Metadata.java @@ -35,6 +35,6 @@ public class Metadata { private String value; public String asJson() { - return "{\"name\":\"" + name + "\",\"type\":\"" + type + "\",\"value\":" + value + "}"; + return "{\"name\":\"" + name + "\",\"type\":\"" + type + "\",\"value\":\"" + value + "\"}"; } } From b190f76ae028f7924f554ec4b1b4b516250e66fa Mon Sep 17 00:00:00 2001 From: Sascha Doemer Date: Fri, 1 Mar 2024 21:47:39 +0100 Subject: [PATCH 3/3] Update version in pom.xml file The version of fiware-integration-layer in the pom.xml file has been updated from 10.1.0 to 10.2.0. This update signifies a minor release with bug fixes and feature improvements. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 926be72..bd14b95 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ de.app.5gla fiware-integration-layer - 10.1.0 + 10.2.0 5gLa FIWARE integration layer https://github.com/vitrum-connect/5gla-fiware-integration-layer