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/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 361a0cf4..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; @@ -24,7 +23,6 @@ @RequiredArgsConstructor public class AgranimoMeasurementImport { - private final ThirdPartyApiConfigurationService thirdPartyApiConfigurationService; private final AgranimoFiwareIntegrationServiceWrapper fiwareIntegrationServiceWrapper; private final AgranimoSoilMoistureIntegrationService agranimoSoilMoistureIntegrationService; private final AgranimoZoneService agranimoZoneService; @@ -61,7 +59,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/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 fd9e157e..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; @@ -24,7 +23,6 @@ public class AgvolutionMeasurementImport { private final AgvolutionSensorDataIntegrationService agvolutionSensorDataIntegrationService; - private final ThirdPartyApiConfigurationService thirdPartyApiConfigurationService; private final AgvolutionFiwareIntegrationServiceWrapper agvolutionFiwareIntegrationServiceWrapper; private final JobMonitor jobMonitor; @@ -53,7 +51,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/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 97263982..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; @@ -27,7 +26,6 @@ public class Farm21MeasurementImport { private final Farm21SensorDataIntegrationService farm21SensorDataIntegrationService; - private final ThirdPartyApiConfigurationService thirdPartyApiConfigurationService; private final Farm21FiwareIntegrationServiceWrapper farm21FiwareIntegrationServiceWrapper; private final JobMonitor jobMonitor; @@ -56,7 +54,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/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; 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 c3d05186..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; @@ -27,7 +26,6 @@ public class SensoterraMeasurementImport { private final ProbeDataIntegrationService probeDataIntegrationService; - private final ThirdPartyApiConfigurationService thirdPartyApiConfigurationService; private final SensoterraFiwareIntegrationServiceWrapper sensoterraFiwareIntegrationServiceWrapper; private final JobMonitor jobMonitor; @@ -56,7 +54,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/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 d5740ad9..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; @@ -27,7 +26,6 @@ public class SentekMeasurementImport { private final SentekSensorDataIntegrationService sentekSensorDataIntegrationService; - private final ThirdPartyApiConfigurationService thirdPartyApiConfigurationService; private final SentekFiwareIntegrationServiceWrapper sentekFiwareIntegrationServiceWrapper; private final JobMonitor jobMonitor; @@ -56,7 +54,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/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 14994c21..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; @@ -24,7 +23,6 @@ public class SoilScoutMeasurementImport { private final SoilScoutMeasurementIntegrationService soilScoutMeasurementIntegrationService; - private final ThirdPartyApiConfigurationService thirdPartyApiConfigurationService; private final SoilScoutFiwareIntegrationServiceWrapper fiwareIntegrationServiceWrapper; private final JobMonitor jobMonitor; @@ -53,7 +51,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/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 fd9653b0..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; @@ -26,7 +25,6 @@ public class WeenatMeasurementImport { private final WeenatMeasuresIntegrationService weenatMeasuresIntegrationService; - private final ThirdPartyApiConfigurationService thirdPartyApiConfigurationService; private final WeenatFiwareIntegrationServiceWrapper weenatFiwareIntegrationServiceWrapper; private final JobMonitor jobMonitor; @@ -55,7 +53,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); 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()); }