From 053a1b1c3855c823e153460ea4bb16872f66e6e8 Mon Sep 17 00:00:00 2001 From: Sascha Doemer Date: Thu, 13 Jun 2024 17:35:27 +0200 Subject: [PATCH 1/5] Refactor data import event handling and update methods This change refactors data import event handling in the application to use the id of the ThirdPartyApiConfiguration instead of the whole object. It also relocates the updateLastRun method call to the handleDataImportEvent method from various import classes to keep the logic in one place. This ensures consistency and prevents potential errors if an event is fired without an existing ThirdPartyApiConfiguration. --- src/main/java/de/app/fivegla/api/Error.java | 3 +- .../ThirdPartyApiConfigurationService.java | 11 +++++ .../ThirdPartyApiConfigurationController.java | 2 +- .../fivegla/event/DataImportEventHandler.java | 47 ++++++++----------- .../fivegla/event/events/DataImportEvent.java | 6 +-- .../agranimo/AgranimoMeasurementImport.java | 1 - .../AgvolutionMeasurementImport.java | 1 - .../farm21/Farm21MeasurementImport.java | 1 - .../SensoterraMeasurementImport.java | 1 - .../sentek/SentekMeasurementImport.java | 1 - .../soilscout/SoilScoutMeasurementImport.java | 1 - .../weenat/WeenatMeasurementImport.java | 1 - 12 files changed, 36 insertions(+), 40 deletions(-) diff --git a/src/main/java/de/app/fivegla/api/Error.java b/src/main/java/de/app/fivegla/api/Error.java index de66477f..8288c364 100644 --- a/src/main/java/de/app/fivegla/api/Error.java +++ b/src/main/java/de/app/fivegla/api/Error.java @@ -47,7 +47,8 @@ public enum Error { TRYING_TO_UPDATE_GROUP_FROM_ANOTHER_TENANT(errorOf(37)), TRYING_TO_ACCESS_GROUP_FROM_ANOTHER_TENANT(errorOf(38)), TRYING_TO_DELETE_GROUP_FROM_ANOTHER_TENANT(errorOf(39)), - DEFAULT_GROUP_FOR_TENANT_NOT_FOUND(errorOf(40)); + DEFAULT_GROUP_FOR_TENANT_NOT_FOUND(errorOf(40)), + THIRD_PARTY_API_CONFIGURATION_NOT_FOUND(errorOf(41)); private static String errorOf(int i) { return ERR_ + String.format("%05d", i); diff --git a/src/main/java/de/app/fivegla/business/ThirdPartyApiConfigurationService.java b/src/main/java/de/app/fivegla/business/ThirdPartyApiConfigurationService.java index 6d11e327..cdf03bb3 100644 --- a/src/main/java/de/app/fivegla/business/ThirdPartyApiConfigurationService.java +++ b/src/main/java/de/app/fivegla/business/ThirdPartyApiConfigurationService.java @@ -10,6 +10,7 @@ import java.time.Instant; import java.util.Date; import java.util.List; +import java.util.Optional; @Slf4j @Service @@ -74,4 +75,14 @@ public void updateLastRun(ThirdPartyApiConfiguration thirdPartyApiConfiguration) thirdPartyApiConfiguration.setLastRun(Date.from(Instant.now())); thirdPartyApiConfigurationRepository.save(thirdPartyApiConfiguration); } + + /** + * Finds a ThirdPartyApiConfiguration by its ID. + * + * @param id The ID of the ThirdPartyApiConfiguration. + * @return An Optional containing the ThirdPartyApiConfiguration with the given ID, or an empty Optional if not found. + */ + public Optional findById(Long id) { + return thirdPartyApiConfigurationRepository.findById(id); + } } diff --git a/src/main/java/de/app/fivegla/controller/tenant/ThirdPartyApiConfigurationController.java b/src/main/java/de/app/fivegla/controller/tenant/ThirdPartyApiConfigurationController.java index 089c594b..214dad51 100644 --- a/src/main/java/de/app/fivegla/controller/tenant/ThirdPartyApiConfigurationController.java +++ b/src/main/java/de/app/fivegla/controller/tenant/ThirdPartyApiConfigurationController.java @@ -70,7 +70,7 @@ public ResponseEntity createThirdPartyApiConfiguration(@Vali var thirdPartyApiConfiguration = request.toEntity(); thirdPartyApiConfiguration.setTenant(tenant); var thirdPartyApiConfigurationCreated = thirdPartyApiConfigurationService.createThirdPartyApiConfiguration(thirdPartyApiConfiguration); - applicationEventPublisher.publishEvent(new DataImportEvent(thirdPartyApiConfigurationCreated)); + applicationEventPublisher.publishEvent(new DataImportEvent(thirdPartyApiConfigurationCreated.getId())); var response = CreateThirdPartyApiConfigurationResponse.builder() .thirdPartyApiConfiguration(ThirdPartyApiConfiguration.builder() .tenantId(thirdPartyApiConfigurationCreated.getTenant().getTenantId()) diff --git a/src/main/java/de/app/fivegla/event/DataImportEventHandler.java b/src/main/java/de/app/fivegla/event/DataImportEventHandler.java index 59ff348e..d723775e 100644 --- a/src/main/java/de/app/fivegla/event/DataImportEventHandler.java +++ b/src/main/java/de/app/fivegla/event/DataImportEventHandler.java @@ -1,14 +1,14 @@ package de.app.fivegla.event; -import de.app.fivegla.api.SubscriptionStatus; -import de.app.fivegla.api.enums.EntityType; +import de.app.fivegla.api.Error; +import de.app.fivegla.api.ErrorMessage; import de.app.fivegla.api.exceptions.BusinessException; import de.app.fivegla.business.TenantService; +import de.app.fivegla.business.ThirdPartyApiConfigurationService; import de.app.fivegla.event.events.DataImportEvent; import de.app.fivegla.integration.agranimo.AgranimoMeasurementImport; import de.app.fivegla.integration.agvolution.AgvolutionMeasurementImport; import de.app.fivegla.integration.farm21.Farm21MeasurementImport; -import de.app.fivegla.integration.fiware.SubscriptionIntegrationService; import de.app.fivegla.integration.sensoterra.SensoterraMeasurementImport; import de.app.fivegla.integration.sentek.SentekMeasurementImport; import de.app.fivegla.integration.soilscout.SoilScoutMeasurementImport; @@ -33,43 +33,36 @@ public class DataImportEventHandler { private final SensoterraMeasurementImport sensoterraMeasurementImport; private final SentekMeasurementImport sentekMeasurementImport; private final WeenatMeasurementImport weenatMeasurementImport; - private final SubscriptionStatus subscriptionStatus; private final TenantService tenantService; - private final SubscriptionIntegrationService subscriptionService; + private final ThirdPartyApiConfigurationService thirdPartyApiConfigurationService; @EventListener(DataImportEvent.class) public void handleDataImportEvent(DataImportEvent dataImportEvent) { - log.info("Handling data import event for tenant {} and manufacturer {}.", dataImportEvent.thirdPartyApiConfiguration().getTenant().getTenantId(), dataImportEvent.thirdPartyApiConfiguration().getManufacturer()); - var manufacturer = dataImportEvent.thirdPartyApiConfiguration().getManufacturer(); - var tenantId = dataImportEvent.thirdPartyApiConfiguration().getTenant().getTenantId(); + var thirdPartyApiConfiguration = thirdPartyApiConfigurationService.findById(dataImportEvent.thirdPartyApiConfigurationId()) + .orElseThrow(() -> new BusinessException(ErrorMessage.builder() + .error(Error.THIRD_PARTY_API_CONFIGURATION_NOT_FOUND) + .message("Third party API configuration not found.") + .build())); + log.info("Handling data import event for tenant {} and manufacturer {}.", thirdPartyApiConfiguration.getTenant().getTenantId(), thirdPartyApiConfiguration.getManufacturer()); + var manufacturer = thirdPartyApiConfiguration.getManufacturer(); + var tenantId = thirdPartyApiConfiguration.getTenant().getTenantId(); var optionalTenant = tenantService.findByTenantId(tenantId); if (optionalTenant.isEmpty()) { log.error("Tenant with id {} not found, not able to handle data import event", tenantId); } else { var tenant = optionalTenant.get(); - var config = dataImportEvent.thirdPartyApiConfiguration(); - if (subscriptionStatus.sendOutSubscriptions(tenantId)) { - try { - subscriptionService.subscribe(tenant, EntityType.values()); - log.info("Subscribed to device measurement notifications."); - subscriptionStatus.subscriptionSent(tenantId); - } catch (BusinessException e) { - log.error("Could not subscribe to device measurement notifications.", e); - } - } else { - log.info("Subscriptions are disabled. Not subscribing to device measurement notifications."); - } switch (manufacturer) { - case SOILSCOUT -> soilScoutScheduledMeasurementImport.run(tenant, config); - case AGVOLUTION -> agvolutionMeasurementImport.run(tenant, config); - case AGRANIMO -> agranimoMeasurementImport.run(tenant, config); - case FARM21 -> farm21MeasurementImport.run(tenant, config); - case SENSOTERRA -> sensoterraMeasurementImport.run(tenant, config); - case SENTEK -> sentekMeasurementImport.run(tenant, config); - case WEENAT -> weenatMeasurementImport.run(tenant, config); + case SOILSCOUT -> soilScoutScheduledMeasurementImport.run(tenant, thirdPartyApiConfiguration); + case AGVOLUTION -> agvolutionMeasurementImport.run(tenant, thirdPartyApiConfiguration); + case AGRANIMO -> agranimoMeasurementImport.run(tenant, thirdPartyApiConfiguration); + case FARM21 -> farm21MeasurementImport.run(tenant, thirdPartyApiConfiguration); + case SENSOTERRA -> sensoterraMeasurementImport.run(tenant, thirdPartyApiConfiguration); + case SENTEK -> sentekMeasurementImport.run(tenant, thirdPartyApiConfiguration); + case WEENAT -> weenatMeasurementImport.run(tenant, thirdPartyApiConfiguration); default -> throw new IllegalArgumentException("Unknown manufacturer: " + manufacturer); } } + thirdPartyApiConfigurationService.updateLastRun(thirdPartyApiConfiguration); } } diff --git a/src/main/java/de/app/fivegla/event/events/DataImportEvent.java b/src/main/java/de/app/fivegla/event/events/DataImportEvent.java index 0446a5d7..8532ff87 100644 --- a/src/main/java/de/app/fivegla/event/events/DataImportEvent.java +++ b/src/main/java/de/app/fivegla/event/events/DataImportEvent.java @@ -1,11 +1,9 @@ package de.app.fivegla.event.events; -import de.app.fivegla.persistence.entity.ThirdPartyApiConfiguration; - /** * Event for data import. * - * @param thirdPartyApiConfiguration The third-party API configuration. + * @param thirdPartyApiConfigurationId The ID of the third party API configuration. */ -public record DataImportEvent(ThirdPartyApiConfiguration thirdPartyApiConfiguration) { +public record DataImportEvent(Long thirdPartyApiConfigurationId) { } diff --git a/src/main/java/de/app/fivegla/integration/agranimo/AgranimoMeasurementImport.java b/src/main/java/de/app/fivegla/integration/agranimo/AgranimoMeasurementImport.java index 361a0cf4..580f078d 100644 --- a/src/main/java/de/app/fivegla/integration/agranimo/AgranimoMeasurementImport.java +++ b/src/main/java/de/app/fivegla/integration/agranimo/AgranimoMeasurementImport.java @@ -61,7 +61,6 @@ public void run(Tenant tenant, ThirdPartyApiConfiguration thirdPartyApiConfigura ); }); } - thirdPartyApiConfigurationService.updateLastRun(thirdPartyApiConfiguration); } catch (Exception e) { log.error("Error while running scheduled data import from Agranimo API", e); jobMonitor.logErrorDuringExecution(Manufacturer.AGRANIMO); diff --git a/src/main/java/de/app/fivegla/integration/agvolution/AgvolutionMeasurementImport.java b/src/main/java/de/app/fivegla/integration/agvolution/AgvolutionMeasurementImport.java index fd9e157e..a5614831 100644 --- a/src/main/java/de/app/fivegla/integration/agvolution/AgvolutionMeasurementImport.java +++ b/src/main/java/de/app/fivegla/integration/agvolution/AgvolutionMeasurementImport.java @@ -53,7 +53,6 @@ public void run(Tenant tenant, ThirdPartyApiConfiguration thirdPartyApiConfigura jobMonitor.logNrOfEntitiesFetched(Manufacturer.AGVOLUTION, seriesEntries.size()); seriesEntries.forEach(seriesEntry -> persistDataWithinFiware(tenant, seriesEntry)); } - thirdPartyApiConfigurationService.updateLastRun(thirdPartyApiConfiguration); } catch (Exception e) { log.error("Error while running scheduled data import from Agvolution API", e); jobMonitor.logErrorDuringExecution(Manufacturer.AGVOLUTION); diff --git a/src/main/java/de/app/fivegla/integration/farm21/Farm21MeasurementImport.java b/src/main/java/de/app/fivegla/integration/farm21/Farm21MeasurementImport.java index 97263982..8399fe81 100644 --- a/src/main/java/de/app/fivegla/integration/farm21/Farm21MeasurementImport.java +++ b/src/main/java/de/app/fivegla/integration/farm21/Farm21MeasurementImport.java @@ -56,7 +56,6 @@ public void run(Tenant tenant, ThirdPartyApiConfiguration thirdPartyApiConfigura jobMonitor.logNrOfEntitiesFetched(Manufacturer.FARM21, measurements.size()); measurements.entrySet().forEach(sensorListEntry -> persistDataWithinFiware(tenant, sensorListEntry)); } - thirdPartyApiConfigurationService.updateLastRun(thirdPartyApiConfiguration); } catch (Exception e) { log.error("Error while running scheduled data import from Farm21 API", e); jobMonitor.logErrorDuringExecution(Manufacturer.FARM21); diff --git a/src/main/java/de/app/fivegla/integration/sensoterra/SensoterraMeasurementImport.java b/src/main/java/de/app/fivegla/integration/sensoterra/SensoterraMeasurementImport.java index c3d05186..5cea94cc 100644 --- a/src/main/java/de/app/fivegla/integration/sensoterra/SensoterraMeasurementImport.java +++ b/src/main/java/de/app/fivegla/integration/sensoterra/SensoterraMeasurementImport.java @@ -56,7 +56,6 @@ public void run(Tenant tenant, ThirdPartyApiConfiguration thirdPartyApiConfigura jobMonitor.logNrOfEntitiesFetched(Manufacturer.SENSOTERRA, seriesEntries.size()); seriesEntries.entrySet().forEach(probeListEntry -> persistDataWithinFiware(tenant, probeListEntry)); } - thirdPartyApiConfigurationService.updateLastRun(thirdPartyApiConfiguration); } catch (Exception e) { log.error("Error while running scheduled data import from Sensoterra API", e); jobMonitor.logErrorDuringExecution(Manufacturer.SENSOTERRA); diff --git a/src/main/java/de/app/fivegla/integration/sentek/SentekMeasurementImport.java b/src/main/java/de/app/fivegla/integration/sentek/SentekMeasurementImport.java index d5740ad9..867dc71c 100644 --- a/src/main/java/de/app/fivegla/integration/sentek/SentekMeasurementImport.java +++ b/src/main/java/de/app/fivegla/integration/sentek/SentekMeasurementImport.java @@ -56,7 +56,6 @@ public void run(Tenant tenant, ThirdPartyApiConfiguration thirdPartyApiConfigura jobMonitor.logNrOfEntitiesFetched(Manufacturer.SENTEK, measurements.size()); measurements.entrySet().forEach(loggerListEntry -> persistDataWithinFiware(tenant, loggerListEntry)); } - thirdPartyApiConfigurationService.updateLastRun(thirdPartyApiConfiguration); } catch (Exception e) { log.error("Error while running scheduled data import from Sentek API", e); jobMonitor.logErrorDuringExecution(Manufacturer.SENTEK); diff --git a/src/main/java/de/app/fivegla/integration/soilscout/SoilScoutMeasurementImport.java b/src/main/java/de/app/fivegla/integration/soilscout/SoilScoutMeasurementImport.java index 14994c21..ddc0cd8a 100644 --- a/src/main/java/de/app/fivegla/integration/soilscout/SoilScoutMeasurementImport.java +++ b/src/main/java/de/app/fivegla/integration/soilscout/SoilScoutMeasurementImport.java @@ -53,7 +53,6 @@ public void run(Tenant tenant, ThirdPartyApiConfiguration thirdPartyApiConfigura log.info("Persisting {} measurements", measurements.size()); measurements.forEach(measurement -> persistDataWithinFiware(tenant, thirdPartyApiConfiguration, measurement)); } - thirdPartyApiConfigurationService.updateLastRun(thirdPartyApiConfiguration); } catch (Exception e) { log.error("Error while running scheduled data import from Soil Scout API", e); jobMonitor.logErrorDuringExecution(Manufacturer.SOILSCOUT); diff --git a/src/main/java/de/app/fivegla/integration/weenat/WeenatMeasurementImport.java b/src/main/java/de/app/fivegla/integration/weenat/WeenatMeasurementImport.java index fd9653b0..4f95b309 100644 --- a/src/main/java/de/app/fivegla/integration/weenat/WeenatMeasurementImport.java +++ b/src/main/java/de/app/fivegla/integration/weenat/WeenatMeasurementImport.java @@ -55,7 +55,6 @@ public void run(Tenant tenant, ThirdPartyApiConfiguration thirdPartyApiConfigura log.info("Persisting {} measurements", measurements.size()); measurements.entrySet().forEach(plotMeasurementsEntry -> persistDataWithinFiware(tenant, plotMeasurementsEntry)); } - thirdPartyApiConfigurationService.updateLastRun(thirdPartyApiConfiguration); } catch (Exception e) { log.error("Error while running scheduled data import from Weenat API", e); jobMonitor.logErrorDuringExecution(Manufacturer.WEENAT); From c56be67cc305269647a5679ea76b0a1bc7ff422d Mon Sep 17 00:00:00 2001 From: Sascha Doemer Date: Thu, 13 Jun 2024 17:36:31 +0200 Subject: [PATCH 2/5] Remove ThirdPartyApiConfigurationService dependency This commit removes the unused dependency on ThirdPartyApiConfigurationService from several classes. These include WeenatMeasurementImport, SensoterraMeasurementImport, and others. This change simplifies the codebase and removes unnecessary coupling. --- .../fivegla/integration/agranimo/AgranimoMeasurementImport.java | 1 - .../integration/agvolution/AgvolutionMeasurementImport.java | 1 - .../app/fivegla/integration/farm21/Farm21MeasurementImport.java | 1 - .../integration/sensoterra/SensoterraMeasurementImport.java | 1 - .../app/fivegla/integration/sentek/SentekMeasurementImport.java | 1 - .../integration/soilscout/SoilScoutMeasurementImport.java | 1 - .../app/fivegla/integration/weenat/WeenatMeasurementImport.java | 1 - 7 files changed, 7 deletions(-) diff --git a/src/main/java/de/app/fivegla/integration/agranimo/AgranimoMeasurementImport.java b/src/main/java/de/app/fivegla/integration/agranimo/AgranimoMeasurementImport.java index 580f078d..56a1f554 100644 --- a/src/main/java/de/app/fivegla/integration/agranimo/AgranimoMeasurementImport.java +++ b/src/main/java/de/app/fivegla/integration/agranimo/AgranimoMeasurementImport.java @@ -24,7 +24,6 @@ @RequiredArgsConstructor public class AgranimoMeasurementImport { - private final ThirdPartyApiConfigurationService thirdPartyApiConfigurationService; private final AgranimoFiwareIntegrationServiceWrapper fiwareIntegrationServiceWrapper; private final AgranimoSoilMoistureIntegrationService agranimoSoilMoistureIntegrationService; private final AgranimoZoneService agranimoZoneService; diff --git a/src/main/java/de/app/fivegla/integration/agvolution/AgvolutionMeasurementImport.java b/src/main/java/de/app/fivegla/integration/agvolution/AgvolutionMeasurementImport.java index a5614831..fb95a39b 100644 --- a/src/main/java/de/app/fivegla/integration/agvolution/AgvolutionMeasurementImport.java +++ b/src/main/java/de/app/fivegla/integration/agvolution/AgvolutionMeasurementImport.java @@ -24,7 +24,6 @@ public class AgvolutionMeasurementImport { private final AgvolutionSensorDataIntegrationService agvolutionSensorDataIntegrationService; - private final ThirdPartyApiConfigurationService thirdPartyApiConfigurationService; private final AgvolutionFiwareIntegrationServiceWrapper agvolutionFiwareIntegrationServiceWrapper; private final JobMonitor jobMonitor; diff --git a/src/main/java/de/app/fivegla/integration/farm21/Farm21MeasurementImport.java b/src/main/java/de/app/fivegla/integration/farm21/Farm21MeasurementImport.java index 8399fe81..eb7e1b6a 100644 --- a/src/main/java/de/app/fivegla/integration/farm21/Farm21MeasurementImport.java +++ b/src/main/java/de/app/fivegla/integration/farm21/Farm21MeasurementImport.java @@ -27,7 +27,6 @@ public class Farm21MeasurementImport { private final Farm21SensorDataIntegrationService farm21SensorDataIntegrationService; - private final ThirdPartyApiConfigurationService thirdPartyApiConfigurationService; private final Farm21FiwareIntegrationServiceWrapper farm21FiwareIntegrationServiceWrapper; private final JobMonitor jobMonitor; diff --git a/src/main/java/de/app/fivegla/integration/sensoterra/SensoterraMeasurementImport.java b/src/main/java/de/app/fivegla/integration/sensoterra/SensoterraMeasurementImport.java index 5cea94cc..f8f51b63 100644 --- a/src/main/java/de/app/fivegla/integration/sensoterra/SensoterraMeasurementImport.java +++ b/src/main/java/de/app/fivegla/integration/sensoterra/SensoterraMeasurementImport.java @@ -27,7 +27,6 @@ public class SensoterraMeasurementImport { private final ProbeDataIntegrationService probeDataIntegrationService; - private final ThirdPartyApiConfigurationService thirdPartyApiConfigurationService; private final SensoterraFiwareIntegrationServiceWrapper sensoterraFiwareIntegrationServiceWrapper; private final JobMonitor jobMonitor; diff --git a/src/main/java/de/app/fivegla/integration/sentek/SentekMeasurementImport.java b/src/main/java/de/app/fivegla/integration/sentek/SentekMeasurementImport.java index 867dc71c..84800950 100644 --- a/src/main/java/de/app/fivegla/integration/sentek/SentekMeasurementImport.java +++ b/src/main/java/de/app/fivegla/integration/sentek/SentekMeasurementImport.java @@ -27,7 +27,6 @@ public class SentekMeasurementImport { private final SentekSensorDataIntegrationService sentekSensorDataIntegrationService; - private final ThirdPartyApiConfigurationService thirdPartyApiConfigurationService; private final SentekFiwareIntegrationServiceWrapper sentekFiwareIntegrationServiceWrapper; private final JobMonitor jobMonitor; diff --git a/src/main/java/de/app/fivegla/integration/soilscout/SoilScoutMeasurementImport.java b/src/main/java/de/app/fivegla/integration/soilscout/SoilScoutMeasurementImport.java index ddc0cd8a..97b74652 100644 --- a/src/main/java/de/app/fivegla/integration/soilscout/SoilScoutMeasurementImport.java +++ b/src/main/java/de/app/fivegla/integration/soilscout/SoilScoutMeasurementImport.java @@ -24,7 +24,6 @@ public class SoilScoutMeasurementImport { private final SoilScoutMeasurementIntegrationService soilScoutMeasurementIntegrationService; - private final ThirdPartyApiConfigurationService thirdPartyApiConfigurationService; private final SoilScoutFiwareIntegrationServiceWrapper fiwareIntegrationServiceWrapper; private final JobMonitor jobMonitor; diff --git a/src/main/java/de/app/fivegla/integration/weenat/WeenatMeasurementImport.java b/src/main/java/de/app/fivegla/integration/weenat/WeenatMeasurementImport.java index 4f95b309..4bd85b17 100644 --- a/src/main/java/de/app/fivegla/integration/weenat/WeenatMeasurementImport.java +++ b/src/main/java/de/app/fivegla/integration/weenat/WeenatMeasurementImport.java @@ -26,7 +26,6 @@ public class WeenatMeasurementImport { private final WeenatMeasuresIntegrationService weenatMeasuresIntegrationService; - private final ThirdPartyApiConfigurationService thirdPartyApiConfigurationService; private final WeenatFiwareIntegrationServiceWrapper weenatFiwareIntegrationServiceWrapper; private final JobMonitor jobMonitor; From c29ff206d8824b47f480ed340f1b92fa04c44d71 Mon Sep 17 00:00:00 2001 From: Sascha Doemer Date: Thu, 13 Jun 2024 17:37:07 +0200 Subject: [PATCH 3/5] Remove unused imports across multiple files The commit involves removing unused imports from several classes belonging to different packages. Specifically, it's related to the removal of the ThirdPartyApiConfigurationService import and reordering of the EmptyAttribute and InstantAttribute imports in multiple integration files. --- .../agranimo/AgranimoFiwareIntegrationServiceWrapper.java | 2 +- .../fivegla/integration/agranimo/AgranimoMeasurementImport.java | 1 - .../agvolution/AgvolutionFiwareIntegrationServiceWrapper.java | 2 +- .../integration/agvolution/AgvolutionMeasurementImport.java | 1 - .../farm21/Farm21FiwareIntegrationServiceWrapper.java | 2 +- .../app/fivegla/integration/farm21/Farm21MeasurementImport.java | 1 - .../sensoterra/SensoterraFiwareIntegrationServiceWrapper.java | 2 +- .../integration/sensoterra/SensoterraMeasurementImport.java | 1 - .../sentek/SentekFiwareIntegrationServiceWrapper.java | 2 +- .../app/fivegla/integration/sentek/SentekMeasurementImport.java | 1 - .../soilscout/SoilScoutFiwareIntegrationServiceWrapper.java | 2 +- .../integration/soilscout/SoilScoutMeasurementImport.java | 1 - .../weenat/WeenatFiwareIntegrationServiceWrapper.java | 2 +- .../app/fivegla/integration/weenat/WeenatMeasurementImport.java | 1 - 14 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/app/fivegla/integration/agranimo/AgranimoFiwareIntegrationServiceWrapper.java b/src/main/java/de/app/fivegla/integration/agranimo/AgranimoFiwareIntegrationServiceWrapper.java index 7400b4cf..f6307089 100644 --- a/src/main/java/de/app/fivegla/integration/agranimo/AgranimoFiwareIntegrationServiceWrapper.java +++ b/src/main/java/de/app/fivegla/integration/agranimo/AgranimoFiwareIntegrationServiceWrapper.java @@ -7,8 +7,8 @@ import de.app.fivegla.integration.agranimo.model.Zone; import de.app.fivegla.integration.fiware.FiwareEntityIntegrationService; import de.app.fivegla.integration.fiware.model.DeviceMeasurement; -import de.app.fivegla.integration.fiware.model.internal.InstantAttribute; import de.app.fivegla.integration.fiware.model.internal.EmptyAttribute; +import de.app.fivegla.integration.fiware.model.internal.InstantAttribute; import de.app.fivegla.integration.fiware.model.internal.NumberAttribute; import de.app.fivegla.integration.fiware.model.internal.TextAttribute; import de.app.fivegla.persistence.entity.Tenant; diff --git a/src/main/java/de/app/fivegla/integration/agranimo/AgranimoMeasurementImport.java b/src/main/java/de/app/fivegla/integration/agranimo/AgranimoMeasurementImport.java index 56a1f554..b9596213 100644 --- a/src/main/java/de/app/fivegla/integration/agranimo/AgranimoMeasurementImport.java +++ b/src/main/java/de/app/fivegla/integration/agranimo/AgranimoMeasurementImport.java @@ -1,7 +1,6 @@ package de.app.fivegla.integration.agranimo; import de.app.fivegla.api.Manufacturer; -import de.app.fivegla.business.ThirdPartyApiConfigurationService; import de.app.fivegla.integration.agranimo.model.SoilMoisture; import de.app.fivegla.integration.agranimo.model.Zone; import de.app.fivegla.monitoring.JobMonitor; diff --git a/src/main/java/de/app/fivegla/integration/agvolution/AgvolutionFiwareIntegrationServiceWrapper.java b/src/main/java/de/app/fivegla/integration/agvolution/AgvolutionFiwareIntegrationServiceWrapper.java index 2a62b201..dc9a9029 100644 --- a/src/main/java/de/app/fivegla/integration/agvolution/AgvolutionFiwareIntegrationServiceWrapper.java +++ b/src/main/java/de/app/fivegla/integration/agvolution/AgvolutionFiwareIntegrationServiceWrapper.java @@ -7,8 +7,8 @@ import de.app.fivegla.integration.agvolution.model.TimeSeriesEntry; import de.app.fivegla.integration.fiware.FiwareEntityIntegrationService; import de.app.fivegla.integration.fiware.model.DeviceMeasurement; -import de.app.fivegla.integration.fiware.model.internal.InstantAttribute; import de.app.fivegla.integration.fiware.model.internal.EmptyAttribute; +import de.app.fivegla.integration.fiware.model.internal.InstantAttribute; import de.app.fivegla.integration.fiware.model.internal.NumberAttribute; import de.app.fivegla.integration.fiware.model.internal.TextAttribute; import de.app.fivegla.persistence.entity.Group; diff --git a/src/main/java/de/app/fivegla/integration/agvolution/AgvolutionMeasurementImport.java b/src/main/java/de/app/fivegla/integration/agvolution/AgvolutionMeasurementImport.java index fb95a39b..6efe3677 100644 --- a/src/main/java/de/app/fivegla/integration/agvolution/AgvolutionMeasurementImport.java +++ b/src/main/java/de/app/fivegla/integration/agvolution/AgvolutionMeasurementImport.java @@ -1,7 +1,6 @@ package de.app.fivegla.integration.agvolution; import de.app.fivegla.api.Manufacturer; -import de.app.fivegla.business.ThirdPartyApiConfigurationService; import de.app.fivegla.integration.agvolution.model.SeriesEntry; import de.app.fivegla.monitoring.JobMonitor; import de.app.fivegla.persistence.entity.Tenant; diff --git a/src/main/java/de/app/fivegla/integration/farm21/Farm21FiwareIntegrationServiceWrapper.java b/src/main/java/de/app/fivegla/integration/farm21/Farm21FiwareIntegrationServiceWrapper.java index 29069ba3..4312845f 100644 --- a/src/main/java/de/app/fivegla/integration/farm21/Farm21FiwareIntegrationServiceWrapper.java +++ b/src/main/java/de/app/fivegla/integration/farm21/Farm21FiwareIntegrationServiceWrapper.java @@ -7,8 +7,8 @@ import de.app.fivegla.integration.farm21.model.SensorData; import de.app.fivegla.integration.fiware.FiwareEntityIntegrationService; import de.app.fivegla.integration.fiware.model.DeviceMeasurement; -import de.app.fivegla.integration.fiware.model.internal.InstantAttribute; import de.app.fivegla.integration.fiware.model.internal.EmptyAttribute; +import de.app.fivegla.integration.fiware.model.internal.InstantAttribute; import de.app.fivegla.integration.fiware.model.internal.NumberAttribute; import de.app.fivegla.integration.fiware.model.internal.TextAttribute; import de.app.fivegla.persistence.entity.Tenant; diff --git a/src/main/java/de/app/fivegla/integration/farm21/Farm21MeasurementImport.java b/src/main/java/de/app/fivegla/integration/farm21/Farm21MeasurementImport.java index eb7e1b6a..d466f4c0 100644 --- a/src/main/java/de/app/fivegla/integration/farm21/Farm21MeasurementImport.java +++ b/src/main/java/de/app/fivegla/integration/farm21/Farm21MeasurementImport.java @@ -1,7 +1,6 @@ package de.app.fivegla.integration.farm21; import de.app.fivegla.api.Manufacturer; -import de.app.fivegla.business.ThirdPartyApiConfigurationService; import de.app.fivegla.integration.farm21.model.Sensor; import de.app.fivegla.integration.farm21.model.SensorData; import de.app.fivegla.monitoring.JobMonitor; diff --git a/src/main/java/de/app/fivegla/integration/sensoterra/SensoterraFiwareIntegrationServiceWrapper.java b/src/main/java/de/app/fivegla/integration/sensoterra/SensoterraFiwareIntegrationServiceWrapper.java index e8f3867d..a2a22bca 100644 --- a/src/main/java/de/app/fivegla/integration/sensoterra/SensoterraFiwareIntegrationServiceWrapper.java +++ b/src/main/java/de/app/fivegla/integration/sensoterra/SensoterraFiwareIntegrationServiceWrapper.java @@ -5,8 +5,8 @@ import de.app.fivegla.business.GroupService; import de.app.fivegla.integration.fiware.FiwareEntityIntegrationService; import de.app.fivegla.integration.fiware.model.DeviceMeasurement; -import de.app.fivegla.integration.fiware.model.internal.InstantAttribute; import de.app.fivegla.integration.fiware.model.internal.EmptyAttribute; +import de.app.fivegla.integration.fiware.model.internal.InstantAttribute; import de.app.fivegla.integration.fiware.model.internal.NumberAttribute; import de.app.fivegla.integration.fiware.model.internal.TextAttribute; import de.app.fivegla.integration.sensoterra.model.Probe; diff --git a/src/main/java/de/app/fivegla/integration/sensoterra/SensoterraMeasurementImport.java b/src/main/java/de/app/fivegla/integration/sensoterra/SensoterraMeasurementImport.java index f8f51b63..cdd57e19 100644 --- a/src/main/java/de/app/fivegla/integration/sensoterra/SensoterraMeasurementImport.java +++ b/src/main/java/de/app/fivegla/integration/sensoterra/SensoterraMeasurementImport.java @@ -1,7 +1,6 @@ package de.app.fivegla.integration.sensoterra; import de.app.fivegla.api.Manufacturer; -import de.app.fivegla.business.ThirdPartyApiConfigurationService; import de.app.fivegla.integration.sensoterra.model.Probe; import de.app.fivegla.integration.sensoterra.model.ProbeData; import de.app.fivegla.monitoring.JobMonitor; diff --git a/src/main/java/de/app/fivegla/integration/sentek/SentekFiwareIntegrationServiceWrapper.java b/src/main/java/de/app/fivegla/integration/sentek/SentekFiwareIntegrationServiceWrapper.java index 541420c7..4846a713 100644 --- a/src/main/java/de/app/fivegla/integration/sentek/SentekFiwareIntegrationServiceWrapper.java +++ b/src/main/java/de/app/fivegla/integration/sentek/SentekFiwareIntegrationServiceWrapper.java @@ -5,8 +5,8 @@ import de.app.fivegla.business.GroupService; import de.app.fivegla.integration.fiware.FiwareEntityIntegrationService; import de.app.fivegla.integration.fiware.model.DeviceMeasurement; -import de.app.fivegla.integration.fiware.model.internal.InstantAttribute; import de.app.fivegla.integration.fiware.model.internal.EmptyAttribute; +import de.app.fivegla.integration.fiware.model.internal.InstantAttribute; import de.app.fivegla.integration.fiware.model.internal.NumberAttribute; import de.app.fivegla.integration.fiware.model.internal.TextAttribute; import de.app.fivegla.integration.sentek.model.csv.Reading; diff --git a/src/main/java/de/app/fivegla/integration/sentek/SentekMeasurementImport.java b/src/main/java/de/app/fivegla/integration/sentek/SentekMeasurementImport.java index 84800950..29c5f9e8 100644 --- a/src/main/java/de/app/fivegla/integration/sentek/SentekMeasurementImport.java +++ b/src/main/java/de/app/fivegla/integration/sentek/SentekMeasurementImport.java @@ -1,7 +1,6 @@ package de.app.fivegla.integration.sentek; import de.app.fivegla.api.Manufacturer; -import de.app.fivegla.business.ThirdPartyApiConfigurationService; import de.app.fivegla.integration.sentek.model.csv.Reading; import de.app.fivegla.integration.sentek.model.xml.Logger; import de.app.fivegla.monitoring.JobMonitor; diff --git a/src/main/java/de/app/fivegla/integration/soilscout/SoilScoutFiwareIntegrationServiceWrapper.java b/src/main/java/de/app/fivegla/integration/soilscout/SoilScoutFiwareIntegrationServiceWrapper.java index e0ecd401..ae118b2b 100644 --- a/src/main/java/de/app/fivegla/integration/soilscout/SoilScoutFiwareIntegrationServiceWrapper.java +++ b/src/main/java/de/app/fivegla/integration/soilscout/SoilScoutFiwareIntegrationServiceWrapper.java @@ -5,8 +5,8 @@ import de.app.fivegla.business.GroupService; import de.app.fivegla.integration.fiware.FiwareEntityIntegrationService; import de.app.fivegla.integration.fiware.model.DeviceMeasurement; -import de.app.fivegla.integration.fiware.model.internal.InstantAttribute; import de.app.fivegla.integration.fiware.model.internal.EmptyAttribute; +import de.app.fivegla.integration.fiware.model.internal.InstantAttribute; import de.app.fivegla.integration.fiware.model.internal.NumberAttribute; import de.app.fivegla.integration.fiware.model.internal.TextAttribute; import de.app.fivegla.integration.soilscout.model.SensorData; diff --git a/src/main/java/de/app/fivegla/integration/soilscout/SoilScoutMeasurementImport.java b/src/main/java/de/app/fivegla/integration/soilscout/SoilScoutMeasurementImport.java index 97b74652..a8b55963 100644 --- a/src/main/java/de/app/fivegla/integration/soilscout/SoilScoutMeasurementImport.java +++ b/src/main/java/de/app/fivegla/integration/soilscout/SoilScoutMeasurementImport.java @@ -1,7 +1,6 @@ package de.app.fivegla.integration.soilscout; import de.app.fivegla.api.Manufacturer; -import de.app.fivegla.business.ThirdPartyApiConfigurationService; import de.app.fivegla.integration.soilscout.model.SensorData; import de.app.fivegla.monitoring.JobMonitor; import de.app.fivegla.persistence.entity.Tenant; diff --git a/src/main/java/de/app/fivegla/integration/weenat/WeenatFiwareIntegrationServiceWrapper.java b/src/main/java/de/app/fivegla/integration/weenat/WeenatFiwareIntegrationServiceWrapper.java index 7d133938..b03f88ec 100644 --- a/src/main/java/de/app/fivegla/integration/weenat/WeenatFiwareIntegrationServiceWrapper.java +++ b/src/main/java/de/app/fivegla/integration/weenat/WeenatFiwareIntegrationServiceWrapper.java @@ -5,8 +5,8 @@ import de.app.fivegla.business.GroupService; import de.app.fivegla.integration.fiware.FiwareEntityIntegrationService; import de.app.fivegla.integration.fiware.model.DeviceMeasurement; -import de.app.fivegla.integration.fiware.model.internal.InstantAttribute; import de.app.fivegla.integration.fiware.model.internal.EmptyAttribute; +import de.app.fivegla.integration.fiware.model.internal.InstantAttribute; import de.app.fivegla.integration.fiware.model.internal.NumberAttribute; import de.app.fivegla.integration.fiware.model.internal.TextAttribute; import de.app.fivegla.integration.weenat.model.Measurements; diff --git a/src/main/java/de/app/fivegla/integration/weenat/WeenatMeasurementImport.java b/src/main/java/de/app/fivegla/integration/weenat/WeenatMeasurementImport.java index 4bd85b17..af83ce45 100644 --- a/src/main/java/de/app/fivegla/integration/weenat/WeenatMeasurementImport.java +++ b/src/main/java/de/app/fivegla/integration/weenat/WeenatMeasurementImport.java @@ -1,7 +1,6 @@ package de.app.fivegla.integration.weenat; import de.app.fivegla.api.Manufacturer; -import de.app.fivegla.business.ThirdPartyApiConfigurationService; import de.app.fivegla.integration.weenat.model.Measurements; import de.app.fivegla.integration.weenat.model.Plot; import de.app.fivegla.monitoring.JobMonitor; From af7f85f0cfa563791068efd4ad55e525d58641f4 Mon Sep 17 00:00:00 2001 From: Sascha Doemer Date: Thu, 13 Jun 2024 17:51:20 +0200 Subject: [PATCH 4/5] Update DataImportEvent parameter Amended the DataImportEvent parameter to use the configuration ID instead of the configuration object. This change ensures only necessary data is sent with the event, rather than the whole configuration object. --- src/main/java/de/app/fivegla/scheduled/DataImportScheduler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/app/fivegla/scheduled/DataImportScheduler.java b/src/main/java/de/app/fivegla/scheduled/DataImportScheduler.java index d0b97d48..fbf95090 100644 --- a/src/main/java/de/app/fivegla/scheduled/DataImportScheduler.java +++ b/src/main/java/de/app/fivegla/scheduled/DataImportScheduler.java @@ -36,7 +36,7 @@ public void scheduleDataImport() { } else { tenants.forEach(tenant -> thirdPartyApiConfigurationService.getThirdPartyApiConfigurations(tenant.getTenantId()).forEach(configuration -> { if (configuration.isEnabled()) { - applicationEventPublisher.publishEvent(new DataImportEvent(configuration)); + applicationEventPublisher.publishEvent(new DataImportEvent(configuration.getId())); } else { log.info("Skipping data import for tenant {} and manufacturer {} because it is disabled.", tenant.getName(), configuration.getManufacturer()); } From 1d95700275146d0fabbe58c21d6855854fd7a672 Mon Sep 17 00:00:00 2001 From: Sascha Doemer Date: Thu, 13 Jun 2024 17:58:40 +0200 Subject: [PATCH 5/5] Add trim function to JSON fields Updated the asJson() functions in the DevicePosition, DeviceMeasurement, and AgriCrop classes. Every field of the returned JSON string now includes the trim() function, removing any leading or trailing white spaces. This change ensures consistency and cleanliness in the JSON strings produced by these methods. --- .../integration/fiware/model/AgriCrop.java | 10 +++++----- .../fiware/model/DeviceMeasurement.java | 16 ++++++++-------- .../integration/fiware/model/DevicePosition.java | 14 +++++++------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main/java/de/app/fivegla/integration/fiware/model/AgriCrop.java b/src/main/java/de/app/fivegla/integration/fiware/model/AgriCrop.java index aa6ea2ca..ddaccf02 100644 --- a/src/main/java/de/app/fivegla/integration/fiware/model/AgriCrop.java +++ b/src/main/java/de/app/fivegla/integration/fiware/model/AgriCrop.java @@ -25,11 +25,11 @@ public record AgriCrop( public String asJson() { validate(); var json = "{" + - " \"id\":\"" + id + "\"," + - " \"type\":\"" + type + "\"," + - " \"customGroup\":" + group.asJson() + "," + - " \"dateCreated\":" + dateCreated.asJson() + "," + - " \"coordinates\":" + coordinatesAsJson(coordinates) + + " \"id\":\"" + id.trim() + "\"," + + " \"type\":\"" + type.trim() + "\"," + + " \"customGroup\":" + group.asJson().trim() + "," + + " \"dateCreated\":" + dateCreated.asJson().trim() + "," + + " \"coordinates\":" + coordinatesAsJson(coordinates).trim() + "}"; log.debug("{} as JSON: {}", this.getClass().getSimpleName(), json); return json; diff --git a/src/main/java/de/app/fivegla/integration/fiware/model/DeviceMeasurement.java b/src/main/java/de/app/fivegla/integration/fiware/model/DeviceMeasurement.java index a2a0a367..a81af1e9 100644 --- a/src/main/java/de/app/fivegla/integration/fiware/model/DeviceMeasurement.java +++ b/src/main/java/de/app/fivegla/integration/fiware/model/DeviceMeasurement.java @@ -26,14 +26,14 @@ public record DeviceMeasurement( public String asJson() { validate(); var json = "{" + - " \"id\":\"" + id + "\"," + - " \"type\":\"" + type + "\"," + - " \"customGroup\":" + group.asJson() + "," + - " \"name\":" + name.asJson() + "," + - " \"controlledProperty\":" + controlledProperty.asJson() + "," + - " \"externalDataReference\":" + externalDataReference.asJson() + "," + - " \"dateCreated\":" + dateCreated.asJson() + "," + - " \"location\":" + locationAsJson(latitude, longitude) + + " \"id\":\"" + id.trim() + "\"," + + " \"type\":\"" + type.trim() + "\"," + + " \"customGroup\":" + group.asJson().trim() + "," + + " \"name\":" + name.asJson().trim() + "," + + " \"controlledProperty\":" + controlledProperty.asJson().trim() + "," + + " \"externalDataReference\":" + externalDataReference.asJson().trim() + "," + + " \"dateCreated\":" + dateCreated.asJson().trim() + "," + + " \"location\":" + locationAsJson(latitude, longitude).trim() + "}"; log.debug("{} as JSON: {}", this.getClass().getSimpleName(), json); return json; diff --git a/src/main/java/de/app/fivegla/integration/fiware/model/DevicePosition.java b/src/main/java/de/app/fivegla/integration/fiware/model/DevicePosition.java index 3900f71f..f317a93b 100644 --- a/src/main/java/de/app/fivegla/integration/fiware/model/DevicePosition.java +++ b/src/main/java/de/app/fivegla/integration/fiware/model/DevicePosition.java @@ -25,13 +25,13 @@ public record DevicePosition( public String asJson() { validate(); var json = "{" + - " \"id\":\"" + id + "\"," + - " \"type\":\"" + type + "\"," + - " \"customGroup\":" + group.asJson() + "," + - " \"transactionId\":" + transactionId.asJson() + "," + - " \"deviceId\":" + deviceId.asJson() + "," + - " \"dateCreated\":" + dateCreated.asJson() + "," + - " \"location\":" + locationAsJson(latitude, longitude) + + " \"id\":\"" + id.trim() + "\"," + + " \"type\":\"" + type.trim() + "\"," + + " \"customGroup\":" + group.asJson().trim() + "," + + " \"transactionId\":" + transactionId.asJson().trim() + "," + + " \"deviceId\":" + deviceId.asJson().trim() + "," + + " \"dateCreated\":" + dateCreated.asJson().trim() + "," + + " \"location\":" + locationAsJson(latitude, longitude).trim() + "}"; log.debug("{} as JSON: {}", this.getClass().getSimpleName(), json); return json;