Skip to content

Commit

Permalink
Fix issue where stop points are sometimes added twice to index
Browse files Browse the repository at this point in the history
This only happens when there are duplicate JourneyPattern in the netex
files.
  • Loading branch information
habrahamsson-skanetrafiken committed Dec 6, 2023
1 parent 15d0a81 commit a66b534
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
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
39 changes: 21 additions & 18 deletions src/main/java/org/opentripplanner/netex/mapping/TransferMapper.java
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

0 comments on commit a66b534

Please sign in to comment.