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 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) { 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 + "\"}"; } }