Skip to content

Commit bf287bd

Browse files
committed
Merge remote branch “origin/feature-ors”
2 parents aff7527 + df4d38b commit bf287bd

31 files changed

+244
-74
lines changed

ors-client/src/main/java/org/nitri/ors/DefaultOrsClient.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,109 +25,129 @@ import org.nitri.ors.domain.snap.SnapRequest
2525
import org.nitri.ors.domain.snap.SnapResponse
2626
import org.nitri.ors.restclient.OpenRouteServiceRestClient
2727

28+
/**
29+
* Default implementation of [OrsClient] using the Retrofit based
30+
* [OpenRouteServiceRestClient].
31+
*/
2832
class DefaultOrsClient(apiKey: String, context: Context) : OrsClient {
2933
private val api = OpenRouteServiceRestClient.create(apiKey, context)
3034

35+
/** @inheritDoc */
3136
override suspend fun getRoute(
3237
profile: Profile,
3338
routeRequest: RouteRequest
3439
): RouteResponse {
3540
return api.getRoute(profile.key, routeRequest)
3641
}
3742

43+
/** @inheritDoc */
3844
override suspend fun getRouteGpx(
3945
profile: Profile,
4046
routeRequest: RouteRequest
4147
): String {
4248
return api.getRouteGpx(profile.key, routeRequest).body()?.string() ?: ""
4349
}
4450

51+
/** @inheritDoc */
4552
override suspend fun getRouteGeoJson(
4653
profile: Profile,
4754
routeRequest: RouteRequest
4855
): GeoJsonRouteResponse {
4956
return api.getRouteGeoJson(profile.key, routeRequest)
5057
}
5158

59+
/** @inheritDoc */
5260
override suspend fun export(
5361
profile: Profile,
5462
exportRequest: ExportRequest
5563
): ExportResponse {
5664
return api.export(profile.key, exportRequest)
5765
}
5866

67+
/** @inheritDoc */
5968
override suspend fun exportJson(
6069
profile: Profile,
6170
exportRequest: ExportRequest
6271
): ExportResponse {
6372
return api.exportJson(profile.key, exportRequest)
6473
}
6574

75+
/** @inheritDoc */
6676
override suspend fun exportTopoJson(
6777
profile: Profile,
6878
exportRequest: ExportRequest
6979
): TopoJsonExportResponse {
7080
return api.exportTopoJson(profile.key, exportRequest)
7181
}
7282

83+
/** @inheritDoc */
7384
override suspend fun getIsochrones(
7485
profile: Profile,
7586
isochronesRequest: IsochronesRequest
7687
): IsochronesResponse {
7788
return api.getIsochrones(profile.key, isochronesRequest)
7889
}
7990

91+
/** @inheritDoc */
8092
override suspend fun getMatrix(
8193
profile: Profile,
8294
matrixRequest: MatrixRequest
8395
): MatrixResponse {
8496
return api.getMatrix(profile.key, matrixRequest)
8597
}
8698

99+
/** @inheritDoc */
87100
override suspend fun getSnap(
88101
profile: Profile,
89102
snapRequest: SnapRequest
90103
): SnapResponse {
91104
return api.getSnap(profile.key, snapRequest)
92105
}
93106

107+
/** @inheritDoc */
94108
override suspend fun getSnapJson(
95109
profile: Profile,
96110
snapRequest: SnapRequest
97111
): SnapResponse {
98112
return api.getSnapJson(profile.key, snapRequest)
99113
}
100114

115+
/** @inheritDoc */
101116
override suspend fun getSnapGeoJson(
102117
profile: Profile,
103118
snapRequest: SnapRequest
104119
): SnapGeoJsonResponse {
105120
return api.getSnapGeoJson(profile.key, snapRequest)
106121
}
107122

123+
/** @inheritDoc */
108124
override suspend fun getPois(poisRequest: PoisRequest): PoisGeoJsonResponse {
109125
val raw = api.getPois(poisRequest)
110126
fun PoisGeoJsonResponse.sanitized(): PoisGeoJsonResponse =
111127
copy(bbox = bbox?.takeIf { it.size == 4 && it.all(Double::isFinite) })
112128
return raw.sanitized()
113129
}
114130

131+
/** @inheritDoc */
115132
override suspend fun getOptimization(optimizationRequest: OptimizationRequest): OptimizationResponse {
116133
return api.getOptimization(optimizationRequest)
117134
}
118135

136+
/** @inheritDoc */
119137
override suspend fun getElevationLine(
120138
elevationLineRequest: ElevationLineRequest
121139
): ElevationLineResponse {
122140
return api.getElevationLine(elevationLineRequest)
123141
}
124142

143+
/** @inheritDoc */
125144
override suspend fun getElevationPoint(
126145
elevationPointRequest: ElevationPointRequest
127146
): ElevationPointResponse {
128147
return api.getElevationPoint(elevationPointRequest)
129148
}
130149

150+
/** @inheritDoc */
131151
override suspend fun geocodeSearch(
132152
text: String,
133153
apiKey: String,
@@ -166,6 +186,7 @@ class DefaultOrsClient(apiKey: String, context: Context) : OrsClient {
166186
)
167187
}
168188

189+
/** @inheritDoc */
169190
override suspend fun geocodeAutocomplete(
170191
apiKey: String,
171192
text: String,
@@ -202,6 +223,7 @@ class DefaultOrsClient(apiKey: String, context: Context) : OrsClient {
202223
)
203224
}
204225

226+
/** @inheritDoc */
205227
override suspend fun geocodeStructured(
206228
apiKey: String,
207229
address: String?,
@@ -252,6 +274,7 @@ class DefaultOrsClient(apiKey: String, context: Context) : OrsClient {
252274
)
253275
}
254276

277+
/** @inheritDoc */
255278
override suspend fun geocodeReverse(
256279
apiKey: String,
257280
lon: Double,

ors-client/src/main/java/org/nitri/ors/Ors.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@ package org.nitri.ors
22

33
import android.content.Context
44

5+
/**
6+
* Factory for obtaining [OrsClient] instances.
7+
*/
58
object Ors {
6-
/** If you already construct the Retrofit API elsewhere, inject it here. */
9+
/**
10+
* Creates a default [OrsClient] backed by Retrofit.
11+
*
12+
* @param apiKey API key obtained from openrouteservice.org
13+
* @param context Android context used for HTTP client construction
14+
*/
715
@JvmStatic
816
fun create(apiKey: String, context: Context): OrsClient = DefaultOrsClient(apiKey, context)
917
}

ors-client/src/main/java/org/nitri/ors/OrsClient.kt

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ import org.nitri.ors.domain.snap.SnapGeoJsonResponse
2323
import org.nitri.ors.domain.snap.SnapRequest
2424
import org.nitri.ors.domain.snap.SnapResponse
2525

26+
/**
27+
* Supported routing profiles used across the OpenRouteService endpoints.
28+
*
29+
* The [key] corresponds to the profile identifier expected by the HTTP API.
30+
*/
2631
enum class Profile(val key: String) {
2732
DRIVING_CAR("driving-car"),
2833
DRIVING_HGV("driving-hgv"),
@@ -35,44 +40,84 @@ enum class Profile(val key: String) {
3540
WHEELCHAIR("wheelchair")
3641
}
3742

38-
@JvmInline value class Lon(val v: Double)
39-
@JvmInline value class Lat(val v: Double)
43+
/** Longitude value wrapper used by the DSL builders. */
44+
@JvmInline
45+
value class Lon(val v: Double)
46+
47+
/** Latitude value wrapper used by the DSL builders. */
48+
@JvmInline
49+
value class Lat(val v: Double)
50+
51+
/** Convenience pair for longitude/latitude coordinates. */
4052
data class LonLat(val lon: Double, val lat: Double)
4153

54+
/**
55+
* Abstraction over the OpenRouteService HTTP API.
56+
*
57+
* Implementations map these suspending functions to the respective REST
58+
* endpoints as documented in the
59+
* [OpenRouteService API reference](https://openrouteservice.org/dev/#/api-docs).
60+
*/
4261
interface OrsClient {
4362

4463
// Directions
64+
/**
65+
* Requests a route using the Directions endpoint.
66+
* `GET /v2/directions/{profile}`
67+
*/
4568
suspend fun getRoute(profile: Profile, routeRequest: RouteRequest): RouteResponse
69+
70+
/** Retrieves the route as GPX. */
4671
suspend fun getRouteGpx(profile: Profile, routeRequest: RouteRequest): String
72+
73+
/** Retrieves the route as GeoJSON feature collection. */
4774
suspend fun getRouteGeoJson(profile: Profile, routeRequest: RouteRequest): GeoJsonRouteResponse
4875

4976
// Export
77+
/** Calls the export endpoint returning plain JSON. */
5078
suspend fun export(profile: Profile, exportRequest: ExportRequest): ExportResponse
79+
80+
/** Same as [export] but explicitly requesting JSON output. */
5181
suspend fun exportJson(profile: Profile, exportRequest: ExportRequest): ExportResponse
82+
83+
/** Requests TopoJSON output from the export endpoint. */
5284
suspend fun exportTopoJson(profile: Profile, exportRequest: ExportRequest): TopoJsonExportResponse
5385

5486
// Isochrones
87+
/** Accesses the isochrones endpoint. */
5588
suspend fun getIsochrones(profile: Profile, isochronesRequest: IsochronesRequest): IsochronesResponse
5689

5790
// Matrix
91+
/** Calls the matrix endpoint and returns distance/duration matrices. */
5892
suspend fun getMatrix(profile: Profile, matrixRequest: MatrixRequest): MatrixResponse
5993

6094
// Snapping
95+
/** Snaps coordinates to the road network. */
6196
suspend fun getSnap(profile: Profile, snapRequest: SnapRequest): SnapResponse
97+
98+
/** Snaps coordinates and returns the JSON variant of the response. */
6299
suspend fun getSnapJson(profile: Profile, snapRequest: SnapRequest): SnapResponse
100+
101+
/** Snaps coordinates and returns a GeoJSON response. */
63102
suspend fun getSnapGeoJson(profile: Profile, snapRequest: SnapRequest): SnapGeoJsonResponse
64103

65104
// POIs
105+
/** Queries points of interest and returns a GeoJSON feature collection. */
66106
suspend fun getPois(poisRequest: PoisRequest): PoisGeoJsonResponse
67107

68108
// Optimization
109+
/** Delegates to the VROOM based optimization service. */
69110
suspend fun getOptimization(optimizationRequest: OptimizationRequest): OptimizationResponse
70111

71112
// Elevation
113+
/** Calls the elevation/line endpoint. */
72114
suspend fun getElevationLine(elevationLineRequest: ElevationLineRequest): ElevationLineResponse
115+
116+
/** Calls the elevation/point endpoint. */
73117
suspend fun getElevationPoint(elevationPointRequest: ElevationPointRequest): ElevationPointResponse
74118

75119
// Geocode
120+
/** Forward geocoding search endpoint. */
76121
suspend fun geocodeSearch(
77122
text: String,
78123
apiKey: String,
@@ -92,6 +137,7 @@ interface OrsClient {
92137
size: Int? = 10,
93138
): GeocodeSearchResponse
94139

140+
/** Autocomplete endpoint returning suggestions for a partial query. */
95141
suspend fun geocodeAutocomplete(
96142
apiKey: String,
97143
text: String,
@@ -110,6 +156,7 @@ interface OrsClient {
110156
size: Int? = null,
111157
): GeocodeSearchResponse
112158

159+
/** Structured forward geocoding using discrete address fields. */
113160
suspend fun geocodeStructured(
114161
apiKey: String,
115162
address: String? = null,
@@ -135,6 +182,7 @@ interface OrsClient {
135182
size: Int? = null,
136183
): GeocodeSearchResponse
137184

185+
/** Reverse geocoding for a single coordinate. */
138186
suspend fun geocodeReverse(
139187
apiKey: String,
140188
lon: Double,

ors-client/src/main/java/org/nitri/ors/domain/elevation/ElevationDsl.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import kotlinx.serialization.json.JsonElement
55
import kotlinx.serialization.json.JsonPrimitive
66
import kotlinx.serialization.json.buildJsonArray
77

8-
// Kotlin DSL for ElevationLineRequest
8+
/** DSL for building [ElevationLineRequest] instances. */
99
inline fun elevationLineRequest(build: ElevationLineRequestBuilder.() -> Unit): ElevationLineRequest =
1010
ElevationLineRequestBuilder().apply(build).build()
1111

12+
/** Builder used by [elevationLineRequest]. */
1213
class ElevationLineRequestBuilder {
1314
var formatIn: String = ElevationFormats.POLYLINE
1415
var formatOut: String = ElevationFormats.GEOJSON
@@ -40,10 +41,11 @@ class ElevationLineRequestBuilder {
4041
}
4142
}
4243

43-
// Kotlin DSL for ElevationPointRequest
44+
/** DSL for constructing [ElevationPointRequest] objects. */
4445
inline fun elevationPointRequest(build: ElevationPointRequestBuilder.() -> Unit): ElevationPointRequest =
4546
ElevationPointRequestBuilder().apply(build).build()
4647

48+
/** Builder used by [elevationPointRequest]. */
4749
class ElevationPointRequestBuilder {
4850
var formatIn: String = "point"
4951
var formatOut: String = "geojson"
@@ -92,4 +94,4 @@ class ElevationPointRequestBuilderJ {
9294
fun dataset(v: String?) = apply { dsl.dataset = v }
9395
fun point(lon: Double, lat: Double) = apply { dsl.point(lon, lat) }
9496
fun build(): ElevationPointRequest = dsl.build()
95-
}
97+
}

ors-client/src/main/java/org/nitri/ors/domain/elevation/ElevationPointRequest.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@ package org.nitri.ors.domain.elevation
33
import kotlinx.serialization.SerialName
44
import kotlinx.serialization.Serializable
55

6+
/** Request for the `elevation/point` endpoint. */
67
@Serializable
78
data class ElevationPointRequest(
89
@SerialName("format_in")
9-
val formatIn: String, // Input format, must be provided (e.g., "point")
10+
/** Input format, e.g. `point`. */
11+
val formatIn: String,
1012

1113
@SerialName("format_out")
12-
val formatOut: String = "geojson", // "geojson" or "point"
14+
/** Output format: `geojson` or `point`. */
15+
val formatOut: String = "geojson",
1316

14-
val dataset: String? = null, // Optional dataset, e.g. "srtm"
17+
/** Optional elevation dataset name, e.g. `srtm`. */
18+
val dataset: String? = null,
1519

16-
val geometry: List<Double> // [lon, lat]
20+
/** Coordinate as `[lon, lat]`. */
21+
val geometry: List<Double>
1722
)

ors-client/src/main/java/org/nitri/ors/domain/export/ExportDsl.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package org.nitri.ors.domain.export
22

3-
// Kotlin DSL for ExportRequest
3+
/** DSL for creating [ExportRequest] objects. */
44
inline fun exportRequest(build: ExportRequestBuilder.() -> Unit): ExportRequest =
55
ExportRequestBuilder().apply(build).build()
66

7+
/** Builder used by [exportRequest]. */
78
class ExportRequestBuilder {
89
private var bbox: List<List<Double>>? = null
910
private var id: String? = null
@@ -23,7 +24,7 @@ class ExportRequestBuilder {
2324
}
2425
}
2526

26-
// Java-friendly builder
27+
/** Java-friendly builder counterpart. */
2728
class ExportRequestBuilderJ {
2829
private var bbox: List<List<Double>>? = null
2930
private var id: String? = null
@@ -41,4 +42,4 @@ class ExportRequestBuilderJ {
4142
val i = id ?: "export_request"
4243
return ExportRequest(bbox = b, id = i, geometry = geometry)
4344
}
44-
}
45+
}

ors-client/src/main/java/org/nitri/ors/domain/export/ExportRequest.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ package org.nitri.ors.domain.export
22

33
import kotlinx.serialization.Serializable
44

5+
/** Request payload for the export endpoint. */
56
@Serializable
67
data class ExportRequest(
7-
val bbox: List<List<Double>>, // [minLon, minLat, maxLon, maxLat]
8+
/** Bounding box specified as `[[minLon,minLat],[maxLon,maxLat]]`. */
9+
val bbox: List<List<Double>>,
10+
/** Client-specified identifier. */
811
val id: String,
12+
/** Whether to include full geometry in the response. */
913
val geometry: Boolean? = null
1014
)

0 commit comments

Comments
 (0)