Skip to content
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 @@ -196,7 +196,7 @@ class TripResultViewModel(
useRealtimeData = RealtimeData.EXPLANATORY,
walkSpeed = state.value.walkingSpeed,
transferLimit = if (state.value.isDirectConnection) 0 else null,
optimisationMethod = if (state.value.isFewerTransfers) OptimisationMethod.MIN_CHANGES.serializedName() else null,
optimisationMethod = if (state.value.isFewerTransfers) OptimisationMethod.MIN_CHANGES else null,
bikeTransport = state.value.isBikeTransport,
),
trip = trip,
Expand Down Expand Up @@ -272,7 +272,7 @@ class TripResultViewModel(
ModeAndModeOfOperationFilter(
exclude = false,
ptMode = emptyList(),
railSubmode = vehicleOption.vehicleType
railSubmode = RailSubmode.fromSerializedName(vehicleOption.vehicleType)
)
}
.toMutableList()
Expand Down Expand Up @@ -305,7 +305,7 @@ class TripResultViewModel(
useRealtimeData = RealtimeData.EXPLANATORY,
walkSpeed = state.value.walkingSpeed,
transferLimit = if (state.value.isDirectConnection) 0 else null,
optimisationMethod = if (state.value.isFewerTransfers) OptimisationMethod.MIN_CHANGES.serializedName() else null,
optimisationMethod = if (state.value.isFewerTransfers) OptimisationMethod.MIN_CHANGES else null,
bikeTransport = state.value.isBikeTransport,
),
individualTransportOption = IndividualTransportOptionDto(
Expand Down
14 changes: 14 additions & 0 deletions sdk/src/main/java/ch/opentransportdata/ojp/OjpSdk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class OjpSdk(
* @param time The time the trip should start/end
* @param isSearchForDepartureTime weather to search for trips that arrive at [time] or leave at [time]. Set to true if searching for trips that leave at [time].
* @param params The params to get further information on each trip
* @param individualTransportOption Optional individual transport option for the trip request
*
* @return [TripDeliveryDto] object with related trip information
*/
Expand Down Expand Up @@ -152,6 +153,19 @@ class OjpSdk(
return OjpKoinContext.koinApp.koin.get<RequestMockTrips>().invoke(stream)
}

/**
* Updates the trip data for a given trip by re-requesting it with the same parameters
*
* @param languageCode The [LanguageCode] for the desired results, default is [LanguageCode.DE]
* @param origin The origin where the trip starts
* @param destination The destination where the trip ends
* @param via The via station which the trip should cover
* @param params The params to get further information on each trip
* @param trip The existing [TripDto] that should be updated
* @param individualTransportOption Optional individual transport option for the trip request
*
* @return [TripDeliveryDto] with the updated trip information
*/
suspend fun updateTripData(
languageCode: LanguageCode = LanguageCode.DE,
origin: PlaceReferenceDto,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import nl.adaptivity.xmlutil.serialization.XmlSerialName
data class ItModeAndModeOfOperationDto(
@XmlElement(true)
@XmlSerialName("PersonalMode", OJP_NAME_SPACE, "")
val personalMode: String?,
val personalMode: String? = null,

@XmlElement(true)
@XmlSerialName("PersonalModeOfOperation", OJP_NAME_SPACE, "")
val personalModeOfOperation: String?,
val personalModeOfOperation: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ internal data class PlaceContextDto(

@XmlElement(true)
@XmlSerialName("IndividualTransportOption", OJP_NAME_SPACE, "")
val individualTransportOption: IndividualTransportOptionDto?,
val individualTransportOption: IndividualTransportOptionDto? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ internal data class TripParamsDto(

@XmlElement(true)
@XmlSerialName("WalkSpeed", OJP_NAME_SPACE, "")
val walkSpeed: Int?,
val walkSpeed: Int? = null,

@XmlElement(true)
@XmlSerialName("TransferLimit", OJP_NAME_SPACE, "")
val transferLimit: Int?,
val transferLimit: Int? = null,

@XmlElement(true)
@XmlSerialName("OptimisationMethod", OJP_NAME_SPACE, "")
val optimisationMethod: String?,
val optimisationMethod: String? = null,

@XmlElement(true)
@XmlSerialName("BikeTransport", OJP_NAME_SPACE, "")
val bikeTransport: Boolean?,
val bikeTransport: Boolean? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import ch.opentransportdata.ojp.data.remote.OjpService
import ch.opentransportdata.ojp.domain.model.LanguageCode
import ch.opentransportdata.ojp.domain.model.TripParams
import ch.opentransportdata.ojp.domain.model.TripRefineParam
import ch.opentransportdata.ojp.domain.model.serializedName
import ch.opentransportdata.ojp.domain.model.shortName
import ch.opentransportdata.ojp.domain.usecase.Initializer
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -134,13 +135,13 @@ internal class RemoteTripDataSourceImpl(
ModeAndModeOfOperationFilterDto(
ptMode = filter.ptMode,
exclude = filter.exclude,
railSubmode = filter.railSubmode,
railSubmode = filter.railSubmode?.serializedName(),
busSubmode = filter.busSubmode,
coachSubmode = filter.coachSubmode,
metroSubmode = filter.metroSubmode,
tramSubmode = filter.tramSubmode,
trolleyBusSubmode = filter.trolleyBusSubmode,
telecabinSubmode = filter.trolleyBusSubmode,
telecabinSubmode = filter.telecabinSubmode,
funicularSubmode = filter.funicularSubmode,
waterSubmode = filter.waterSubmode,
airSubmode = filter.airSubmode,
Expand All @@ -150,7 +151,7 @@ internal class RemoteTripDataSourceImpl(
},
walkSpeed = this.walkSpeed,
transferLimit = this.transferLimit,
optimisationMethod = this.optimisationMethod,
optimisationMethod = this.optimisationMethod?.serializedName(),
bikeTransport = this.bikeTransport,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlinx.parcelize.Parcelize
data class ModeAndModeOfOperationFilter(
val ptMode: List<PtMode>,
val exclude: Boolean,
val railSubmode: String? = null,
val railSubmode: RailSubmode? = null,
val busSubmode: String? = null,
val coachSubmode: String? = null,
val metroSubmode: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import kotlinx.serialization.Serializable
* Created by Nico Brandenberger on 19.02.2026
*/
@Serializable
enum class OptimisationMethod() {
enum class OptimisationMethod {
@SerialName("minChanges")
MIN_CHANGES
}

fun OptimisationMethod.serializedName(): String =
this::class.java.getField(this.name)
.getAnnotation(SerialName::class.java)
?.value
?: this.name
fun OptimisationMethod.serializedName(): String = when (this) {
OptimisationMethod.MIN_CHANGES -> "minChanges"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import kotlinx.serialization.Serializable
* Created by Nico Brandenberger on 19.02.2026
*/
@Serializable
enum class RailSubmode() {
enum class RailSubmode {
@SerialName("international") //Trains ICE, TGV, EC, RJX, NJ, EN
INTERNATIONAL,
@SerialName("highSpeedRail") //Trains IC
Expand All @@ -17,11 +17,18 @@ enum class RailSubmode() {
@SerialName("railShuttle") // Trains ATZ, PE
RAIL_SHUTTLE,
@SerialName("local") //Trains S, SN, RB, RE,
LOCAL,
LOCAL;

companion object {
fun fromSerializedName(name: String): RailSubmode? =
entries.firstOrNull { it.serializedName() == name }
}
}

fun RailSubmode.serializedName(): String =
this::class.java.getField(this.name)
.getAnnotation(SerialName::class.java)
?.value
?: this.name
fun RailSubmode.serializedName(): String = when (this) {
RailSubmode.INTERNATIONAL -> "international"
RailSubmode.HIGH_SPEED_RAIL -> "highSpeedRail"
RailSubmode.INTERREGIONAL_RAIL -> "interregionalRail"
RailSubmode.RAIL_SHUTTLE -> "railShuttle"
RailSubmode.LOCAL -> "local"
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ data class TripParams(
val includeIntermediateStops: Boolean = false,
val includeAllRestrictedLines: Boolean = false,
val useRealtimeData: RealtimeData? = null,
val modeAndModeOfOperationFilter: List<ModeAndModeOfOperationFilter>?,
val walkSpeed: Int?,
val transferLimit: Int?,
val optimisationMethod: String?,
val bikeTransport: Boolean?,
val modeAndModeOfOperationFilter: List<ModeAndModeOfOperationFilter>? = null,
val walkSpeed: Int? = null,
val transferLimit: Int? = null,
val optimisationMethod: OptimisationMethod? = null,
val bikeTransport: Boolean? = null,
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ internal class RequestTrips(
time = time,
isSearchForDepartureTime = isSearchForDepartureTime,
params = params,
individualTransportOption = individualTransportOption,
)

return when (val response =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import ch.opentransportdata.ojp.domain.model.RealtimeData
import ch.opentransportdata.ojp.domain.model.Result
import ch.opentransportdata.ojp.domain.model.TripParams
import ch.opentransportdata.ojp.domain.model.TripRefineParam
import ch.opentransportdata.ojp.domain.model.serializedName

import kotlinx.coroutines.test.runTest
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
Expand Down Expand Up @@ -141,7 +141,7 @@ class TripRefinementXmlUtilTest {
useRealtimeData = RealtimeData.FULL,
walkSpeed = 100,
transferLimit = 0,
optimisationMethod = OptimisationMethod.MIN_CHANGES.serializedName(),
optimisationMethod = OptimisationMethod.MIN_CHANGES,
bikeTransport = false
)

Expand Down
Loading