-
Notifications
You must be signed in to change notification settings - Fork 145
Add usecase to get Loi reports #3605
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a373cff
move LoiReport to sepparate package
andreia-ferreira da0fc50
move LoiProperties to domain
andreia-ferreira 0bfdb80
add usecase to get the loi report
andreia-ferreira c587e3b
add unit tests
andreia-ferreira 70aaf74
fix codestyle
andreia-ferreira 2bd3cd0
remove unused code
andreia-ferreira 632f89e
apply suggestions for usecase
andreia-ferreira 1bed725
apply suggestions for di module
andreia-ferreira e346529
add documentation
andreia-ferreira 6d587b0
Merge branch 'master' into andreia/3575/add-usecase
andreia-ferreira 222107b
update documentation
andreia-ferreira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
app/src/main/java/org/groundplatform/android/di/DomainModule.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.groundplatform.android.di | ||
|
|
||
| import dagger.Binds | ||
| import dagger.Module | ||
| import dagger.Provides | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.components.SingletonComponent | ||
| import org.groundplatform.android.repository.LoiDataProvider | ||
| import org.groundplatform.domain.usecases.GetLoiReportUseCase | ||
| import org.groundplatform.domain.usecases.LoiDataProviderInterface | ||
|
|
||
| @InstallIn(SingletonComponent::class) | ||
| @Module | ||
| internal abstract class DomainModule { | ||
| @Binds abstract fun bindLoiGeometryProvider(impl: LoiDataProvider): LoiDataProviderInterface | ||
|
|
||
| companion object { | ||
| @Provides | ||
| fun provideGetLoiGeometryUseCase(loiGeometryProvider: LoiDataProviderInterface) = | ||
| GetLoiReportUseCase(loiGeometryProvider) | ||
| } | ||
|
andreia-ferreira marked this conversation as resolved.
Outdated
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/src/main/java/org/groundplatform/android/repository/LoiDataProvider.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.groundplatform.android.repository | ||
|
|
||
| import javax.inject.Inject | ||
| import org.groundplatform.domain.usecases.LoiDataProviderInterface | ||
|
|
||
| class LoiDataProvider | ||
| @Inject | ||
| constructor(private val locationOfInterestRepository: LocationOfInterestRepository) : | ||
| LoiDataProviderInterface { | ||
| override suspend fun get(surveyId: String, loiId: String): LoiDataProviderInterface.LoiData? { | ||
| val loi = locationOfInterestRepository.getOfflineLoi(surveyId, loiId) | ||
| return loi?.let { | ||
| LoiDataProviderInterface.LoiData(geometry = it.geometry, properties = it.properties) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...ommonMain/kotlin/org/groundplatform/domain/model/locationofinterest/LocationOfInterest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.groundplatform.domain.model.locationofinterest | ||
|
|
||
| /** Alias for a map of properties with string names. */ | ||
| typealias LoiProperties = Map<String, Any> | ||
|
|
||
| const val LOI_NAME_PROPERTY = "name" | ||
|
|
||
| fun generateProperties(loiName: String? = null): LoiProperties = | ||
| loiName?.let { mapOf(LOI_NAME_PROPERTY to it) } ?: mapOf() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
core/domain/src/commonMain/kotlin/org/groundplatform/domain/usecases/GetLoiReportUseCase.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.groundplatform.domain.usecases | ||
|
|
||
| import kotlinx.serialization.json.JsonArray | ||
| import kotlinx.serialization.json.JsonElement | ||
| import kotlinx.serialization.json.JsonObject | ||
| import kotlinx.serialization.json.JsonPrimitive | ||
| import org.groundplatform.domain.model.geometry.Coordinates | ||
| import org.groundplatform.domain.model.geometry.Geometry | ||
| import org.groundplatform.domain.model.geometry.LineString | ||
| import org.groundplatform.domain.model.geometry.LinearRing | ||
| import org.groundplatform.domain.model.geometry.MultiPolygon | ||
| import org.groundplatform.domain.model.geometry.Point | ||
| import org.groundplatform.domain.model.geometry.Polygon | ||
| import org.groundplatform.domain.model.locationofinterest.LoiProperties | ||
| import org.groundplatform.domain.model.locationofinterest.LoiReport | ||
|
|
||
| class GetLoiReportUseCase(private val loiGeometryProvider: LoiDataProviderInterface) { | ||
|
shobhitagarwal1612 marked this conversation as resolved.
|
||
| suspend operator fun invoke(loiId: String, surveyId: String): LoiReport? { | ||
| val loiData = loiGeometryProvider.get(surveyId, loiId) | ||
| return loiData?.let { LoiReport(it.geometry.toGeoJson(it.properties)) } | ||
| } | ||
|
|
||
| /** | ||
| * Converts a [Geometry] to its GeoJSON representation as defined by | ||
| * [RFC 7946](https://datatracker.ietf.org/doc/html/rfc7946). | ||
| */ | ||
| private fun Geometry.toGeoJson(loiProperties: LoiProperties): JsonObject { | ||
| val geometryJson = | ||
| when (this) { | ||
| is Point -> geoJsonObject("Point", coordinatesToPosition(coordinates)) | ||
| is LineString -> geoJsonObject("LineString", coordinatesToPositions(coordinates)) | ||
| is LinearRing -> geoJsonObject("LineString", coordinatesToPositions(coordinates)) | ||
| is Polygon -> geoJsonObject("Polygon", polygonToCoordinates(this)) | ||
| is MultiPolygon -> | ||
| geoJsonObject("MultiPolygon", JsonArray(polygons.map { polygonToCoordinates(it) })) | ||
| } | ||
| return JsonObject( | ||
| mapOf( | ||
| "type" to JsonPrimitive("Feature"), | ||
| "properties" to JsonObject(loiProperties.mapValues { JsonPrimitive(it.value.toString()) }), | ||
|
andreia-ferreira marked this conversation as resolved.
Outdated
|
||
| "geometry" to geometryJson, | ||
|
shobhitagarwal1612 marked this conversation as resolved.
Outdated
|
||
| ) | ||
| ) | ||
| } | ||
|
|
||
| private fun geoJsonObject(type: String, coordinates: JsonElement): JsonObject = | ||
| JsonObject(mapOf("type" to JsonPrimitive(type), "coordinates" to coordinates)) | ||
|
|
||
| /** Converts a single [Coordinates] to a GeoJSON position: `[lng, lat]`. */ | ||
| private fun coordinatesToPosition(coordinates: Coordinates): JsonArray = | ||
| JsonArray(listOf(JsonPrimitive(coordinates.lng), JsonPrimitive(coordinates.lat))) | ||
|
|
||
| /** Converts a list of [Coordinates] to a GeoJSON array of positions. */ | ||
| private fun coordinatesToPositions(coordinates: List<Coordinates>): JsonArray = | ||
| JsonArray(coordinates.map { coordinatesToPosition(it) }) | ||
|
|
||
| /** Converts a [Polygon] to its GeoJSON coordinates (shell + holes as ring arrays). */ | ||
| private fun polygonToCoordinates(polygon: Polygon): JsonArray { | ||
| val rings = mutableListOf(coordinatesToPositions(polygon.shell.coordinates)) | ||
| polygon.holes.forEach { rings.add(coordinatesToPositions(it.coordinates)) } | ||
| return JsonArray(rings) | ||
| } | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
...main/src/commonMain/kotlin/org/groundplatform/domain/usecases/LoiDataProviderInterface.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.groundplatform.domain.usecases | ||
|
|
||
| import org.groundplatform.domain.model.geometry.Geometry | ||
| import org.groundplatform.domain.model.locationofinterest.LoiProperties | ||
|
|
||
| // TODO: Extract LocationOfInterestRepositoryInterface to domain module | ||
| // This is a temporary abstraction while the repository interface is still not fully decoupled from | ||
| // Android-specific types | ||
| interface LoiDataProviderInterface { | ||
| /** Returns the Geometry for an existing LOI, or null if not found. */ | ||
| suspend fun get(surveyId: String, loiId: String): LoiData? | ||
|
|
||
| data class LoiData(val geometry: Geometry, val properties: LoiProperties) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.