Skip to content

Commit

Permalink
Catch invalid mapping of scheduled stop point to quay
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Mar 5, 2025
1 parent a85a3e9 commit 1a88a20
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,20 @@ private void mapScheduledStopPointsToQuays() {
.localKeys()
.forEach(id -> {
var sspid = idFactory.createId(id);
var stopId = idFactory.createId(currentNetexIndex.getQuayIdByStopPointRef().lookup(id));
var stop = Objects.requireNonNull(transitBuilder.getStops().get(stopId));
transitBuilder.addStopByScheduledStopPoint(sspid, stop);
var quayId = idFactory.createId(currentNetexIndex.getQuayIdByStopPointRef().lookup(id));
if (quayId != null && transitBuilder.getStops().containsKey(quayId)) {
var stop = transitBuilder.getStops().get(quayId);
transitBuilder.addStopByScheduledStopPoint(sspid, stop);
} else {
// it's debatable if this is actually a problem with the data set. there are legitimate
// cases where SSPs are not mapped, for example pass-through stops.
issueStore.add(
"ScheduledStopPointAssignedToUnknownQuay",
"Scheduled stop point %s been mapped to unknow quay %s.",
sspid,
quayId
);
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ public void addScheduledStopPointMapping(Map<FeedScopedId, RegularStop> mapping)
/**
* Return the stop that is associated with the NeTEx concept of a scheduled stop point.
* <p>
* The scheduled stop point which is a "location-independent" stop that schedule systems provide
* The scheduled stop point is a "location-independent" stop that schedule systems provide
* which in turn can be later be resolved to an actual stop.
* <p>
* This way two schedule systems can use their own IDs for scheduled stop points but the stop (the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package org.opentripplanner.netex.mapping;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Set;
import org.junit.jupiter.api.Test;
import org.opentripplanner.graph_builder.issue.api.DataImportIssue;
import org.opentripplanner.graph_builder.issue.service.DefaultDataImportIssueStore;
import org.opentripplanner.model.impl.OtpTransitServiceBuilder;
import org.opentripplanner.netex.index.NetexEntityIndex;
import org.opentripplanner.transit.model.framework.Deduplicator;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.opentripplanner.transit.model.site.RegularStop;
import org.opentripplanner.transit.service.SiteRepository;
import org.rutebanken.netex.model.Quay;

class NetexMapperTest {

private static final String QUAY_ID = "quay-1";
private static final String SSP_ID = "ssp-1";
private static final String FEED_ID = "sta";
private static final RegularStop STOP = RegularStop.of(new FeedScopedId(FEED_ID, QUAY_ID), () -> 1
).build();
private static final Deduplicator DEDUPLICATOR = new Deduplicator();

@Test
void sspWithAssignment() {
var issueStore = new DefaultDataImportIssueStore();
var transitBuilder = new OtpTransitServiceBuilder(SiteRepository.of().build(), issueStore);
transitBuilder.siteRepository().withRegularStop(STOP);

var netexMapper = new NetexMapper(
transitBuilder,
FEED_ID,
DEDUPLICATOR,
issueStore,
Set.of(),
Set.of(),
10,
false
);

var index = new NetexEntityIndex();
index.quayById.add(new Quay().withId(QUAY_ID));
index.quayIdByStopPointRef.add(SSP_ID, QUAY_ID);
netexMapper.mapNetexToOtp(index.readOnlyView());

assertEquals(
STOP,
transitBuilder.stopsByScheduledStopPoints().get(new FeedScopedId(FEED_ID, SSP_ID))
);
}

@Test
void sspPointsToUnknownId() {
var issueStore = new DefaultDataImportIssueStore();

var netexMapper = new NetexMapper(
new OtpTransitServiceBuilder(SiteRepository.of().build(), issueStore),
FEED_ID,
DEDUPLICATOR,
issueStore,
Set.of(),
Set.of(),
10,
false
);

var index = new NetexEntityIndex();
index.quayById.add(new Quay().withId(QUAY_ID));
index.quayIdByStopPointRef.add(SSP_ID, QUAY_ID);
netexMapper.mapNetexToOtp(index.readOnlyView());

var issueTypes = issueStore.listIssues().stream().map(DataImportIssue::getType).toList();

assertThat(issueTypes).contains("ScheduledStopPointAssignedToUnknownQuay");
}
}

0 comments on commit 1a88a20

Please sign in to comment.