diff --git a/data-collectors/carpooling/src/main/java/it/bz/odh/carpooling/SyncScheduler.java b/data-collectors/carpooling/src/main/java/it/bz/odh/carpooling/SyncScheduler.java index 7e582cac..d384d84a 100644 --- a/data-collectors/carpooling/src/main/java/it/bz/odh/carpooling/SyncScheduler.java +++ b/data-collectors/carpooling/src/main/java/it/bz/odh/carpooling/SyncScheduler.java @@ -26,14 +26,14 @@ public class SyncScheduler { private static final String DATATYPE_ITINERARY_ID = "itinerary_details"; @Value("${odh_client.period}") - private Integer period; + private Integer period; @Value("${odh_client.stationNamePrefix}") - private String stationNamePrefix; + private String stationNamePrefix; - @Lazy - @Autowired - private OdhClient odhClient; + @Lazy + @Autowired + private OdhClient odhClient; @Autowired private GoogleDriveConnector googleDriveConnector; @@ -45,19 +45,20 @@ public void carPoolingMain() { long currentTimeInMillis = System.currentTimeMillis(); - List carPoolingTripList = CsvFileUtilities.parseCarPoolingCsvData(googleDriveConnector.readRidesCsvContent()); + List carPoolingTripList = CsvFileUtilities + .parseCarPoolingCsvData(googleDriveConnector.readRidesCsvContent()); StationList stationList = new StationList(); DataMapDto dataMap = new DataMapDto<>(); LOG.info("got {} car pooling trips", carPoolingTripList.size()); - for(int i = 0; i < carPoolingTripList.size(); i++) { + for (int i = 0; i < carPoolingTripList.size(); i++) { CarPoolingTripDto carPoolingTrip = carPoolingTripList.get(i); StationDto stationDto = new StationDto(carPoolingTrip.getHashedId(), - stationNamePrefix + i, - carPoolingTrip.getStartLatApprox(), - carPoolingTrip.getStartLonApprox()); + stationNamePrefix + i, + carPoolingTrip.getStartLatApprox(), + carPoolingTrip.getStartLonApprox()); stationDto.setOrigin(odhClient.getProvenance().getLineage()); @@ -69,12 +70,17 @@ public void carPoolingMain() { stationList.add(stationDto); dataMap.addRecord(stationDto.getId(), DATATYPE_ITINERARY_ID, - new SimpleRecordDto(currentTimeInMillis, carPoolingTrip.toJson(), period)); + new SimpleRecordDto(currentTimeInMillis, carPoolingTrip.toJson(), period)); } LOG.info("sync {} car pooling stations", stationList.size()); try { - odhClient.syncStations(stationList); + if (stationList.isEmpty()) { + // deactivate all active stations, if none are present + odhClient.syncStationStates(stationNamePrefix, odhClient.getProvenance().getLineage(), null, false); + } else { + odhClient.syncStations(stationList); + } } catch (WebClientRequestException e) { LOG.error("Sync stations failed: Request exception: {}", e.getMessage()); } @@ -95,13 +101,11 @@ private void initDataTypes() { List odhDataTypeList = new ArrayList<>(); odhDataTypeList.add( - new DataTypeDto( - externalDataType.get("name"), - externalDataType.get("unit"), - externalDataType.get("name"), - "Instantaneous" - ) - ); + new DataTypeDto( + externalDataType.get("name"), + externalDataType.get("unit"), + externalDataType.get("name"), + "Instantaneous")); try { odhClient.syncDataTypes(odhDataTypeList);