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

Feature/fix npe in case there is no metadata #38

Merged
merged 4 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.0.0</version>
<version>10.1.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 @@ -62,22 +62,23 @@ public DeviceMeasurementBuilder withLocation(double latitude, double longitude)
* @return the DeviceMeasurementBuilder instance with the updated measurement attribute
*/
public DeviceMeasurementBuilder withMeasurement(String name, String type, String value, Instant dateObserved, MetadataEntry... metadataEntries) {
var attribute = new Attribute();
attribute.setName(name);
attribute.setType(type);
attribute.setValue(value);
var measurement = new Attribute();
measurement.setName(name);
measurement.setType(type);
measurement.setValue(value);
var metadata = new ArrayList<Metadata>();
var dateObservedMetadata = new Metadata();
dateObservedMetadata.setName("dateObservedMetadata");
dateObservedMetadata.setType(FiwareTypes.DATE_TIME.getKey());
dateObservedMetadata.setValue(dateObservedMetadata.toString());
metadata.add(dateObservedMetadata);
if (null != metadataEntries && metadataEntries.length > 0) {
var metadata = new ArrayList<Metadata>();
for (var metadataEntry : metadataEntries) {
metadata.add(metadataEntry.asMetadata());
}
attribute.setMetadata(metadata);
measurement.setMetadata(metadata);
}
deviceMeasurement.setMeasurement(attribute);
deviceMeasurement.setMeasurement(measurement);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public String asJson() {
}

private String metadataAsJson() {
return metadata.stream().map(Metadata::asJson).collect(Collectors.joining(","));
if (metadata == null || metadata.isEmpty()) {
return "";
} else {
return metadata.stream().map(Metadata::asJson).collect(Collectors.joining(","));
}
}
}
Loading