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

Commit

Permalink
Feature/adapt location to create valid entries (#40)
Browse files Browse the repository at this point in the history
* Replace Attribute type with new Location type for device measurements

The "location" in DeviceMeasurements has been updated from the generic Attribute type to use a new explicit Location class. Correspondingly, the DeviceMeasurementBuilder has been adjusted to work with the Location class when setting the location. The format for geographical information in FiwareTypes was updated from "geo:point" to "geo:json" to align with this change.

* Update version in pom.xml

The version of the "fiware-integration-layer" artifact in pom.xml has been updated from 10.2.0 to 10.3.0. This is a routine version bump as part of our product lifecycle management.
  • Loading branch information
saschadoemer authored Mar 1, 2024
1 parent 0dc0b0d commit bfda5a9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 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.2.0</version>
<version>10.3.0</version>

<name>5gLa FIWARE integration layer</name>
<url>https://github.com/vitrum-connect/5gla-fiware-integration-layer</url>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/app/fivegla/fiware/api/FiwareTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
@Getter
public enum FiwareTypes {
GEO_POINT("geo:point"),
GEO_POINT("geo:json"),
DATE_TIME("DateTime"),
TEXT("Text");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import de.app.fivegla.fiware.model.api.Validatable;
import de.app.fivegla.fiware.model.generic.Attribute;
import de.app.fivegla.fiware.model.generic.Location;
import lombok.*;
import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -31,7 +32,7 @@ public class DeviceMeasurement implements Validatable {
/**
* The location of the device.
*/
private Attribute location;
private Location location;

/**
* The Attribute class represents an attribute with a name, type, and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import de.app.fivegla.fiware.api.FiwareTypes;
import de.app.fivegla.fiware.model.DeviceMeasurement;
import de.app.fivegla.fiware.model.generic.Attribute;
import de.app.fivegla.fiware.model.generic.Location;
import de.app.fivegla.fiware.model.generic.Metadata;

import java.time.Instant;
Expand Down Expand Up @@ -52,10 +53,9 @@ public DeviceMeasurementBuilder withId(String id) {
* @return the DeviceMeasurementBuilder instance with the updated location
*/
public DeviceMeasurementBuilder withLocation(double latitude, double longitude) {
var attribute = new Attribute();
attribute.setName("location");
attribute.setType(FiwareTypes.GEO_POINT.getKey());
attribute.setValue("{\"type\":\"Point\",\"coordinates\":[" + longitude + "," + latitude + "]}");
var attribute = new Location();
attribute.setLatitude(latitude);
attribute.setLongitude(longitude);
deviceMeasurement.setLocation(attribute);
return this;
}
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/de/app/fivegla/fiware/model/generic/Location.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package de.app.fivegla.fiware.model.generic;

import de.app.fivegla.fiware.api.FiwareTypes;
import lombok.Getter;
import lombok.Setter;

/**
* The Attribute class represents an attribute with a name, type, and value.
*/
@Getter
@Setter
public class Location {

/**
* The value of an Attribute.
* <p>
* This variable represents the value of an attribute. It is a private instance variable
* in the Attribute class. The value is stored as a String.
*/
private String value;

/**
* The latitude of a location.
* <p>
* This variable represents the latitude of a location. It is a private instance variable
* in the Location class which is a part of the Attribute class. The latitude is stored as a double.
* The latitude is used along with the longitude to represent a geographical point in the Fiware platform.
*/
private double latitude;

/**
* The longitude of a location.
* <p>
* This variable represents the longitude of a location. It is a private instance variable
* in the Location class which is a part of the Attribute class. The longitude is stored as a double.
* The longitude is used along with the latitude to represent a geographical point in the Fiware platform.
*/
private double longitude;

public String asJson() {
return "{\"type\":\"" + FiwareTypes.GEO_POINT.getKey() + "\",\"value\":{\"type\":\"Point\",\"coordinates\":[" + longitude + "," + latitude + "]}}";
}

}

0 comments on commit bfda5a9

Please sign in to comment.