Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interchange wait time and active dates validation #611

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/no/entur/antu/config/NetexDataConfig.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package no.entur.antu.config;

import static no.entur.antu.config.cache.CacheConfig.ACTIVE_DATES_CACHE;
import static no.entur.antu.config.cache.CacheConfig.LINE_INFO_CACHE;
import static no.entur.antu.config.cache.CacheConfig.SERVICE_JOURNEY_DAY_TYPES_CACHE;
import static no.entur.antu.config.cache.CacheConfig.SERVICE_JOURNEY_INTERCHANGE_INFO_CACHE;
import static no.entur.antu.config.cache.CacheConfig.SERVICE_JOURNEY_OPERATING_DAYS_CACHE;
import static no.entur.antu.config.cache.CacheConfig.SERVICE_JOURNEY_STOPS_CACHE;

import java.util.List;
Expand All @@ -25,6 +28,15 @@ NetexDataRepository netexDataRepository(
@Qualifier(
SERVICE_JOURNEY_STOPS_CACHE
) Map<String, Map<String, List<String>>> serviceJourneyStopsCache,
@Qualifier(
SERVICE_JOURNEY_DAY_TYPES_CACHE
) Map<String, Map<String, String>> serviceJourneyDayTypesCache,
@Qualifier(
ACTIVE_DATES_CACHE
) Map<String, Map<String, String>> activeDatesCache,
@Qualifier(
SERVICE_JOURNEY_OPERATING_DAYS_CACHE
) Map<String, Map<String, String>> serviceJourneyOperatingDaysCache,
@Qualifier(
SERVICE_JOURNEY_INTERCHANGE_INFO_CACHE
) Map<String, List<String>> serviceJourneyInterchangeInfoCache
Expand All @@ -33,6 +45,9 @@ NetexDataRepository netexDataRepository(
redissonClient,
lineInfoCache,
serviceJourneyStopsCache,
serviceJourneyDayTypesCache,
activeDatesCache,
serviceJourneyOperatingDaysCache,
serviceJourneyInterchangeInfoCache
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@

import java.util.List;
import java.util.Set;
import no.entur.antu.netexdata.collectors.DatedServiceJourneysCollector;
import no.entur.antu.netexdata.collectors.LineInfoCollector;
import no.entur.antu.netexdata.collectors.ServiceJourneyDayTypesCollector;
import no.entur.antu.netexdata.collectors.ServiceJourneyInterchangeInfoCollector;
import no.entur.antu.netexdata.collectors.ServiceJourneyStopsCollector;
import no.entur.antu.netexdata.collectors.activedatecollector.ActiveDatesCollector;
import no.entur.antu.organisation.OrganisationRepository;
import no.entur.antu.validation.validator.id.NetexIdValidator;
import no.entur.antu.validation.validator.interchange.distance.UnexpectedInterchangeDistanceValidator;
import no.entur.antu.validation.validator.interchange.duplicate.DuplicateInterchangesValidator;
import no.entur.antu.validation.validator.interchange.mandatoryfields.MandatoryFieldsValidator;
import no.entur.antu.validation.validator.interchange.stoppoints.StopPointsInVehicleJourneyValidator;
import no.entur.antu.validation.validator.interchange.waittime.UnexpectedWaitTimeAndActiveDatesValidator;
import no.entur.antu.validation.validator.journeypattern.stoppoint.distance.UnexpectedDistanceBetweenStopPointsValidator;
import no.entur.antu.validation.validator.journeypattern.stoppoint.identicalstoppoints.IdenticalStopPointsValidator;
import no.entur.antu.validation.validator.journeypattern.stoppoint.samequayref.SameQuayRefValidator;
Expand All @@ -42,7 +46,10 @@
import no.entur.antu.validation.validator.servicelink.distance.UnexpectedDistanceInServiceLinkValidator;
import no.entur.antu.validation.validator.servicelink.stoppoints.MismatchedStopPointsValidator;
import no.entur.antu.validation.validator.xpath.EnturTimetableDataValidationTreeFactory;
import org.entur.netex.validation.validator.*;
import org.entur.netex.validation.validator.DatasetValidator;
import org.entur.netex.validation.validator.NetexValidatorsRunner;
import org.entur.netex.validation.validator.ValidationReportEntryFactory;
import org.entur.netex.validation.validator.XPathValidator;
import org.entur.netex.validation.validator.id.NetexIdUniquenessValidator;
import org.entur.netex.validation.validator.id.NetexReferenceValidator;
import org.entur.netex.validation.validator.id.ReferenceToValidEntityTypeValidator;
Expand Down Expand Up @@ -106,6 +113,19 @@ public DuplicateLineNameValidator duplicateLineNameValidator(
);
}

@Bean
public UnexpectedWaitTimeAndActiveDatesValidator unexpectedWaitTimeValidator(
@Qualifier(
"validationReportEntryFactory"
) ValidationReportEntryFactory validationReportEntryFactory,
NetexDataRepository netexDataRepository
) {
return new UnexpectedWaitTimeAndActiveDatesValidator(
validationReportEntryFactory,
netexDataRepository
);
}

@Bean
public NetexValidatorsRunner timetableDataValidatorsRunner(
@Qualifier(
Expand All @@ -125,10 +145,14 @@ public NetexValidatorsRunner timetableDataValidatorsRunner(
) NetexIdUniquenessValidator netexIdUniquenessValidator,
StopPointsInVehicleJourneyValidator stopPointsInVehicleJourneyValidator,
DuplicateLineNameValidator duplicateLineNameValidator,
UnexpectedWaitTimeAndActiveDatesValidator unexpectedWaitTimeAndActiveDatesValidator,
LineInfoCollector lineInfoCollector,
ServiceJourneyStopsCollector serviceJourneyStopsCollector,
ServiceJourneyInterchangeInfoCollector serviceJourneyInterchangeInfoCollector,
CommonDataRepositoryLoader commonDataRepository,
ActiveDatesCollector activeDatesCollector,
ServiceJourneyDayTypesCollector serviceJourneyDayTypesCollector,
DatedServiceJourneysCollector datedServiceJourneysCollector,
CommonDataRepositoryLoader commonDataRepositoryLoader,
NetexDataRepository netexDataRepository,
StopPlaceRepository stopPlaceRepository
) {
Expand Down Expand Up @@ -165,13 +189,17 @@ public NetexValidatorsRunner timetableDataValidatorsRunner(

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

List<NetexDataCollector> commonDataCollectors = List.of(
lineInfoCollector,
serviceJourneyInterchangeInfoCollector,
serviceJourneyStopsCollector
serviceJourneyStopsCollector,
activeDatesCollector,
serviceJourneyDayTypesCollector,
datedServiceJourneysCollector
);

return NetexValidatorsRunner
Expand All @@ -182,7 +210,7 @@ public NetexValidatorsRunner timetableDataValidatorsRunner(
.withJaxbValidators(jaxbValidators)
.withDatasetValidators(netexTimetableDatasetValidators)
.withNetexDataCollectors(commonDataCollectors)
.withCommonDataRepository(commonDataRepository)
.withCommonDataRepository(commonDataRepositoryLoader)
.withNetexDataRepository(netexDataRepository)
.withStopPlaceRepository(stopPlaceRepository)
.withValidationReportEntryFactory(validationReportEntryFactory)
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/no/entur/antu/config/cache/CacheConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ public class CacheConfig {
public static final String LINE_INFO_CACHE = "linesInfoCache";
public static final String SERVICE_JOURNEY_INTERCHANGE_INFO_CACHE =
"serviceJourneyInterchangeInfoCache";
public static final String SERVICE_JOURNEY_DAY_TYPES_CACHE =
"serviceJourneyDayTypesCache";
public static final String SERVICE_JOURNEY_STOPS_CACHE =
"serviceJourneyStopsCache";
public static final String SERVICE_JOURNEY_OPERATING_DAYS_CACHE =
"serviceJourneyOperatingDaysCache";
public static final String ACTIVE_DATES_CACHE = "activeDatesCache";
public static final String QUAY_ID_NOT_FOUND_CACHE = "quayIdNotFoundCache";

private static final Kryo5Codec DEFAULT_CODEC = new Kryo5Codec();
Expand Down Expand Up @@ -172,6 +177,17 @@ public Map<String, List<String>> serviceJourneyInterchangeInfoCache(
);
}

@Bean(name = SERVICE_JOURNEY_DAY_TYPES_CACHE)
public Map<String, Map<String, String>> serviceJourneyDayTypesCache(
RedissonClient redissonClient
) {
return getOrCreateReportScopedCache(
redissonClient,
SERVICE_JOURNEY_DAY_TYPES_CACHE,
new CompositeCodec(new StringCodec(), new StringCodec())
);
}

@Bean(name = SERVICE_JOURNEY_STOPS_CACHE)
public Map<String, Map<String, List<String>>> serviceJourneyStopsCache(
RedissonClient redissonClient
Expand All @@ -183,6 +199,28 @@ public Map<String, Map<String, List<String>>> serviceJourneyStopsCache(
);
}

@Bean(name = ACTIVE_DATES_CACHE)
public Map<String, Map<String, String>> activeDatesCache(
RedissonClient redissonClient
) {
return getOrCreateReportScopedCache(
redissonClient,
ACTIVE_DATES_CACHE,
new CompositeCodec(new StringCodec(), new StringCodec())
);
}

@Bean(name = SERVICE_JOURNEY_OPERATING_DAYS_CACHE)
public Map<String, Map<String, String>> serviceJourneyOperatingDaysCache(
RedissonClient redissonClient
) {
return getOrCreateReportScopedCache(
redissonClient,
SERVICE_JOURNEY_OPERATING_DAYS_CACHE,
new CompositeCodec(new StringCodec(), new StringCodec())
);
}

@Bean
public NetexIdRepository netexIdRepository(
RedissonClient redissonClient,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package no.entur.antu.config.cache;

import static no.entur.antu.config.cache.CacheConfig.ACTIVE_DATES_CACHE;
import static no.entur.antu.config.cache.CacheConfig.LINE_INFO_CACHE;
import static no.entur.antu.config.cache.CacheConfig.SERVICE_JOURNEY_DAY_TYPES_CACHE;
import static no.entur.antu.config.cache.CacheConfig.SERVICE_JOURNEY_INTERCHANGE_INFO_CACHE;
import static no.entur.antu.config.cache.CacheConfig.SERVICE_JOURNEY_OPERATING_DAYS_CACHE;
import static no.entur.antu.config.cache.CacheConfig.SERVICE_JOURNEY_STOPS_CACHE;

import java.util.List;
import java.util.Map;
import no.entur.antu.netexdata.collectors.DatedServiceJourneysCollector;
import no.entur.antu.netexdata.collectors.LineInfoCollector;
import no.entur.antu.netexdata.collectors.ServiceJourneyDayTypesCollector;
import no.entur.antu.netexdata.collectors.ServiceJourneyInterchangeInfoCollector;
import no.entur.antu.netexdata.collectors.ServiceJourneyStopsCollector;
import no.entur.antu.netexdata.collectors.activedatecollector.ActiveDatesCollector;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
Expand All @@ -25,6 +31,29 @@ public LineInfoCollector lineInfoScraper(
return new LineInfoCollector(redissonClient, lineInfoCache);
}

@Bean
public ActiveDatesCollector activeDatesCollector(
RedissonClient redissonClient,
@Qualifier(
ACTIVE_DATES_CACHE
) Map<String, Map<String, String>> activeDatesCache
) {
return new ActiveDatesCollector(redissonClient, activeDatesCache);
}

@Bean
public DatedServiceJourneysCollector datedServiceJourneysCollector(
RedissonClient redissonClient,
@Qualifier(
SERVICE_JOURNEY_OPERATING_DAYS_CACHE
) Map<String, Map<String, String>> serviceJourneyOperatingDaysCache
) {
return new DatedServiceJourneysCollector(
redissonClient,
serviceJourneyOperatingDaysCache
);
}

@Bean
public ServiceJourneyInterchangeInfoCollector serviceJourneyInterchangeInfoCollector(
RedissonClient redissonClient,
Expand All @@ -38,6 +67,19 @@ public ServiceJourneyInterchangeInfoCollector serviceJourneyInterchangeInfoColle
);
}

@Bean
public ServiceJourneyDayTypesCollector serviceJourneyDayTypesCollector(
RedissonClient redissonClient,
@Qualifier(
SERVICE_JOURNEY_DAY_TYPES_CACHE
) Map<String, Map<String, String>> serviceJourneyDayTypesCache
) {
return new ServiceJourneyDayTypesCollector(
redissonClient,
serviceJourneyDayTypesCache
);
}

@Bean
public ServiceJourneyStopsCollector serviceJourneyStopsCollector(
RedissonClient redissonClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import no.entur.antu.exception.AntuException;
import org.entur.netex.validation.validator.model.ActiveDates;
import org.entur.netex.validation.validator.model.ActiveDatesId;
Expand All @@ -23,15 +24,24 @@ public class DefaultNetexDataRepository implements NetexDataRepositoryLoader {

private final Map<String, List<String>> lineInfoCache;
private final Map<String, Map<String, List<String>>> serviceJourneyStopsCache;
private final Map<String, Map<String, String>> serviceJourneyDayTypesCache;
private final Map<String, Map<String, String>> activeDatesCache;
private final Map<String, Map<String, String>> serviceJourneyOperatingDaysCache;
private final Map<String, List<String>> serviceJourneyInterchangeInfoCache;

public DefaultNetexDataRepository(
Map<String, List<String>> lineInfoCache,
Map<String, Map<String, List<String>>> serviceJourneyStopsCache,
Map<String, Map<String, String>> serviceJourneyDayTypesCache,
Map<String, Map<String, String>> activeDatesCache,
Map<String, Map<String, String>> serviceJourneyOperatingDaysCache,
Map<String, List<String>> serviceJourneyInterchangeInfoCache
) {
this.lineInfoCache = lineInfoCache;
this.serviceJourneyStopsCache = serviceJourneyStopsCache;
this.serviceJourneyDayTypesCache = serviceJourneyDayTypesCache;
this.activeDatesCache = activeDatesCache;
this.serviceJourneyOperatingDaysCache = serviceJourneyOperatingDaysCache;
this.serviceJourneyInterchangeInfoCache =
serviceJourneyInterchangeInfoCache;
}
Expand Down Expand Up @@ -67,40 +77,79 @@ public Map<ServiceJourneyId, List<ServiceJourneyStop>> serviceJourneyStops(
);
}

@Override
public List<ServiceJourneyInterchangeInfo> serviceJourneyInterchangeInfos(
public Map<ServiceJourneyId, List<DayTypeId>> serviceJourneyDayTypes(
String validationReportId
) {
return Optional
.ofNullable(serviceJourneyInterchangeInfoCache)
.map(Map::entrySet)
return serviceJourneyDayTypesCache
.keySet()
.stream()
.flatMap(Set::stream)
.filter(entry -> entry.getKey().startsWith(validationReportId))
.flatMap(entry -> entry.getValue().stream())
.map(ServiceJourneyInterchangeInfo::fromString)
.toList();
.filter(k -> k.startsWith(validationReportId))
.map(serviceJourneyDayTypesCache::get)
.flatMap(m -> m.entrySet().stream())
.collect(
Collectors.toMap(
entry -> ServiceJourneyId.ofValidId(entry.getKey()),
entry ->
Stream.of(entry.getValue().split(",")).map(DayTypeId::new).toList(),
(p, n) -> n
)
);
}

@Override
public Map<ServiceJourneyId, List<DayTypeId>> serviceJourneyDayTypes(
public Map<ServiceJourneyId, List<OperatingDayId>> serviceJourneyOperatingDays(
String validationReportId
) {
throw new UnsupportedOperationException();
return serviceJourneyOperatingDaysCache
.keySet()
.stream()
.filter(k -> k.startsWith(validationReportId))
.map(serviceJourneyOperatingDaysCache::get)
.flatMap(m -> m.entrySet().stream())
.collect(
Collectors.toMap(
entry -> ServiceJourneyId.ofValidId(entry.getKey()),
entry ->
Stream
.of(entry.getValue().split(","))
.map(OperatingDayId::new)
.toList(),
(p, n) -> n
)
);
}

@Override
public Map<ActiveDatesId, ActiveDates> activeDates(
String validationReportId
) {
throw new UnsupportedOperationException();
return activeDatesCache
.keySet()
.stream()
.filter(k -> k.startsWith(validationReportId))
.map(activeDatesCache::get)
.flatMap(m -> m.entrySet().stream())
.collect(
Collectors.toMap(
entry -> ActiveDatesId.of(entry.getKey()),
entry -> ActiveDates.fromString(entry.getValue()),
(p, n) -> n
)
);
}

@Override
public Map<ServiceJourneyId, List<OperatingDayId>> serviceJourneyOperatingDays(
public List<ServiceJourneyInterchangeInfo> serviceJourneyInterchangeInfos(
String validationReportId
) {
throw new UnsupportedOperationException();
return Optional
.ofNullable(serviceJourneyInterchangeInfoCache)
.map(Map::entrySet)
.stream()
.flatMap(Set::stream)
.filter(entry -> entry.getKey().startsWith(validationReportId))
.flatMap(entry -> entry.getValue().stream())
.map(ServiceJourneyInterchangeInfo::fromString)
.toList();
}

@Override
Expand Down
Loading