Skip to content

Commit

Permalink
Refactor isOpportunistic to isPlanned
Browse files Browse the repository at this point in the history
  • Loading branch information
sufyanAbbasi committed Mar 6, 2024
1 parent 9f00c79 commit be162c9
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 28 deletions.
2 changes: 1 addition & 1 deletion ground/src/main/java/com/google/android/ground/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object Config {

// Local db settings.
// TODO(#128): Reset version to 1 before releasing.
const val DB_VERSION = 114
const val DB_VERSION = 115
const val DB_NAME = "ground.db"

// Firebase Cloud Firestore settings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,10 @@ data class LocationOfInterest(
* the user.
*/
val ownerEmail: String? = null,
/**
* Whether this LOI was created opportunistically by the user through the Suggest LOI flow, or
* false if the LOI was created by the survey organizer.
*/
val isOpportunistic: Boolean = false,
/** Custom map of properties for this LOI. Corresponds to the properties field in GeoJSON */
val properties: LoiProperties = mapOf(),
/** Whether the LOI was predefined in the survey or not (i.e. added ad hoc). */
val planned: Boolean? = null,
val isPlanned: Boolean? = null,
) {

/**
Expand All @@ -76,8 +71,8 @@ data class LocationOfInterest(
geometry = geometry,
submissionCount = submissionCount,
ownerEmail = ownerEmail,
isOpportunistic = isOpportunistic,
properties = properties,
isPlanned = isPlanned,
)

fun getProperty(key: String): String = properties[key]?.toString() ?: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ data class LocationOfInterestMutation(
val geometry: Geometry? = null,
val submissionCount: Int = 0,
val ownerEmail: String? = null,
val isOpportunistic: Boolean = false,
val properties: LoiProperties = mapOf(),
val isPlanned: Boolean? = null,
) : Mutation()
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,8 @@ fun LocationOfInterest.toLocalDataStoreObject() =
customId = customId,
submissionCount = submissionCount,
ownerEmail = ownerEmail,
isOpportunistic = isOpportunistic,
properties = properties,
// TODO(#2300): Add `planned` field for local storage.
isPlanned = isPlanned,
)

fun LocationOfInterestEntity.toModelObject(survey: Survey): LocationOfInterest =
Expand All @@ -167,12 +166,12 @@ fun LocationOfInterestEntity.toModelObject(survey: Survey): LocationOfInterest =
geometry = geometry.getGeometry(),
submissionCount = submissionCount,
properties = properties,
isPlanned = isPlanned,
job =
survey.getJob(jobId = jobId)
?: throw LocalDataConsistencyException(
"Unknown jobId ${this.jobId} in location of interest ${this.id}"
)
// TODO(#2300): Add `planned` field for rendering use.
)
}

Expand All @@ -198,8 +197,8 @@ fun LocationOfInterestMutation.toLocalDataStoreObject(user: User): LocationOfInt
customId = customId,
submissionCount = submissionCount,
ownerEmail = ownerEmail,
isOpportunistic = isOpportunistic,
properties = properties
properties = properties,
isPlanned = isPlanned,
)
}

Expand All @@ -218,6 +217,7 @@ fun LocationOfInterestMutation.toLocalDataStoreObject() =
lastError = lastError,
retryCount = retryCount,
newProperties = properties,
isPlanned = isPlanned,
)

fun LocationOfInterestMutationEntity.toModelObject() =
Expand All @@ -234,7 +234,8 @@ fun LocationOfInterestMutationEntity.toModelObject() =
clientTimestamp = Date(clientTimestamp),
lastError = lastError,
retryCount = retryCount,
properties = newProperties
properties = newProperties,
isPlanned = isPlanned,
)

fun MultipleChoiceEntity.toModelObject(optionEntities: List<OptionEntity>): MultipleChoice {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ data class LocationOfInterestEntity(
val customId: String,
val submissionCount: Int,
val ownerEmail: String?,
val isOpportunistic: Boolean,
val properties: LoiProperties,
// TODO(#2300): Add `planned` field for local storage.
val isPlanned: Boolean?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ data class LocationOfInterestMutationEntity(
@ColumnInfo(name = "client_timestamp") val clientTimestamp: Long,
@ColumnInfo(name = "location_of_interest_id") val locationOfInterestId: String,
@ColumnInfo(name = "job_id") val jobId: String,
@ColumnInfo(name = "is_planned") val isPlanned: Boolean?,
/** Non-null if the LOI's geometry was updated, null if unchanged. */
val newGeometry: GeometryWrapper?,
val newProperties: LoiProperties,
val newCustomId: String
val newCustomId: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object LoiConverter {
const val GEOMETRY_COORDINATES = "coordinates"
const val GEOMETRY = "geometry"
const val SUBMISSION_COUNT = "submissionCount"
const val PLANNED = "planned"
const val IS_PLANNED = "planned"

fun toLoi(survey: Survey, doc: DocumentSnapshot): Result<LocationOfInterest> = runCatching {
toLoiUnchecked(survey, doc)
Expand Down Expand Up @@ -73,7 +73,7 @@ object LoiConverter {
geometry = geometry,
submissionCount = submissionCount,
properties = loiDoc.properties ?: mapOf(),
planned = loiDoc.planned,
isPlanned = loiDoc.planned,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal object LoiMutationConverter {
Mutation.Type.CREATE -> {
map[LoiConverter.CREATED] = auditInfo
map[LoiConverter.LAST_MODIFIED] = auditInfo
map[LoiConverter.PLANNED] = false
map[LoiConverter.IS_PLANNED] = mutation.isPlanned ?: false
}
Mutation.Type.UPDATE -> {
map[LoiConverter.LAST_MODIFIED] = auditInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ constructor(
created = auditInfo,
lastModified = auditInfo,
ownerEmail = user.email,
isOpportunistic = true
isPlanned = false
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ import com.google.android.ground.ui.map.gms.GmsExt.getShellCoordinates
import com.google.common.truth.Truth.assertThat
import com.sharedtest.FakeData
import dagger.hilt.android.testing.HiltAndroidTest
import java.util.*
import javax.inject.Inject
import kotlin.test.assertFailsWith
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.advanceUntilIdle
Expand All @@ -56,9 +59,6 @@ import org.hamcrest.Matchers
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import java.util.*
import javax.inject.Inject
import kotlin.test.assertFailsWith

@HiltAndroidTest
@RunWith(RobolectricTestRunner::class)
Expand Down Expand Up @@ -415,7 +415,7 @@ class LocalDataStoreTests : BaseHiltTest() {
job = TEST_JOB,
submissionId = "submission id",
deltas =
listOf(ValueDelta("task id", Task.Type.TEXT, TextResponse.fromString("updated value"))),
listOf(ValueDelta("task id", Task.Type.TEXT, TextResponse.fromString("updated value"))),
id = 1L,
type = Mutation.Type.CREATE,
syncStatus = SyncStatus.PENDING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import com.google.android.ground.model.mutation.Mutation
import com.google.common.truth.Truth.assertThat
import com.google.firebase.firestore.GeoPoint
import com.sharedtest.FakeData
import kotlin.test.fail
import org.junit.Assert.assertThrows
import org.junit.Test
import kotlin.test.fail

class LoiMutationConverterTest {
@Test
Expand Down Expand Up @@ -65,7 +65,7 @@ class LoiMutationConverterTest {
assertThat(map[CREATED]).isEqualTo(map[LAST_MODIFIED])
assertThat(map[CREATED])
.isEqualTo(AuditInfoConverter.fromMutationAndUser(mutation, TEST_USER))
assertThat(map[PLANNED]).isEqualTo(false)
assertThat(map[IS_PLANNED]).isEqualTo(false)
}
}

Expand Down

0 comments on commit be162c9

Please sign in to comment.