Skip to content

Commit

Permalink
Refactor Fiware device ID generation (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
saschadoemer authored Feb 22, 2024
1 parent aa6f2b5 commit c076814
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 57 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<dependency>
<groupId>de.app.5gla</groupId>
<artifactId>fiware-integration-layer</artifactId>
<version>7.1.0</version>
<version>8.0.0</version>
<exclusions>
<!-- SLF4J NOP -->
<exclusion>
Expand Down
33 changes: 0 additions & 33 deletions src/main/java/de/app/fivegla/api/FiwareDevicMeasurementeId.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package de.app.fivegla.api;

import de.app.fivegla.config.manufacturer.CommonManufacturerConfiguration;
import de.app.fivegla.fiware.api.FiwareIdGenerator;
import de.app.fivegla.fiware.api.FiwareIdChecker;

/**
* Generates FIWARE device IDs.
*/
public class FiwareDeviceId {
public class FiwareIdGenerator {

/**
* Creates a FIWARE device ID.
Expand All @@ -26,7 +26,9 @@ public static String create(CommonManufacturerConfiguration manufacturerConfigur
* @return The FIWARE device ID.
*/
public static String create(CommonManufacturerConfiguration commonManufacturerConfiguration, String id) {
return FiwareIdGenerator.id(commonManufacturerConfiguration.fiwareDeviceIdPrefix() + id);
var fiwareId = commonManufacturerConfiguration.fiwareDeviceIdPrefix() + id;
FiwareIdChecker.check(fiwareId);
return fiwareId;
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.app.fivegla.integration.agranimo;


import de.app.fivegla.api.FiwareDeviceId;
import de.app.fivegla.api.FiwareIdGenerator;
import de.app.fivegla.api.Format;
import de.app.fivegla.config.ApplicationConfiguration;
import de.app.fivegla.config.manufacturer.CommonManufacturerConfiguration;
Expand Down Expand Up @@ -42,7 +42,7 @@ public void persist(Zone zone, SoilMoisture soilMoisture) {
private DeviceMeasurement createDeviceMeasurements(Zone zone, SoilMoisture soilMoisture) {
log.debug("Persisting data for zone: {}", zone.getId());
return DeviceMeasurement.builder()
.id(FiwareDeviceId.create(getManufacturerConfiguration(), soilMoisture.getDeviceId()))
.id(FiwareIdGenerator.create(getManufacturerConfiguration(), soilMoisture.getDeviceId()))
.manufacturerSpecificId(soilMoisture.getDeviceId())
.dateObserved(Format.format(soilMoisture.getTms()))
.location(Location.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.app.fivegla.integration.agvolution;


import de.app.fivegla.api.FiwareDeviceId;
import de.app.fivegla.api.FiwareIdGenerator;
import de.app.fivegla.api.Format;
import de.app.fivegla.config.ApplicationConfiguration;
import de.app.fivegla.config.manufacturer.CommonManufacturerConfiguration;
Expand Down Expand Up @@ -45,7 +45,7 @@ private List<DeviceMeasurement> createDeviceMeasurements(SeriesEntry seriesEntry
var deviceMeasurements = new ArrayList<DeviceMeasurement>();
timeSeriesEntry.getValues().forEach(timeSeriesValue -> {
var deviceMeasurement = DeviceMeasurement.builder()
.id(FiwareDeviceId.create(getManufacturerConfiguration(), seriesEntry.getDeviceId()))
.id(FiwareIdGenerator.create(getManufacturerConfiguration(), seriesEntry.getDeviceId()))
.manufacturerSpecificId(seriesEntry.getDeviceId())
.dateObserved(Format.format(timeSeriesValue.getTime()))
.location(Location.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.app.fivegla.integration.farm21;


import de.app.fivegla.api.FiwareDeviceId;
import de.app.fivegla.api.FiwareIdGenerator;
import de.app.fivegla.api.Format;
import de.app.fivegla.config.ApplicationConfiguration;
import de.app.fivegla.config.manufacturer.CommonManufacturerConfiguration;
Expand Down Expand Up @@ -103,7 +103,7 @@ private DeviceMeasurement.DeviceMeasurementBuilder createDefaultDeviceMeasuremen
log.debug("Persisting sensor data for sensor: {}", sensor);
log.debug("Persisting sensor data: {}", sensorData);
return DeviceMeasurement.builder()
.id(FiwareDeviceId.create(getManufacturerConfiguration(), String.valueOf(sensor.getId())))
.id(FiwareIdGenerator.create(getManufacturerConfiguration(), String.valueOf(sensor.getId())))
.manufacturerSpecificId(String.valueOf(sensor.getId()))
.dateObserved(Format.format(sensorData.getMeasuredAt()))
.location(Location.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package de.app.fivegla.integration.micasense;


import de.app.fivegla.api.FiwareDevicMeasurementeId;
import de.app.fivegla.api.FiwareDeviceId;
import de.app.fivegla.api.FiwareIdGenerator;
import de.app.fivegla.config.ApplicationConfiguration;
import de.app.fivegla.config.manufacturer.CommonManufacturerConfiguration;
import de.app.fivegla.fiware.DroneDeviceMeasurementIntegrationService;
Expand Down Expand Up @@ -37,7 +36,7 @@ public void createDroneDeviceMeasurement(String droneId, MicaSenseImage image) {
var droneDeviceMeasurement = DroneDeviceMeasurement.builder()
.deviceMeasurement(createDefaultDeviceMeasurement(droneId, image)
.build())
.id(FiwareDevicMeasurementeId.create(getManufacturerConfiguration(), image.getOid()))
.id(FiwareIdGenerator.create(getManufacturerConfiguration(), image.getOid()))
.channel(image.getChannel().name())
.imagePath(imagePathBaseUrl + image.getOid())
.build();
Expand All @@ -47,7 +46,7 @@ public void createDroneDeviceMeasurement(String droneId, MicaSenseImage image) {
private DeviceMeasurement.DeviceMeasurementBuilder createDefaultDeviceMeasurement(String droneId, MicaSenseImage image) {
log.debug("Persisting drone image for drone: {}", image.getDroneId());
return DeviceMeasurement.builder()
.id(FiwareDeviceId.create(getManufacturerConfiguration(), droneId))
.id(FiwareIdGenerator.create(getManufacturerConfiguration(), droneId))
.manufacturerSpecificId(droneId)
.dateObserved(InstantFormatter.format(image.getMeasuredAt()))
.location(image.getLocation());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package de.app.fivegla.integration.micasense;

import de.app.fivegla.api.FiwareIdGenerator;
import de.app.fivegla.api.dto.SortableImageOids;
import de.app.fivegla.fiware.api.FiwareIdGenerator;
import de.app.fivegla.config.ApplicationConfiguration;
import de.app.fivegla.config.manufacturer.CommonManufacturerConfiguration;
import de.app.fivegla.integration.micasense.events.ImageProcessingFinishedEvent;
import de.app.fivegla.integration.micasense.events.ImageProcessingStartedEvent;
import de.app.fivegla.integration.micasense.model.MicaSenseChannel;
Expand Down Expand Up @@ -31,6 +33,7 @@ public class MicaSenseIntegrationService {
private final ApplicationDataRepository applicationDataRepository;
private final ActiveMicaSenseTransactions activeMicaSenseTransactions;
private final ApplicationEventPublisher applicationEventPublisher;
private final ApplicationConfiguration applicationConfiguration;

/**
* Processes an image from the mica sense camera.
Expand All @@ -45,7 +48,7 @@ public String processImage(String transactionId, String droneId, MicaSenseChanne
log.debug("Channel for the image: {}.", micaSenseChannel);
log.debug("Location for the image: {}.", location.getCoordinates());
var micaSenseImage = applicationDataRepository.addMicaSenseImage(MicaSenseImage.builder()
.oid(FiwareIdGenerator.id())
.oid(FiwareIdGenerator.create(getManufacturerConfiguration(), droneId))
.channel(micaSenseChannel)
.droneId(droneId)
.transactionId(transactionId)
Expand Down Expand Up @@ -103,4 +106,9 @@ public List<SortableImageOids> getImageOidsForTransaction(String transactionId)
public void beginImageProcessing(String droneId, String transactionId) {
applicationEventPublisher.publishEvent(new ImageProcessingStartedEvent(this, droneId, transactionId));
}

private CommonManufacturerConfiguration getManufacturerConfiguration() {
return applicationConfiguration.getSensors().micasense();
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.app.fivegla.integration.sensoterra;


import de.app.fivegla.api.FiwareDeviceId;
import de.app.fivegla.api.FiwareIdGenerator;
import de.app.fivegla.api.Format;
import de.app.fivegla.config.ApplicationConfiguration;
import de.app.fivegla.config.manufacturer.SensoterraConfiguration;
Expand Down Expand Up @@ -38,7 +38,7 @@ private DeviceMeasurement createDeviceMeasurement(Probe probe, ProbeData probeDa
log.debug("Persisting probe data for probe: {}", probe);
log.debug("Persisting probe data: {}", probeData);
return DeviceMeasurement.builder()
.id(FiwareDeviceId.create(getManufacturerConfiguration(), String.valueOf(probe.getId())))
.id(FiwareIdGenerator.create(getManufacturerConfiguration(), String.valueOf(probe.getId())))
.manufacturerSpecificId(String.valueOf(probe.getId()))
.dateObserved(Format.format(probeData.getTimestamp()))
.location(Location.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.app.fivegla.integration.sentek;


import de.app.fivegla.api.FiwareDeviceId;
import de.app.fivegla.api.FiwareIdGenerator;
import de.app.fivegla.api.Format;
import de.app.fivegla.config.ApplicationConfiguration;
import de.app.fivegla.config.manufacturer.CommonManufacturerConfiguration;
Expand Down Expand Up @@ -154,7 +154,7 @@ private DeviceMeasurement.DeviceMeasurementBuilder createDefaultDeviceMeasuremen
log.debug("Persisting sensor data for logger: {}", logger);
log.debug("Persisting sensor data: {}", reading);
return DeviceMeasurement.builder()
.id(FiwareDeviceId.create(getManufacturerConfiguration(), String.valueOf(logger.getId())))
.id(FiwareIdGenerator.create(getManufacturerConfiguration(), String.valueOf(logger.getId())))
.manufacturerSpecificId(String.valueOf(logger.getId()))
.dateObserved(Format.format(reading.getDateTime()))
.location(Location.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.app.fivegla.integration.soilscout;


import de.app.fivegla.api.FiwareDeviceId;
import de.app.fivegla.api.FiwareIdGenerator;
import de.app.fivegla.config.ApplicationConfiguration;
import de.app.fivegla.config.manufacturer.CommonManufacturerConfiguration;
import de.app.fivegla.fiware.DeviceMeasurementIntegrationService;
Expand Down Expand Up @@ -74,7 +74,7 @@ public void persist(SensorData sensorData) {

private DeviceMeasurement.DeviceMeasurementBuilder createDefaultDeviceMeasurement(SensorData sensorData, Sensor sensor) {
return DeviceMeasurement.builder()
.id(FiwareDeviceId.create(getManufacturerConfiguration(), String.valueOf(sensor.getId())))
.id(FiwareIdGenerator.create(getManufacturerConfiguration(), String.valueOf(sensor.getId())))
.manufacturerSpecificId(String.valueOf(sensor.getId()))
.dateObserved(sensorData.getTimestamp().toString())
.location(Location.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.app.fivegla.integration.weenat;


import de.app.fivegla.api.FiwareDeviceId;
import de.app.fivegla.api.FiwareIdGenerator;
import de.app.fivegla.api.Format;
import de.app.fivegla.config.ApplicationConfiguration;
import de.app.fivegla.config.manufacturer.WeenatConfiguration;
Expand Down Expand Up @@ -208,7 +208,7 @@ private DeviceMeasurement.DeviceMeasurementBuilder createDeviceMeasurement(Plot
log.debug("Persisting probe data for probe: {}", plot);
log.debug("Persisting measurement data: {}", measurement);
return DeviceMeasurement.builder()
.id(FiwareDeviceId.create(getManufacturerConfiguration(), String.valueOf(plot.getId())))
.id(FiwareIdGenerator.create(getManufacturerConfiguration(), String.valueOf(plot.getId())))
.manufacturerSpecificId(String.valueOf(plot.getId()))
.dateObserved(Format.format(measurement.getTimestamp()))
.location(Location.builder()
Expand Down

0 comments on commit c076814

Please sign in to comment.