forked from opentripplanner/OpenTripPlanner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidator.java
More file actions
53 lines (45 loc) · 2 KB
/
Validator.java
File metadata and controls
53 lines (45 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package org.opentripplanner.netex.validation;
import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore;
import org.opentripplanner.netex.index.NetexEntityIndex;
import org.opentripplanner.netex.index.hierarchy.AbstractHierarchicalMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Validate input NeTEx entities, especially relations. The validation step is mainly there to
* enable us to remove entities with “broken” references. This happens in real life, when the import
* comes from more than one source (stops register & authority transit data) and these sources are
* out of sync.
* <p>
* Make sure the order of the validation steps are inline with the data relations. For example, if A
* reference B, any validation of the reference should be done AFTER validation steps on B. If B is
* removed, then validating A -> B, should also remove A.
*/
public class Validator {
private static final Logger LOG = LoggerFactory.getLogger(Validator.class);
private final NetexEntityIndex index;
private final DataImportIssueStore issueStore;
private Validator(NetexEntityIndex index, DataImportIssueStore issueStore) {
this.index = index;
this.issueStore = issueStore;
}
public static void validate(NetexEntityIndex index, DataImportIssueStore issueStore) {
new Validator(index, issueStore).run();
}
private void run() {
validate(index.quayIdByStopPointRef, new PassengerStopAssignmentQuayNotFound());
validate(index.serviceJourneyById, new JourneyPatternNotFoundInSJ());
validate(index.serviceJourneyById, new JourneyPatternSJMismatch());
validate(index.datedServiceJourneys, new DSJOperatingDayNotFound());
validate(index.datedServiceJourneys, new DSJServiceJourneyNotFound());
}
/**
* Validate a set of entities for a given rule.
*/
private <K, V> void validate(
AbstractHierarchicalMap<K, V> map,
AbstractHMapValidationRule<K, V> rule
) {
rule.setup(index.readOnlyView());
map.validate(rule, issueStore::add);
}
}