Skip to content

Commit

Permalink
Revert "String hash table references instead of nested tables."
Browse files Browse the repository at this point in the history
This reverts commit a0d7909.
  • Loading branch information
mansoor-sajjad committed Oct 17, 2024
1 parent a0d7909 commit 2ffffc9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 41 deletions.
3 changes: 0 additions & 3 deletions src/main/java/no/entur/antu/config/NetexDataConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import no.entur.antu.netexdata.DefaultNetexDataRepository;
import no.entur.antu.netexdata.NetexDataResource;
import org.entur.netex.validation.validator.jaxb.NetexDataRepository;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -30,7 +29,6 @@ NetexDataResource netexDataResource() {
@Profile("!test")
NetexDataRepository netexDataRepository(
NetexDataResource netexDataResource,
RedissonClient redissonClient,
@Qualifier(
SCHEDULED_STOP_POINT_AND_QUAY_ID_CACHE
) Map<String, Map<String, String>> scheduledStopPointAndQuayIdCache,
Expand All @@ -47,7 +45,6 @@ NetexDataRepository netexDataRepository(
) {
return new DefaultNetexDataRepository(
netexDataResource,
redissonClient,
scheduledStopPointAndQuayIdCache,
serviceLinksAndFromToScheduledStopPointIdCache,
lineInfoCache,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,14 @@ public NetexValidatorsRunner timetableDataValidatorsRunner(
);

List<DatasetValidator> netexTimetableDatasetValidators = List.of(
duplicateLineNameValidator,
stopPointsInVehicleJourneyValidator
duplicateLineNameValidator
// stopPointsInVehicleJourneyValidator
);

List<NetexDataCollector> commonDataCollectors = List.of(
lineInfoCollector,
serviceJourneyInterchangeInfoCollector,
serviceJourneyStopsCollector
// serviceJourneyStopsCollector,
serviceJourneyInterchangeInfoCollector
);

return new NetexValidatorsRunner(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collectors;
import no.entur.antu.exception.AntuException;
import org.entur.netex.validation.validator.jaxb.*;
import org.entur.netex.validation.validator.model.*;
import org.redisson.RedissonLocalCachedMap;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -23,7 +21,6 @@ public class DefaultNetexDataRepository implements NetexDataRepository {
);

private final NetexDataResource netexDataResource;
private final RedissonClient redissonClient;
private final Map<String, Map<String, String>> scheduledStopPointAndQuayIdCache;
private final Map<String, Map<String, String>> serviceLinksAndFromToScheduledStopPointIdCache;
private final Map<String, List<String>> lineInfoCache;
Expand All @@ -32,15 +29,13 @@ public class DefaultNetexDataRepository implements NetexDataRepository {

public DefaultNetexDataRepository(
NetexDataResource netexDataResource,
RedissonClient redissonClient,
Map<String, Map<String, String>> scheduledStopPointAndQuayIdCache,
Map<String, Map<String, String>> serviceLinksAndFromToScheduledStopPointIdCache,
Map<String, List<String>> lineInfoCache,
Map<String, Map<String, List<String>>> serviceJourneyStopsCache,
Map<String, List<String>> serviceJourneyInterchangeInfoCache
) {
this.netexDataResource = netexDataResource;
this.redissonClient = redissonClient;
this.scheduledStopPointAndQuayIdCache = scheduledStopPointAndQuayIdCache;
this.serviceLinksAndFromToScheduledStopPointIdCache =
serviceLinksAndFromToScheduledStopPointIdCache;
Expand Down Expand Up @@ -110,20 +105,24 @@ public List<ServiceJourneyStop> serviceJourneyStops(
String validationReportId,
ServiceJourneyId serviceJourneyId
) {
if (
serviceJourneyStopsCache instanceof RedissonLocalCachedMap<String, Map<String, List<String>>> localCachedMap
) {
return localCachedMap
.keySet(validationReportId + "*")
.stream()
.map(localCachedMap::get)
.flatMap(m -> m.entrySet().stream())
.filter(e -> e.getKey().equals(serviceJourneyId.id()))
.flatMap(e -> e.getValue().stream())
.map(ServiceJourneyStop::fromString)
.toList();
Map<String, List<String>> serviceJourneyStopsForReport =
serviceJourneyStopsCache.get(validationReportId);
if (serviceJourneyStopsForReport == null) {
throw new AntuException(
"ServiceJourneyStops cache not found for validation report with id: " +
validationReportId
);
}
return List.of();
return Optional
.ofNullable(serviceJourneyStopsForReport.get(serviceJourneyId.id()))
.map(serviceJourneyStops ->
serviceJourneyStops
.stream()
.map(ServiceJourneyStop::fromString)
.filter(ServiceJourneyStop::isValid)
.toList()
)
.orElse(List.of());
}

@Override
Expand Down Expand Up @@ -177,7 +176,7 @@ public void fillNetexDataCache(
.getFromToScheduledStopPointIdPerServiceLinkId()
.entrySet()
.stream()
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

serviceLinksAndFromToScheduledStopPointIdCache.merge(
validationReportId,
Expand All @@ -200,10 +199,6 @@ public void cleanUp(String validationReportId) {
scheduledStopPointAndQuayIdCache.remove(validationReportId);
serviceLinksAndFromToScheduledStopPointIdCache.remove(validationReportId);
lineInfoCache.remove(validationReportId);
redissonClient.getKeys().deleteByPattern(validationReportId + '*');
serviceJourneyStopsCache
.keySet()
.removeIf(k -> k.startsWith(validationReportId));
serviceJourneyStopsCache.remove(validationReportId);
serviceJourneyInterchangeInfoCache.remove(validationReportId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.entur.netex.validation.validator.model.ScheduledStopPointId;
import org.entur.netex.validation.validator.model.ServiceJourneyStop;
import org.redisson.api.RLock;
import org.redisson.api.RMap;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -45,6 +44,7 @@ protected void collectDataFromLineFile(

Map<String, List<String>> serviceJourneyStops = antuNetexData
.validServiceJourneys()
// TODO: unique service journeys ids
.map(serviceJourney -> {
Map<String, ScheduledStopPointId> scheduledStopPointIdMap =
AntuNetexData.scheduledStopPointIdByStopPointId(
Expand All @@ -71,7 +71,6 @@ protected void collectDataFromLineFile(

addServiceJourneyStops(
validationContext.getValidationReportId(),
validationContext.getFileName(),
serviceJourneyStops
);
}
Expand All @@ -85,20 +84,19 @@ protected void collectDataFromCommonFile(

private void addServiceJourneyStops(
String validationReportId,
String filename,
Map<String, List<String>> serviceJourneyStops
) {
RLock lock = redissonClient.getLock(validationReportId);
try {
lock.lock();

RMap<String, List<String>> serviceJourneyStopsMap = redissonClient.getMap(
validationReportId + "_" + filename
);
serviceJourneyStopsMap.putAll(serviceJourneyStops);
serviceJourneyStopsCache.put(
validationReportId + "_" + filename,
serviceJourneyStopsMap
serviceJourneyStopsCache.merge(
validationReportId,
serviceJourneyStops,
(existingMap, newMap) -> {
existingMap.putAll(newMap);
return existingMap;
}
);
} finally {
if (lock.isHeldByCurrentThread()) {
Expand Down

0 comments on commit 2ffffc9

Please sign in to comment.