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

Commit

Permalink
Feature/adapt fiware model to create geospatial data (#46)
Browse files Browse the repository at this point in the history
* Refactor DeviceMeasurement model class

The DeviceMeasurement class has been significantly modified by removing its dependency on the Attribute class. Several properties, including 'name', 'value', 'dateCreated', 'latitude', 'longitude' and 'externalDataReference', have been directly added and described in the DeviceMeasurement class. This update simplifies the structure of the model and makes it easier to interpret and maintain.

* Add type validation and refactor DeviceMeasurement building

Additional validation for the 'type' attribute was added to the validate method of the DeviceMeasurement class. Moreover, the building process of a DeviceMeasurement instance was refactored with the removal of the Attribute class dependency, directly assigning properties like 'name', 'value', 'dateCreated', latitude, longitude, and externalDataReference in the DeviceMeasurementBuilder. This refactoring simplifies the model's structure and its maintenance.

* Update version in pom.xml

The version of the 'fiware-integration-layer' in the pom.xml file was updated from 10.8.0 to 11.0.0, preparing for a new release. This change reflects the recent modifications in the project, including the addition of type validation in the DeviceMeasurement class and the refactoring of its building process, as well as removing the dependency on the Attribute class.

* Remove Attribute class from fiware model

The Attribute class from the fiware model has been deleted. This class was no longer necessary due to recent refactoring and changes in the structures, as its functionalities have been covered by other components. The project update also included other modifications, such as the version update in pom.xml, as part of the preparation for a new release.
  • Loading branch information
saschadoemer committed Mar 2, 2024
1 parent 4e672fd commit 92d180b
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 117 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.8.0</version>
<version>11.0.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 @@ -28,7 +28,6 @@ public DeviceMeasurementIntegrationService(String contextBrokerUrl, String tenan
* @param entity the device to create
*/
public void persist(DeviceMeasurement entity) {
entity.validate();
var updateOrCreateEntityRequest = UpdateOrCreateDeviceMeasurementRequest.builder()
.entities(List.of(entity))
.build();
Expand Down
91 changes: 83 additions & 8 deletions src/main/java/de/app/fivegla/fiware/model/DeviceMeasurement.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package de.app.fivegla.fiware.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import de.app.fivegla.fiware.api.FiwareType;
import de.app.fivegla.fiware.model.api.Validatable;
import de.app.fivegla.fiware.model.generic.Attribute;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

Expand Down Expand Up @@ -39,21 +40,95 @@ public class DeviceMeasurement implements Validatable {
private String type;

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

/**
* 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 double value;

/**
* The dateCreated represents the timestamp when an Attribute object is created.
* It is a private instance variable in the Attribute class.
* The date is stored as an Instant, which represents a moment on the timeline in UTC time zone.
*/
private Instant dateCreated;

/**
* 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;

/**
* The externalDataReference variable holds a reference to external data related to a device measurement.
* <p>
* This variable is of type String, and it is declared as private in the DeviceMeasurement class.
* <p>
* This variable is used to identify and reference external data associated with a device measurement. It can be used to link the measurement to data stored in an external system
* or to provide additional context or information about the measurement from an external source.
* <p>
* The value stored in this variable should be a valid reference to the external data, such as an identifier, URL, or any other format used to reference the data.¶* <p>
*/
private String externalDataReference;

public String asJson() {
return "{" +
" \"id\":\"" + id + "\"," +
" \"name\":\"" + name + "\"," +
" \"type\":\"" + type + "\"," +
" \"value\":" + value + "," +
" \"externalDataLink\":" + (StringUtils.isNotBlank(externalDataReference) ? externalDataReference : " ") + "\"," +
" \"dateCreated\":" + dateCreatedAsJson() + "," +
" \"location\":" + locationAsJson() +
"}";
}

private String dateCreatedAsJson() {
return "{" +
" \"type\":\"" + FiwareType.DATE_TIME.getKey() + "\"," +
" \"value\":\"" + formatter.format(dateCreated) + "\"" +
"}";
}

private String locationAsJson() {
return "{" +
" \"type\":\"" + FiwareType.GEO_POINT.getKey() + "\"," +
" \"value\": {" +
" \"type\":\"Point\"," +
" \"coordinates\": [" + longitude + "," + latitude + "]" +
" }" +
"}";
}

@Override
public void validate() {
if (StringUtils.isBlank(id)) {
throw new IllegalArgumentException("The id of the device measurement must not be null or blank.");
}
if (measurement == null) {
throw new IllegalArgumentException("The measurement of the device measurement must not be null.");
if (StringUtils.isBlank(type)) {
throw new IllegalArgumentException("The type of the device measurement must not be null or blank.");
}
}

public String asJson() {
return "{\"id\":\"" + id + "\",\"type\":\"" + type + "\",\"measurement\":" + measurement.asJson() + "}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import de.app.fivegla.fiware.api.FiwareChecker;
import de.app.fivegla.fiware.api.FiwareType;
import de.app.fivegla.fiware.model.DeviceMeasurement;
import de.app.fivegla.fiware.model.generic.Attribute;

import java.time.Instant;

Expand Down Expand Up @@ -45,15 +44,24 @@ public DeviceMeasurementBuilder withId(String id) {
* @param dateCreated the date observed of the measurement attribute
* @return the DeviceMeasurementBuilder instance with the updated measurement attribute
*/
public DeviceMeasurementBuilder withMeasurement(String name, FiwareType fiwareType, String value, Instant dateCreated, double latitude, double longitude) {
var measurement = new Attribute();
measurement.setName(name);
measurement.setType(fiwareType.getKey());
measurement.setValue(value);
measurement.setDateCreated(dateCreated);
measurement.setLatitude(latitude);
measurement.setLongitude(longitude);
deviceMeasurement.setMeasurement(measurement);
public DeviceMeasurementBuilder withMeasurement(String name, FiwareType fiwareType, double value, Instant dateCreated, double latitude, double longitude) {
deviceMeasurement.setName(name);
deviceMeasurement.setType(fiwareType.getKey());
deviceMeasurement.setValue(value);
deviceMeasurement.setDateCreated(dateCreated);
deviceMeasurement.setLatitude(latitude);
deviceMeasurement.setLongitude(longitude);
return this;
}

/**
* Sets the external data reference for the device measurement.
*
* @param externalDataReference the external data reference to be set
* @return the DeviceMeasurementBuilder instance
*/
public DeviceMeasurementBuilder withExternalDataReference(String externalDataReference) {
deviceMeasurement.setExternalDataReference(externalDataReference);
return this;
}

Expand All @@ -69,6 +77,7 @@ public DeviceMeasurementBuilder withType(String type) {
}

public DeviceMeasurement build() {
deviceMeasurement.validate();
return deviceMeasurement;
}

Expand Down
97 changes: 0 additions & 97 deletions src/main/java/de/app/fivegla/fiware/model/generic/Attribute.java

This file was deleted.

0 comments on commit 92d180b

Please sign in to comment.