Skip to content

Commit 7049634

Browse files
Interchange wait time and active dates validation
1 parent df90fec commit 7049634

28 files changed

+5049
-122
lines changed

src/main/java/no/entur/antu/config/NetexDataConfig.java

+15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package no.entur.antu.config;
22

3+
import static no.entur.antu.config.cache.CacheConfig.ACTIVE_DATES_CACHE;
34
import static no.entur.antu.config.cache.CacheConfig.LINE_INFO_CACHE;
5+
import static no.entur.antu.config.cache.CacheConfig.SERVICE_JOURNEY_DAY_TYPES_CACHE;
46
import static no.entur.antu.config.cache.CacheConfig.SERVICE_JOURNEY_INTERCHANGE_INFO_CACHE;
7+
import static no.entur.antu.config.cache.CacheConfig.SERVICE_JOURNEY_OPERATING_DAYS_CACHE;
58
import static no.entur.antu.config.cache.CacheConfig.SERVICE_JOURNEY_STOPS_CACHE;
69

710
import java.util.List;
@@ -25,6 +28,15 @@ NetexDataRepository netexDataRepository(
2528
@Qualifier(
2629
SERVICE_JOURNEY_STOPS_CACHE
2730
) Map<String, Map<String, List<String>>> serviceJourneyStopsCache,
31+
@Qualifier(
32+
SERVICE_JOURNEY_DAY_TYPES_CACHE
33+
) Map<String, Map<String, String>> serviceJourneyDayTypesCache,
34+
@Qualifier(
35+
ACTIVE_DATES_CACHE
36+
) Map<String, Map<String, String>> activeDatesCache,
37+
@Qualifier(
38+
SERVICE_JOURNEY_OPERATING_DAYS_CACHE
39+
) Map<String, Map<String, String>> serviceJourneyOperatingDaysCache,
2840
@Qualifier(
2941
SERVICE_JOURNEY_INTERCHANGE_INFO_CACHE
3042
) Map<String, List<String>> serviceJourneyInterchangeInfoCache
@@ -33,6 +45,9 @@ NetexDataRepository netexDataRepository(
3345
redissonClient,
3446
lineInfoCache,
3547
serviceJourneyStopsCache,
48+
serviceJourneyDayTypesCache,
49+
activeDatesCache,
50+
serviceJourneyOperatingDaysCache,
3651
serviceJourneyInterchangeInfoCache
3752
);
3853
}

src/main/java/no/entur/antu/config/TimetableDataValidatorConfig.java

+33-5
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@
1818

1919
import java.util.List;
2020
import java.util.Set;
21+
import no.entur.antu.netexdata.collectors.DatedServiceJourneysCollector;
2122
import no.entur.antu.netexdata.collectors.LineInfoCollector;
23+
import no.entur.antu.netexdata.collectors.ServiceJourneyDayTypesCollector;
2224
import no.entur.antu.netexdata.collectors.ServiceJourneyInterchangeInfoCollector;
2325
import no.entur.antu.netexdata.collectors.ServiceJourneyStopsCollector;
26+
import no.entur.antu.netexdata.collectors.activedatecollector.ActiveDatesCollector;
2427
import no.entur.antu.organisation.OrganisationRepository;
2528
import no.entur.antu.validation.validator.id.NetexIdValidator;
2629
import no.entur.antu.validation.validator.interchange.distance.UnexpectedInterchangeDistanceValidator;
2730
import no.entur.antu.validation.validator.interchange.duplicate.DuplicateInterchangesValidator;
2831
import no.entur.antu.validation.validator.interchange.mandatoryfields.MandatoryFieldsValidator;
2932
import no.entur.antu.validation.validator.interchange.stoppoints.StopPointsInVehicleJourneyValidator;
33+
import no.entur.antu.validation.validator.interchange.waittime.UnexpectedWaitTimeAndActiveDatesValidator;
3034
import no.entur.antu.validation.validator.journeypattern.stoppoint.distance.UnexpectedDistanceBetweenStopPointsValidator;
3135
import no.entur.antu.validation.validator.journeypattern.stoppoint.identicalstoppoints.IdenticalStopPointsValidator;
3236
import no.entur.antu.validation.validator.journeypattern.stoppoint.samequayref.SameQuayRefValidator;
@@ -41,7 +45,10 @@
4145
import no.entur.antu.validation.validator.servicelink.distance.UnexpectedDistanceInServiceLinkValidator;
4246
import no.entur.antu.validation.validator.servicelink.stoppoints.MismatchedStopPointsValidator;
4347
import no.entur.antu.validation.validator.xpath.EnturTimetableDataValidationTreeFactory;
44-
import org.entur.netex.validation.validator.*;
48+
import org.entur.netex.validation.validator.DatasetValidator;
49+
import org.entur.netex.validation.validator.NetexValidatorsRunner;
50+
import org.entur.netex.validation.validator.ValidationReportEntryFactory;
51+
import org.entur.netex.validation.validator.XPathValidator;
4552
import org.entur.netex.validation.validator.id.NetexIdUniquenessValidator;
4653
import org.entur.netex.validation.validator.id.NetexReferenceValidator;
4754
import org.entur.netex.validation.validator.id.ReferenceToValidEntityTypeValidator;
@@ -180,6 +187,19 @@ public DuplicateLineNameValidator duplicateLineNameValidator(
180187
);
181188
}
182189

190+
@Bean
191+
public UnexpectedWaitTimeAndActiveDatesValidator unexpectedWaitTimeValidator(
192+
@Qualifier(
193+
"validationReportEntryFactory"
194+
) ValidationReportEntryFactory validationReportEntryFactory,
195+
NetexDataRepository netexDataRepository
196+
) {
197+
return new UnexpectedWaitTimeAndActiveDatesValidator(
198+
validationReportEntryFactory,
199+
netexDataRepository
200+
);
201+
}
202+
183203
@Bean
184204
public NetexValidatorsRunner timetableDataValidatorsRunner(
185205
@Qualifier(
@@ -214,10 +234,14 @@ public NetexValidatorsRunner timetableDataValidatorsRunner(
214234
StopPointsInVehicleJourneyValidator stopPointsInVehicleJourneyValidator,
215235
DuplicateLineNameValidator duplicateLineNameValidator,
216236
MissingReplacementValidator missingReplacementValidator,
237+
UnexpectedWaitTimeAndActiveDatesValidator unexpectedWaitTimeAndActiveDatesValidator,
217238
LineInfoCollector lineInfoCollector,
218239
ServiceJourneyStopsCollector serviceJourneyStopsCollector,
219240
ServiceJourneyInterchangeInfoCollector serviceJourneyInterchangeInfoCollector,
220-
CommonDataRepositoryLoader commonDataRepository,
241+
ActiveDatesCollector activeDatesCollector,
242+
ServiceJourneyDayTypesCollector serviceJourneyDayTypesCollector,
243+
DatedServiceJourneysCollector datedServiceJourneysCollector,
244+
CommonDataRepositoryLoader commonDataRepositoryLoader,
221245
NetexDataRepository netexDataRepository,
222246
StopPlaceRepository stopPlaceRepository
223247
) {
@@ -254,13 +278,17 @@ public NetexValidatorsRunner timetableDataValidatorsRunner(
254278

255279
List<DatasetValidator> netexTimetableDatasetValidators = List.of(
256280
duplicateLineNameValidator,
257-
stopPointsInVehicleJourneyValidator
281+
stopPointsInVehicleJourneyValidator,
282+
unexpectedWaitTimeAndActiveDatesValidator
258283
);
259284

260285
List<NetexDataCollector> commonDataCollectors = List.of(
261286
lineInfoCollector,
262287
serviceJourneyInterchangeInfoCollector,
263-
serviceJourneyStopsCollector
288+
serviceJourneyStopsCollector,
289+
activeDatesCollector,
290+
serviceJourneyDayTypesCollector,
291+
datedServiceJourneysCollector
264292
);
265293

266294
return NetexValidatorsRunner
@@ -271,7 +299,7 @@ public NetexValidatorsRunner timetableDataValidatorsRunner(
271299
.withJaxbValidators(jaxbValidators)
272300
.withDatasetValidators(netexTimetableDatasetValidators)
273301
.withNetexDataCollectors(commonDataCollectors)
274-
.withCommonDataRepository(commonDataRepository)
302+
.withCommonDataRepository(commonDataRepositoryLoader)
275303
.withNetexDataRepository(netexDataRepository)
276304
.withStopPlaceRepository(stopPlaceRepository)
277305
.withValidationReportEntryFactory(validationReportEntryFactory)

src/main/java/no/entur/antu/config/cache/CacheConfig.java

+38
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@ public class CacheConfig {
4040
public static final String LINE_INFO_CACHE = "linesInfoCache";
4141
public static final String SERVICE_JOURNEY_INTERCHANGE_INFO_CACHE =
4242
"serviceJourneyInterchangeInfoCache";
43+
public static final String SERVICE_JOURNEY_DAY_TYPES_CACHE =
44+
"serviceJourneyDayTypesCache";
4345
public static final String SERVICE_JOURNEY_STOPS_CACHE =
4446
"serviceJourneyStopsCache";
47+
public static final String SERVICE_JOURNEY_OPERATING_DAYS_CACHE =
48+
"serviceJourneyOperatingDaysCache";
49+
public static final String ACTIVE_DATES_CACHE = "activeDatesCache";
4550
public static final String QUAY_ID_NOT_FOUND_CACHE = "quayIdNotFoundCache";
4651

4752
private static final Kryo5Codec DEFAULT_CODEC = new Kryo5Codec();
@@ -172,6 +177,17 @@ public Map<String, List<String>> serviceJourneyInterchangeInfoCache(
172177
);
173178
}
174179

180+
@Bean(name = SERVICE_JOURNEY_DAY_TYPES_CACHE)
181+
public Map<String, Map<String, String>> serviceJourneyDayTypesCache(
182+
RedissonClient redissonClient
183+
) {
184+
return getOrCreateReportScopedCache(
185+
redissonClient,
186+
SERVICE_JOURNEY_DAY_TYPES_CACHE,
187+
new CompositeCodec(new StringCodec(), new StringCodec())
188+
);
189+
}
190+
175191
@Bean(name = SERVICE_JOURNEY_STOPS_CACHE)
176192
public Map<String, Map<String, List<String>>> serviceJourneyStopsCache(
177193
RedissonClient redissonClient
@@ -183,6 +199,28 @@ public Map<String, Map<String, List<String>>> serviceJourneyStopsCache(
183199
);
184200
}
185201

202+
@Bean(name = ACTIVE_DATES_CACHE)
203+
public Map<String, Map<String, String>> activeDatesCache(
204+
RedissonClient redissonClient
205+
) {
206+
return getOrCreateReportScopedCache(
207+
redissonClient,
208+
ACTIVE_DATES_CACHE,
209+
new CompositeCodec(new StringCodec(), new StringCodec())
210+
);
211+
}
212+
213+
@Bean(name = SERVICE_JOURNEY_OPERATING_DAYS_CACHE)
214+
public Map<String, Map<String, String>> serviceJourneyOperatingDaysCache(
215+
RedissonClient redissonClient
216+
) {
217+
return getOrCreateReportScopedCache(
218+
redissonClient,
219+
SERVICE_JOURNEY_OPERATING_DAYS_CACHE,
220+
new CompositeCodec(new StringCodec(), new StringCodec())
221+
);
222+
}
223+
186224
@Bean
187225
public NetexIdRepository netexIdRepository(
188226
RedissonClient redissonClient,

src/main/java/no/entur/antu/config/cache/NetexDataCollectorConfig.java

+42
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
package no.entur.antu.config.cache;
22

3+
import static no.entur.antu.config.cache.CacheConfig.ACTIVE_DATES_CACHE;
34
import static no.entur.antu.config.cache.CacheConfig.LINE_INFO_CACHE;
5+
import static no.entur.antu.config.cache.CacheConfig.SERVICE_JOURNEY_DAY_TYPES_CACHE;
46
import static no.entur.antu.config.cache.CacheConfig.SERVICE_JOURNEY_INTERCHANGE_INFO_CACHE;
7+
import static no.entur.antu.config.cache.CacheConfig.SERVICE_JOURNEY_OPERATING_DAYS_CACHE;
58
import static no.entur.antu.config.cache.CacheConfig.SERVICE_JOURNEY_STOPS_CACHE;
69

710
import java.util.List;
811
import java.util.Map;
12+
import no.entur.antu.netexdata.collectors.DatedServiceJourneysCollector;
913
import no.entur.antu.netexdata.collectors.LineInfoCollector;
14+
import no.entur.antu.netexdata.collectors.ServiceJourneyDayTypesCollector;
1015
import no.entur.antu.netexdata.collectors.ServiceJourneyInterchangeInfoCollector;
1116
import no.entur.antu.netexdata.collectors.ServiceJourneyStopsCollector;
17+
import no.entur.antu.netexdata.collectors.activedatecollector.ActiveDatesCollector;
1218
import org.redisson.api.RedissonClient;
1319
import org.springframework.beans.factory.annotation.Qualifier;
1420
import org.springframework.context.annotation.Bean;
@@ -25,6 +31,29 @@ public LineInfoCollector lineInfoScraper(
2531
return new LineInfoCollector(redissonClient, lineInfoCache);
2632
}
2733

34+
@Bean
35+
public ActiveDatesCollector activeDatesCollector(
36+
RedissonClient redissonClient,
37+
@Qualifier(
38+
ACTIVE_DATES_CACHE
39+
) Map<String, Map<String, String>> activeDatesCache
40+
) {
41+
return new ActiveDatesCollector(redissonClient, activeDatesCache);
42+
}
43+
44+
@Bean
45+
public DatedServiceJourneysCollector datedServiceJourneysCollector(
46+
RedissonClient redissonClient,
47+
@Qualifier(
48+
SERVICE_JOURNEY_OPERATING_DAYS_CACHE
49+
) Map<String, Map<String, String>> serviceJourneyOperatingDaysCache
50+
) {
51+
return new DatedServiceJourneysCollector(
52+
redissonClient,
53+
serviceJourneyOperatingDaysCache
54+
);
55+
}
56+
2857
@Bean
2958
public ServiceJourneyInterchangeInfoCollector serviceJourneyInterchangeInfoCollector(
3059
RedissonClient redissonClient,
@@ -38,6 +67,19 @@ public ServiceJourneyInterchangeInfoCollector serviceJourneyInterchangeInfoColle
3867
);
3968
}
4069

70+
@Bean
71+
public ServiceJourneyDayTypesCollector serviceJourneyDayTypesCollector(
72+
RedissonClient redissonClient,
73+
@Qualifier(
74+
SERVICE_JOURNEY_DAY_TYPES_CACHE
75+
) Map<String, Map<String, String>> serviceJourneyDayTypesCache
76+
) {
77+
return new ServiceJourneyDayTypesCollector(
78+
redissonClient,
79+
serviceJourneyDayTypesCache
80+
);
81+
}
82+
4183
@Bean
4284
public ServiceJourneyStopsCollector serviceJourneyStopsCollector(
4385
RedissonClient redissonClient,

src/main/java/no/entur/antu/netexdata/DefaultNetexDataRepository.java

+65-16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.Optional;
66
import java.util.Set;
77
import java.util.stream.Collectors;
8+
import java.util.stream.Stream;
89
import no.entur.antu.exception.AntuException;
910
import org.entur.netex.validation.validator.model.ActiveDates;
1011
import org.entur.netex.validation.validator.model.ActiveDatesId;
@@ -23,15 +24,24 @@ public class DefaultNetexDataRepository implements NetexDataRepositoryLoader {
2324

2425
private final Map<String, List<String>> lineInfoCache;
2526
private final Map<String, Map<String, List<String>>> serviceJourneyStopsCache;
27+
private final Map<String, Map<String, String>> serviceJourneyDayTypesCache;
28+
private final Map<String, Map<String, String>> activeDatesCache;
29+
private final Map<String, Map<String, String>> serviceJourneyOperatingDaysCache;
2630
private final Map<String, List<String>> serviceJourneyInterchangeInfoCache;
2731

2832
public DefaultNetexDataRepository(
2933
Map<String, List<String>> lineInfoCache,
3034
Map<String, Map<String, List<String>>> serviceJourneyStopsCache,
35+
Map<String, Map<String, String>> serviceJourneyDayTypesCache,
36+
Map<String, Map<String, String>> activeDatesCache,
37+
Map<String, Map<String, String>> serviceJourneyOperatingDaysCache,
3138
Map<String, List<String>> serviceJourneyInterchangeInfoCache
3239
) {
3340
this.lineInfoCache = lineInfoCache;
3441
this.serviceJourneyStopsCache = serviceJourneyStopsCache;
42+
this.serviceJourneyDayTypesCache = serviceJourneyDayTypesCache;
43+
this.activeDatesCache = activeDatesCache;
44+
this.serviceJourneyOperatingDaysCache = serviceJourneyOperatingDaysCache;
3545
this.serviceJourneyInterchangeInfoCache =
3646
serviceJourneyInterchangeInfoCache;
3747
}
@@ -67,40 +77,79 @@ public Map<ServiceJourneyId, List<ServiceJourneyStop>> serviceJourneyStops(
6777
);
6878
}
6979

70-
@Override
71-
public List<ServiceJourneyInterchangeInfo> serviceJourneyInterchangeInfos(
80+
public Map<ServiceJourneyId, List<DayTypeId>> serviceJourneyDayTypes(
7281
String validationReportId
7382
) {
74-
return Optional
75-
.ofNullable(serviceJourneyInterchangeInfoCache)
76-
.map(Map::entrySet)
83+
return serviceJourneyDayTypesCache
84+
.keySet()
7785
.stream()
78-
.flatMap(Set::stream)
79-
.filter(entry -> entry.getKey().startsWith(validationReportId))
80-
.flatMap(entry -> entry.getValue().stream())
81-
.map(ServiceJourneyInterchangeInfo::fromString)
82-
.toList();
86+
.filter(k -> k.startsWith(validationReportId))
87+
.map(serviceJourneyDayTypesCache::get)
88+
.flatMap(m -> m.entrySet().stream())
89+
.collect(
90+
Collectors.toMap(
91+
entry -> ServiceJourneyId.ofValidId(entry.getKey()),
92+
entry ->
93+
Stream.of(entry.getValue().split(",")).map(DayTypeId::new).toList(),
94+
(p, n) -> n
95+
)
96+
);
8397
}
8498

8599
@Override
86-
public Map<ServiceJourneyId, List<DayTypeId>> serviceJourneyDayTypes(
100+
public Map<ServiceJourneyId, List<OperatingDayId>> serviceJourneyOperatingDays(
87101
String validationReportId
88102
) {
89-
throw new UnsupportedOperationException();
103+
return serviceJourneyOperatingDaysCache
104+
.keySet()
105+
.stream()
106+
.filter(k -> k.startsWith(validationReportId))
107+
.map(serviceJourneyOperatingDaysCache::get)
108+
.flatMap(m -> m.entrySet().stream())
109+
.collect(
110+
Collectors.toMap(
111+
entry -> ServiceJourneyId.ofValidId(entry.getKey()),
112+
entry ->
113+
Stream
114+
.of(entry.getValue().split(","))
115+
.map(OperatingDayId::new)
116+
.toList(),
117+
(p, n) -> n
118+
)
119+
);
90120
}
91121

92-
@Override
93122
public Map<ActiveDatesId, ActiveDates> activeDates(
94123
String validationReportId
95124
) {
96-
throw new UnsupportedOperationException();
125+
return activeDatesCache
126+
.keySet()
127+
.stream()
128+
.filter(k -> k.startsWith(validationReportId))
129+
.map(activeDatesCache::get)
130+
.flatMap(m -> m.entrySet().stream())
131+
.collect(
132+
Collectors.toMap(
133+
entry -> ActiveDatesId.of(entry.getKey()),
134+
entry -> ActiveDates.fromString(entry.getValue()),
135+
(p, n) -> n
136+
)
137+
);
97138
}
98139

99140
@Override
100-
public Map<ServiceJourneyId, List<OperatingDayId>> serviceJourneyOperatingDays(
141+
public List<ServiceJourneyInterchangeInfo> serviceJourneyInterchangeInfos(
101142
String validationReportId
102143
) {
103-
throw new UnsupportedOperationException();
144+
return Optional
145+
.ofNullable(serviceJourneyInterchangeInfoCache)
146+
.map(Map::entrySet)
147+
.stream()
148+
.flatMap(Set::stream)
149+
.filter(entry -> entry.getKey().startsWith(validationReportId))
150+
.flatMap(entry -> entry.getValue().stream())
151+
.map(ServiceJourneyInterchangeInfo::fromString)
152+
.toList();
104153
}
105154

106155
@Override

0 commit comments

Comments
 (0)