Skip to content

Commit

Permalink
carpooling: deactivate all active stations, if none are available
Browse files Browse the repository at this point in the history
  • Loading branch information
dulvui committed Feb 21, 2024
1 parent 5153e3a commit 16a8194
Showing 1 changed file with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,19 +45,20 @@ public void carPoolingMain() {

long currentTimeInMillis = System.currentTimeMillis();

List<CarPoolingTripDto> carPoolingTripList = CsvFileUtilities.parseCarPoolingCsvData(googleDriveConnector.readRidesCsvContent());
List<CarPoolingTripDto> carPoolingTripList = CsvFileUtilities
.parseCarPoolingCsvData(googleDriveConnector.readRidesCsvContent());

StationList stationList = new StationList();
DataMapDto<RecordDtoImpl> 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());

Expand All @@ -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());
}
Expand All @@ -95,13 +101,11 @@ private void initDataTypes() {

List<DataTypeDto> 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);
Expand Down

0 comments on commit 16a8194

Please sign in to comment.