Skip to content

Commit

Permalink
Add validation of route to centroid StopPlace ids
Browse files Browse the repository at this point in the history
  • Loading branch information
habrahamsson-skanetrafiken committed Sep 16, 2024
1 parent 345b2a9 commit 7d77b4c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/org/opentripplanner/netex/NetexBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.opentripplanner.netex.loader.NetexXmlParser;
import org.opentripplanner.netex.loader.parser.NetexDocumentParser;
import org.opentripplanner.netex.mapping.NetexMapper;
import org.opentripplanner.netex.validation.RouteToCentroidStationIdValidator;
import org.opentripplanner.netex.validation.Validator;
import org.opentripplanner.transit.model.framework.Deduplicator;
import org.rutebanken.netex.model.PublicationDeliveryStructure;
Expand Down Expand Up @@ -104,6 +105,8 @@ public OtpTransitServiceBuilder loadBundle(
// Load data
loadFileEntries();

postValidation();

return transitBuilder;
}

Expand Down Expand Up @@ -191,4 +194,15 @@ private void loadSingeFileEntry(String fileDescription, DataSource entry) {
issueStore.stopProcessingSource();
}
}

/**
* Validate properties once all data is loaded
*/
private void postValidation() {
RouteToCentroidStationIdValidator.validate(
issueStore,
routeToCentroidStationIds,
index
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.opentripplanner.netex.validation;

import java.util.Set;
import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore;
import org.opentripplanner.netex.index.NetexEntityIndex;

public class RouteToCentroidStationIdValidator {
public static void validate(
DataImportIssueStore issueStore,
Set<String> routeToCentroidStationIds,
NetexEntityIndex index
) {
routeToCentroidStationIds
.stream()
.filter(id -> !index.stopPlaceById.containsKey(id))
.forEach(id ->
issueStore.add(
"UnknownStopPlaceId",
"routeToCentroidStationIds specified a stopPlace that does not exist: " + id
)
);
}
}

0 comments on commit 7d77b4c

Please sign in to comment.