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

Fix issue where stop points are sometimes added twice to index #5552

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.google.common.collect.ArrayListMultimap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore;
import org.opentripplanner.model.impl.OtpTransitServiceBuilder;
import org.opentripplanner.model.transfer.ConstrainedTransfer;
Expand All @@ -25,7 +27,7 @@ class GroupNetexMapper {
/**
* A map from trip/serviceJourney id to an ordered list of scheduled stop point ids.
*/
final ArrayListMultimap<String, String> scheduledStopPointsIndex = ArrayListMultimap.create();
final Map<String, List<String>> scheduledStopPointsIndex = new HashMap<>();

GroupNetexMapper(
FeedScopedIdFactory idFactory,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.opentripplanner.netex.mapping;

import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import jakarta.xml.bind.JAXBElement;
import java.time.LocalDateTime;
import java.time.ZoneId;
Expand Down Expand Up @@ -469,7 +470,7 @@ private void mapTripPatterns(Map<String, FeedScopedId> serviceIds) {
transitBuilder.getTripPatterns().put(it.getKey(), it.getValue());
}
currentMapperIndexes.addStopTimesByNetexId(result.stopTimeByNetexId);
groupMapper.scheduledStopPointsIndex.putAll(result.scheduledStopPointsIndex);
groupMapper.scheduledStopPointsIndex.putAll(Multimaps.asMap(result.scheduledStopPointsIndex));
transitBuilder.getTripOnServiceDates().addAll(result.tripOnServiceDates);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.opentripplanner.netex.mapping;

import com.google.common.collect.ArrayListMultimap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore;
import org.opentripplanner.model.transfer.ConstrainedTransfer;
Expand All @@ -23,13 +24,13 @@ public class TransferMapper {

private final FeedScopedIdFactory idFactory;
private final DataImportIssueStore issueStore;
private final ArrayListMultimap<String, String> scheduledStopPointsIndex;
private final Map<String, List<String>> scheduledStopPointsIndex;
private final EntityById<Trip> trips;

public TransferMapper(
FeedScopedIdFactory idFactory,
DataImportIssueStore issueStore,
ArrayListMultimap<String, String> scheduledStopPointsIndex,
Map<String, List<String>> scheduledStopPointsIndex,
EntityById<Trip> trips
) {
this.idFactory = idFactory;
Expand Down Expand Up @@ -139,32 +140,34 @@ private int findStopPosition(
ScheduledStopPointRefStructure scheduledStopPointRef
) {
String sspId = scheduledStopPointRef.getRef();
var scheduledStopPoints = scheduledStopPointsIndex.get(sjId);
String errorMessage;

if (scheduledStopPoints != null) {
var index =
switch (label) {
case Label.TO -> scheduledStopPoints.indexOf(sspId);
case Label.FROM -> scheduledStopPoints.lastIndexOf(sspId);
};
if (index >= 0) {
return index;
}

int index = -1;
if (label == Label.TO) {
index = scheduledStopPointsIndex.get(sjId).indexOf(sspId);
} else if (label == Label.FROM) {
index = scheduledStopPointsIndex.get(sjId).lastIndexOf(sspId);
}

if (index >= 0) {
return index;
errorMessage = "Scheduled-stop-point-ref not found";
} else {
errorMessage = "Service-journey not found";
}

String detailedMsg = scheduledStopPointsIndex.containsKey(sjId)
? "Scheduled-stop-point-ref not found"
: "Service-journey not found";

issueStore.add(
new InterchangePointMappingFailed(
detailedMsg,
errorMessage,
interchangeId,
label.label(fieldName),
sjId,
sspId
)
);
return index;
return -1;
}

private FeedScopedId createId(String id) {
Expand Down
Loading