From 270470beb42f34b086d37084a1f80ba4507510b2 Mon Sep 17 00:00:00 2001 From: Shobhit Agarwal Date: Tue, 18 Jun 2024 16:47:08 +0530 Subject: [PATCH] Remove unused code related to loading submissions (#2503) --- .../persistence/remote/RemoteDataStore.kt | 7 ---- .../remote/firebase/FirestoreDataStore.kt | 11 ------ .../base/FluentCollectionReference.kt | 34 ------------------- .../schema/SubmissionCollectionReference.kt | 14 -------- .../schema/SubmissionMutationConverter.kt | 2 +- .../persistence/remote/FakeRemoteDataStore.kt | 5 --- 6 files changed, 1 insertion(+), 72 deletions(-) diff --git a/ground/src/main/java/com/google/android/ground/persistence/remote/RemoteDataStore.kt b/ground/src/main/java/com/google/android/ground/persistence/remote/RemoteDataStore.kt index 24938faf51..54ddafd131 100644 --- a/ground/src/main/java/com/google/android/ground/persistence/remote/RemoteDataStore.kt +++ b/ground/src/main/java/com/google/android/ground/persistence/remote/RemoteDataStore.kt @@ -21,7 +21,6 @@ import com.google.android.ground.model.TermsOfService import com.google.android.ground.model.User import com.google.android.ground.model.locationofinterest.LocationOfInterest import com.google.android.ground.model.mutation.Mutation -import com.google.android.ground.model.submission.Submission import kotlinx.coroutines.flow.Flow /** @@ -49,12 +48,6 @@ interface RemoteDataStore { /** Returns LOIs created by the specified email in the specified survey. Main-safe. */ suspend fun loadUserDefinedLois(survey: Survey, creatorEmail: String): List - /** - * Returns a list of all submissions associated with the specified LOI, or an empty list if none - * are found. - */ - suspend fun loadSubmissions(locationOfInterest: LocationOfInterest): List - /** * Applies the provided mutations to the remote data store in a single batched transaction. If one * update fails, none of the mutations will be applied. diff --git a/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/FirestoreDataStore.kt b/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/FirestoreDataStore.kt index 0383d62b59..ae3cc319e7 100644 --- a/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/FirestoreDataStore.kt +++ b/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/FirestoreDataStore.kt @@ -20,11 +20,9 @@ import com.google.android.ground.model.Survey import com.google.android.ground.model.SurveyListItem import com.google.android.ground.model.TermsOfService import com.google.android.ground.model.User -import com.google.android.ground.model.locationofinterest.LocationOfInterest import com.google.android.ground.model.mutation.LocationOfInterestMutation import com.google.android.ground.model.mutation.Mutation import com.google.android.ground.model.mutation.SubmissionMutation -import com.google.android.ground.model.submission.Submission import com.google.android.ground.model.toListItem import com.google.android.ground.persistence.remote.RemoteDataStore import com.google.android.ground.persistence.remote.firebase.schema.GroundFirestore @@ -59,15 +57,6 @@ internal constructor( override suspend fun loadSurvey(surveyId: String): Survey = withContext(ioDispatcher) { db().surveys().survey(surveyId).get() } - override suspend fun loadSubmissions(locationOfInterest: LocationOfInterest): List = - withContext(ioDispatcher) { - db() - .surveys() - .survey(locationOfInterest.surveyId) - .submissions() - .submissionsByLocationOfInterestId(locationOfInterest) - } - override suspend fun loadTermsOfService(): TermsOfService? = withContext(ioDispatcher) { db().termsOfService().terms().get() } diff --git a/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/base/FluentCollectionReference.kt b/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/base/FluentCollectionReference.kt index 2bc09422c1..dc9555d3fd 100644 --- a/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/base/FluentCollectionReference.kt +++ b/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/base/FluentCollectionReference.kt @@ -16,14 +16,9 @@ package com.google.android.ground.persistence.remote.firebase.base -import com.google.android.ground.system.NetworkManager import com.google.firebase.firestore.CollectionReference -import com.google.firebase.firestore.DocumentSnapshot -import com.google.firebase.firestore.Query import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.tasks.await -import timber.log.Timber open class FluentCollectionReference protected constructor( @@ -32,35 +27,6 @@ protected constructor( protected val defaultDispatcher: CoroutineDispatcher = Dispatchers.Default, ) { - private val context = reference.firestore.app.applicationContext - - /** - * Runs the specified query, returning a Single containing a List of values created by applying - * the mappingFunction to all results. Fails immediately with an error if an active network is not - * available. - */ - protected suspend fun runQuery( - query: Query, - mappingFunction: (snapshot: DocumentSnapshot) -> T, - ): List { - NetworkManager(context).requireNetworkConnection() - val querySnapshot = query.get().await() - return querySnapshot.documents - .filter { it.exists() } - .mapNotNull { applyFunctionAndIgnoreFailures(it, mappingFunction) } - } - - private fun applyFunctionAndIgnoreFailures( - value: DocumentSnapshot, - mappingFunction: (snapshot: DocumentSnapshot) -> T, - ): T? = - try { - mappingFunction(value) - } catch (e: Throwable) { - Timber.e(e, "Skipping corrupt remote document: ${value.id}") - null - } - protected fun reference(): CollectionReference = reference override fun toString(): String = reference.path diff --git a/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/schema/SubmissionCollectionReference.kt b/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/schema/SubmissionCollectionReference.kt index 5ff83b961d..84de359677 100644 --- a/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/schema/SubmissionCollectionReference.kt +++ b/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/schema/SubmissionCollectionReference.kt @@ -16,25 +16,11 @@ package com.google.android.ground.persistence.remote.firebase.schema -import com.google.android.ground.model.locationofinterest.LocationOfInterest -import com.google.android.ground.model.submission.Submission import com.google.android.ground.persistence.remote.firebase.base.FluentCollectionReference import com.google.firebase.firestore.CollectionReference -import com.google.firebase.firestore.FieldPath -import com.google.firebase.firestore.Query class SubmissionCollectionReference internal constructor(ref: CollectionReference) : FluentCollectionReference(ref) { fun submission(id: String) = SubmissionDocumentReference(reference().document(id)) - - suspend fun submissionsByLocationOfInterestId( - locationOfInterest: LocationOfInterest - ): List = - runQuery(byLoiId(locationOfInterest.id)) { - SubmissionConverter.toSubmission(locationOfInterest, it) - } - - private fun byLoiId(loiId: String): Query = - reference().whereEqualTo(FieldPath.of(SubmissionMutationConverter.LOI_ID), loiId) } diff --git a/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/schema/SubmissionMutationConverter.kt b/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/schema/SubmissionMutationConverter.kt index 206b504df9..64a73bedff 100644 --- a/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/schema/SubmissionMutationConverter.kt +++ b/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/schema/SubmissionMutationConverter.kt @@ -29,7 +29,7 @@ import timber.log.Timber /** Converts between Firestore maps used to merge updates and [SubmissionMutation] instances. */ internal object SubmissionMutationConverter { - const val LOI_ID = "loiId" + private const val LOI_ID = "loiId" private const val JOB_ID = "jobId" private const val DATA = "data" private const val CREATED = "created" diff --git a/sharedTest/src/main/kotlin/com/sharedtest/persistence/remote/FakeRemoteDataStore.kt b/sharedTest/src/main/kotlin/com/sharedtest/persistence/remote/FakeRemoteDataStore.kt index 2e1b4c5700..d705a2255f 100644 --- a/sharedTest/src/main/kotlin/com/sharedtest/persistence/remote/FakeRemoteDataStore.kt +++ b/sharedTest/src/main/kotlin/com/sharedtest/persistence/remote/FakeRemoteDataStore.kt @@ -21,7 +21,6 @@ import com.google.android.ground.model.TermsOfService import com.google.android.ground.model.User import com.google.android.ground.model.locationofinterest.LocationOfInterest import com.google.android.ground.model.mutation.Mutation -import com.google.android.ground.model.submission.Submission import com.google.android.ground.model.toListItem import com.google.android.ground.persistence.remote.RemoteDataStore import javax.inject.Inject @@ -52,10 +51,6 @@ class FakeRemoteDataStore @Inject internal constructor() : RemoteDataStore { override suspend fun loadPredefinedLois(survey: Survey) = predefinedLois - override suspend fun loadSubmissions(locationOfInterest: LocationOfInterest): List { - TODO("Missing implementation") - } - override suspend fun applyMutations(mutations: List, user: User) { if (applyMutationError != null) { throw applyMutationError as Error