-
Notifications
You must be signed in to change notification settings - Fork 120
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
Replace suggestLoiTaskType with DataCollectionStrategy #2108
Conversation
This is now working, modulo:
Will mark "Ready for review" once those are fixed and/or out for review. @rfontanarosa FYI. |
…o gino-m/2097/1 # Conflicts: # ground/src/main/java/com/google/android/ground/persistence/sync/LocalMutationSyncWorker.kt
@scolsen PTAL @rfontanarosa FYI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couple of small comments but lgtm
data class Job( | ||
val id: String, | ||
val style: Style? = null, | ||
val name: String? = null, | ||
val tasks: Map<String, Task> = mapOf(), | ||
val suggestLoiTaskType: Task.Type? = null, | ||
val strategy: DataCollectionStrategy = DataCollectionStrategy.MIXED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this have a default? Don't we need this to be defined by survey organizers? Shouldn't it be a required argument, and shouldn't we error out if it's not available/provided?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value was mainly for tests, but that's probably the wrong reason. Updating now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing this turned out to be more disruptive than I expected; basically we end up needing to defined it in all tests even where it's not relevant. Ideally we'd have a custom constructor with default values for tests, but since we don't have yet that we can apply UNKNOWN as a default based on your next suggestion
) { | ||
enum class DataCollectionStrategy { | ||
PREDEFINED, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far, it's been helpful to have UNKNOWN
for cases in when the web app evolves before the android app/field names change. Not sure if you want to add one here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think UNKNOWN is useful for serialized representations like protos, but for model objects less so; if the strategy is invalid in remote or local data store, by the time to deserialize we should either have chosen a fall-back value, or thrown an error.
@@ -112,7 +113,7 @@ fun JobEntityAndRelations.toModelObject(): Job { | |||
jobEntity.style?.toModelObject(), | |||
jobEntity.name, | |||
taskMap.toPersistentMap(), | |||
jobEntity.suggestLoiTaskType?.let { Task.Type.valueOf(it) } | |||
jobEntity.strategy.let { DataCollectionStrategy.valueOf(it) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just DataCollectionStrategy.valueOf(jobEntity.strategy)
?
Or. like other entities, I might expect to see jobEntity.strategy.toModelObject()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just
DataCollectionStrategy.valueOf(jobEntity.strategy)
?
Because strategy
might be null, and Enum.valueOf() doesn't accept nulls
Or. like other entities, I might expect to see
jobEntity.strategy.toModelObject()
Because in jobEntity
strategy is a String, and defining fun String.?toModelObject()
would be too broad.
@@ -24,5 +25,5 @@ data class JobNestedObject( | |||
val defaultStyle: StyleNestedObject? = null, | |||
val name: String? = null, | |||
val tasks: Map<String, TaskNestedObject>? = null, | |||
val suggestLoiTaskType: String? = null | |||
val strategy: String = MIXED.toString() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I worry that this default value and the default value for the Job model object could get out of sync. I think removing a default from the model might be one way to avoid that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Done!
addAll(job.tasksSorted) | ||
} | ||
// LOI creation task is included only on "new data collection site" flow.. | ||
val tasks: List<Task> = job.tasksSorted.filter { loiId == null || !it.isAddLoiTask } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this filter a little tricky to understand. Seems like we're getting tasks that either have no LOI Id or that are explicitly not add LOI tasks. The latter makes sense given the comment, but I don't understand why we filter for tasks with loiId == null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're including all tasks when loiId = null. I can rewrite this, lmkwyt.
Fixes #2097