Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Bugfix/fix invalid json (#39)
Browse files Browse the repository at this point in the history
* 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.

* 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.

* 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.
  • Loading branch information
saschadoemer authored Mar 1, 2024
1 parent a0366a7 commit 0dc0b0d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>de.app.5gla</groupId>
<artifactId>fiware-integration-layer</artifactId>
<version>10.1.0</version>
<version>10.2.0</version>

<name>5gLa FIWARE integration layer</name>
<url>https://github.com/vitrum-connect/5gla-fiware-integration-layer</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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.
Expand Down Expand Up @@ -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;
}
Expand All @@ -68,9 +76,9 @@ public DeviceMeasurementBuilder withMeasurement(String name, String type, String
measurement.setValue(value);
var metadata = new ArrayList<Metadata>();
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "\"}";
}
}

0 comments on commit 0dc0b0d

Please sign in to comment.