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

Enforce non-null coordinates on multimodal station #5971

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
@@ -1,6 +1,7 @@
package org.opentripplanner.netex.mapping;

import java.util.Collection;
import javax.annotation.Nullable;
import org.opentripplanner.framework.geometry.WgsCoordinate;
import org.opentripplanner.framework.i18n.NonLocalizedString;
import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore;
Expand All @@ -21,6 +22,7 @@ public MultiModalStationMapper(DataImportIssueStore issueStore, FeedScopedIdFact
this.idFactory = idFactory;
}

@Nullable
MultiModalStation map(StopPlace stopPlace, Collection<Station> childStations) {
MultiModalStationBuilder multiModalStation = MultiModalStation
.of(idFactory.createId(stopPlace.getId()))
Expand All @@ -34,13 +36,13 @@ MultiModalStation map(StopPlace stopPlace, Collection<Station> childStations) {
if (coordinate == null) {
issueStore.add(
"MultiModalStationWithoutCoordinates",
"MultiModal station {} does not contain any coordinates.",
"MultiModal station %s does not contain any coordinates.",
multiModalStation.getId()
);
return null;
} else {
multiModalStation.withCoordinate(coordinate);
return multiModalStation.build();
}

return multiModalStation.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,9 @@ private void mapMultiModalStopPlaces() {
.getStationsByMultiModalStationRfs()
.get(multiModalStopPlace.getId());
var multiModalStation = mapper.map(multiModalStopPlace, stations);

transitBuilder.stopModel().withMultiModalStation(multiModalStation);
if (multiModalStation != null) {
transitBuilder.stopModel().withMultiModalStation(multiModalStation);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public class MultiModalStation
super(builder.getId());
// Required fields
this.childStations = Objects.requireNonNull(builder.childStations());
this.coordinate = Objects.requireNonNull(builder.coordinate());
this.name = I18NString.assertHasValue(builder.name());

// Optional fields
// TODO Make required
this.coordinate = builder.coordinate();
this.code = builder.code();
this.description = builder.description();
this.url = builder.url();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.opentripplanner.netex.mapping;

import static org.junit.jupiter.api.Assertions.*;

import java.util.List;
import org.junit.jupiter.api.Test;
import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore;
import org.opentripplanner.graph_builder.issue.service.DefaultDataImportIssueStore;
import org.opentripplanner.netex.NetexTestDataSupport;
import org.opentripplanner.netex.mapping.support.FeedScopedIdFactory;
import org.opentripplanner.transit.model._data.TransitModelForTest;
import org.rutebanken.netex.model.StopPlace;

class MultiModalStationMapperTest {

@Test
void testMissingCoordinates() {
DataImportIssueStore dataIssueStore = new DefaultDataImportIssueStore();
FeedScopedIdFactory feedScopeIdFactory = new FeedScopedIdFactory(TransitModelForTest.FEED_ID);
MultiModalStationMapper multiModalStationMapper = new MultiModalStationMapper(
dataIssueStore,
feedScopeIdFactory
);
StopPlace stopPlace = new StopPlace();
stopPlace.setId(NetexTestDataSupport.STOP_PLACE_ID);
assertNull(multiModalStationMapper.map(stopPlace, List.of()));
assertEquals(1, dataIssueStore.listIssues().size());
assertEquals(
"MultiModalStationWithoutCoordinates",
dataIssueStore.listIssues().getFirst().getType()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.util.Set;
import org.junit.jupiter.api.Test;
import org.opentripplanner.framework.geometry.WgsCoordinate;
import org.opentripplanner.framework.i18n.I18NString;
import org.opentripplanner.framework.i18n.NonLocalizedString;
import org.opentripplanner.transit.model._data.TransitModelForTest;
Expand All @@ -26,6 +27,7 @@ class MultiModalStationTest {
.of(TransitModelForTest.id(ID))
.withName(NAME)
.withChildStations(CHILD_STATIONS)
.withCoordinate(new WgsCoordinate(1, 1))
.build();

@Test
Expand Down
Loading