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

Commit

Permalink
Feature/add location to device for direct data logging (#25)
Browse files Browse the repository at this point in the history
* Add location attribute in Device model

Added a location attribute to the Device model to provide more detailed information about devices. The 'location' attribute will allow to track the whereabouts of a device, enhancing the application's device management capabilities. The DeviceCategory class was minimally modified for optimal code formatting.

* Update version in pom.xml

The version of the fiware-integration-layer in the pom.xml file has been updated from 6.0.0 to 6.1.0. This change reflects the addition of the 'location' attribute to the Device model, which enhances device tracking and management capabilities. Minor modifications were also made to the DeviceCategory class for improved code formatting.

* Added functionality to delete a device from the system

Imported FiwareIntegrationLayerException and added a delete function to the AbstractEntityIntegrationService class to allow deletion of a device from the system by id. A test has been written in DeviceIntegrationServiceIT to ensure its proper operation. This change was made to improve the device management, where we can now delete devices that are no longer used or invalid.
  • Loading branch information
saschadoemer authored Oct 24, 2023
1 parent 9b932b9 commit 81b0165
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
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>6.0.0</version>
<version>6.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 @@ -108,4 +108,36 @@ public Optional<T> read(String id) {
}
}

/**
* Deletes the device with the given id.
*
* @param id the id of the device to be deleted
* @return true if the delete operation is successful, false otherwise
* @throws FiwareIntegrationLayerException if an exception occurs during the delete operation
*/
public boolean delete(String id) {
if (exists(id)) {
var httpClient = HttpClient.newHttpClient();
var httpRequest = HttpRequest.newBuilder()
.header(CustomHeader.FIWARE_SERVICE, getTenant())
.uri(URI.create(contextBrokerUrlForCommands() + "/entities/" + id))
.DELETE().build();
try {
var response = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() != 204) {
log.warn("Device with the ID '{}' does not exist. Could not delete the device.", id);
log.debug("Response: " + response.body());
return false;
} else {
return true;
}
} catch (Exception e) {
throw new FiwareIntegrationLayerException("Could not check if device exists.", e);
}
} else {
log.warn("Device with the ID '{}' does not exist.", id);
throw new FiwareIntegrationLayerException("Could not delete the device, since it does not exist.");
}
}

}
5 changes: 5 additions & 0 deletions src/main/java/de/app/fivegla/fiware/model/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public class Device implements Validatable {
*/
private DeviceCategory deviceCategory;

/**
* The location of the device.
*/
private Location location;

@Override
public void validate() {
if (StringUtils.isBlank(id)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ public class DeviceCategory {
* The value of the device category.
*/
private List<String> value;

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.app.fivegla.fiware;

import de.app.fivegla.fiware.api.FiwareIntegrationLayerException;
import de.app.fivegla.fiware.api.enums.DeviceCategoryValues;
import de.app.fivegla.fiware.model.Device;
import de.app.fivegla.fiware.model.DeviceCategory;
Expand Down Expand Up @@ -59,4 +60,17 @@ void givenExistingDeviceWhenCheckingIfTheDeviceDoesExistTheServiceShouldReturnTr
Assertions.assertFalse(fiwareIntegrationService.exists("integration-test:does-not-exist"));
}

@Test
void givenExistingDeviceWhenDeletingIfTheDeviceDoesExistTheServiceShouldReturnTrue() {
var fiwareIntegrationService = new DeviceIntegrationService(contextBrokerUrl, tenant);
var id = "integration-test:" + UUID.randomUUID();
var device = Device.builder().id(id).deviceCategory(DeviceCategory.builder().value(List.of(DeviceCategoryValues.SoilScoutSensor.getKey())).build()).build();
fiwareIntegrationService.persist(device);
Assertions.assertTrue(fiwareIntegrationService.exists(id));
Assertions.assertTrue(fiwareIntegrationService.delete(id));
Assertions.assertFalse(fiwareIntegrationService.exists(id));
Assertions.assertThrows(FiwareIntegrationLayerException.class, () -> fiwareIntegrationService.delete(id));
}


}

0 comments on commit 81b0165

Please sign in to comment.