Skip to content

Commit 13f89c6

Browse files
authored
Merge pull request #6640 from entur/ferry_suport
Enable CAR transfers with ferries with NeTEx import
2 parents 89c03fe + 5aa88e7 commit 13f89c6

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

application/src/main/java/org/opentripplanner/netex/mapping/TransportModeMapper.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
package org.opentripplanner.netex.mapping;
22

3+
import static org.rutebanken.netex.model.WaterSubmodeEnumeration.HIGH_SPEED_VEHICLE_SERVICE;
4+
import static org.rutebanken.netex.model.WaterSubmodeEnumeration.LOCAL_CAR_FERRY;
5+
import static org.rutebanken.netex.model.WaterSubmodeEnumeration.NATIONAL_CAR_FERRY;
6+
import static org.rutebanken.netex.model.WaterSubmodeEnumeration.REGIONAL_CAR_FERRY;
7+
8+
import java.util.Set;
9+
import javax.annotation.Nullable;
310
import org.opentripplanner.netex.mapping.support.NetexMainAndSubMode;
11+
import org.opentripplanner.transit.model.basic.SubMode;
412
import org.opentripplanner.transit.model.basic.TransitMode;
13+
import org.opentripplanner.transit.model.network.CarAccess;
514
import org.rutebanken.netex.model.AllVehicleModesOfTransportEnumeration;
615
import org.rutebanken.netex.model.TransportSubmodeStructure;
716

@@ -13,6 +22,13 @@
1322
*/
1423
class TransportModeMapper {
1524

25+
private static final Set<String> CARS_ALLOWED_WATER_SUBMODES = Set.of(
26+
NATIONAL_CAR_FERRY.value(),
27+
REGIONAL_CAR_FERRY.value(),
28+
LOCAL_CAR_FERRY.value(),
29+
HIGH_SPEED_VEHICLE_SERVICE.value()
30+
);
31+
1632
public NetexMainAndSubMode map(
1733
AllVehicleModesOfTransportEnumeration netexMode,
1834
TransportSubmodeStructure submode
@@ -44,6 +60,26 @@ public TransitMode mapAllVehicleModesOfTransport(AllVehicleModesOfTransportEnume
4460
};
4561
}
4662

63+
/**
64+
* Use submode to determine if a trip/ServiceJourney is allowed for car or not. There are
65+
* probably other ways to specify this in NeTEx. The list of included submodes
66+
* {@link #CARS_ALLOWED_WATER_SUBMODES} are not complete, feel free to request
67+
* changes.
68+
*/
69+
public CarAccess mapCarsAllowed(@Nullable TransportSubmodeStructure submode) {
70+
if (submode == null || submode.getWaterSubmode() == null) {
71+
return CarAccess.NOT_ALLOWED;
72+
}
73+
return mapCarsAllowed(submode.getWaterSubmode().value());
74+
}
75+
76+
/**
77+
* @see #carsAllowed(TransportSubmodeStructure)
78+
*/
79+
public CarAccess mapCarsAllowed(@Nullable SubMode otpSubmode) {
80+
return mapCarsAllowed(otpSubmode == null ? null : otpSubmode.name());
81+
}
82+
4783
private NetexMainAndSubMode getSubmodeAsString(TransportSubmodeStructure submode) {
4884
if (submode.getAirSubmode() != null) {
4985
return new NetexMainAndSubMode(TransitMode.AIRPLANE, submode.getAirSubmode().value());
@@ -77,4 +113,10 @@ public UnsupportedModeException(AllVehicleModesOfTransportEnumeration mode) {
77113
this.mode = mode;
78114
}
79115
}
116+
117+
private CarAccess mapCarsAllowed(@Nullable String submode) {
118+
return submode != null && CARS_ALLOWED_WATER_SUBMODES.contains(submode)
119+
? CarAccess.ALLOWED
120+
: CarAccess.NOT_ALLOWED;
121+
}
80122
}

application/src/main/java/org/opentripplanner/netex/mapping/TripMapper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.opentripplanner.transit.model.framework.DefaultEntityById;
1515
import org.opentripplanner.transit.model.framework.EntityById;
1616
import org.opentripplanner.transit.model.framework.FeedScopedId;
17+
import org.opentripplanner.transit.model.network.CarAccess;
1718
import org.opentripplanner.transit.model.organization.Operator;
1819
import org.opentripplanner.transit.model.timetable.Trip;
1920
import org.rutebanken.netex.model.DirectionTypeEnumeration;
@@ -130,6 +131,11 @@ Trip mapServiceJourney(ServiceJourney serviceJourney, Supplier<String> headsign)
130131
}
131132
builder.withMode(transitMode.mainMode());
132133
builder.withNetexSubmode(transitMode.subMode());
134+
builder.withCarsAllowed(
135+
transportModeMapper.mapCarsAllowed(serviceJourney.getTransportSubmode())
136+
);
137+
} else {
138+
builder.withCarsAllowed(transportModeMapper.mapCarsAllowed(route.getNetexSubmode()));
133139
}
134140

135141
builder.withDirection(DirectionMapper.map(resolveDirectionType(serviceJourney)));

application/src/test/java/org/opentripplanner/netex/mapping/TransportModeMapperTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
import static org.junit.jupiter.api.Assertions.assertNull;
66
import static org.junit.jupiter.api.Assertions.assertThrows;
77
import static org.junit.jupiter.api.Assertions.fail;
8+
import static org.opentripplanner.transit.model.network.CarAccess.ALLOWED;
9+
import static org.opentripplanner.transit.model.network.CarAccess.NOT_ALLOWED;
10+
import static org.rutebanken.netex.model.WaterSubmodeEnumeration.HIGH_SPEED_VEHICLE_SERVICE;
11+
import static org.rutebanken.netex.model.WaterSubmodeEnumeration.LOCAL_CAR_FERRY;
12+
import static org.rutebanken.netex.model.WaterSubmodeEnumeration.NATIONAL_CAR_FERRY;
13+
import static org.rutebanken.netex.model.WaterSubmodeEnumeration.POST_BOAT;
14+
import static org.rutebanken.netex.model.WaterSubmodeEnumeration.REGIONAL_CAR_FERRY;
815

916
import java.util.EnumSet;
1017
import java.util.List;
@@ -14,6 +21,7 @@
1421
import org.junit.jupiter.params.provider.Arguments;
1522
import org.junit.jupiter.params.provider.MethodSource;
1623
import org.opentripplanner.netex.mapping.TransportModeMapper.UnsupportedModeException;
24+
import org.opentripplanner.transit.model.basic.SubMode;
1725
import org.opentripplanner.transit.model.basic.TransitMode;
1826
import org.rutebanken.netex.model.AirSubmodeEnumeration;
1927
import org.rutebanken.netex.model.AllVehicleModesOfTransportEnumeration;
@@ -126,10 +134,38 @@ void unsupportedMode() {
126134
assertThrows(UnsupportedModeException.class, () -> transportModeMapper.map(null, null));
127135
}
128136

137+
@Test
138+
void carsAllowedBasedOnSubMode() {
139+
assertEquals(ALLOWED, transportModeMapper.mapCarsAllowed(SubMode.of("nationalCarFerry")));
140+
assertEquals(ALLOWED, transportModeMapper.mapCarsAllowed(SubMode.of("regionalCarFerry")));
141+
assertEquals(ALLOWED, transportModeMapper.mapCarsAllowed(SubMode.of("localCarFerry")));
142+
assertEquals(
143+
ALLOWED,
144+
transportModeMapper.mapCarsAllowed(SubMode.of("highSpeedVehicleService"))
145+
);
146+
assertEquals(NOT_ALLOWED, transportModeMapper.mapCarsAllowed(SubMode.UNKNOWN));
147+
assertEquals(NOT_ALLOWED, transportModeMapper.mapCarsAllowed((SubMode) null));
148+
}
149+
150+
@Test
151+
void carsAllowedBasedOn() {
152+
assertEquals(ALLOWED, transportModeMapper.mapCarsAllowed(tsm(NATIONAL_CAR_FERRY)));
153+
assertEquals(ALLOWED, transportModeMapper.mapCarsAllowed(tsm(REGIONAL_CAR_FERRY)));
154+
assertEquals(ALLOWED, transportModeMapper.mapCarsAllowed(tsm(LOCAL_CAR_FERRY)));
155+
assertEquals(ALLOWED, transportModeMapper.mapCarsAllowed(tsm(HIGH_SPEED_VEHICLE_SERVICE)));
156+
assertEquals(NOT_ALLOWED, transportModeMapper.mapCarsAllowed(tsm(POST_BOAT)));
157+
assertEquals(NOT_ALLOWED, transportModeMapper.mapCarsAllowed(tsm(null)));
158+
assertEquals(NOT_ALLOWED, transportModeMapper.mapCarsAllowed((TransportSubmodeStructure) null));
159+
}
160+
129161
private static List<Arguments> createSubModeTestCases() {
130162
return VALID_SUBMODE_STRUCTURES.entrySet()
131163
.stream()
132164
.map(entry -> Arguments.of(entry.getKey(), entry.getValue()))
133165
.toList();
134166
}
167+
168+
private static TransportSubmodeStructure tsm(WaterSubmodeEnumeration waterSubMode) {
169+
return new TransportSubmodeStructure().withWaterSubmode(waterSubMode);
170+
}
135171
}

0 commit comments

Comments
 (0)