Skip to content

Commit

Permalink
fix: [ANDROSDK-1866] Ensure events without registration are saved (#2160
Browse files Browse the repository at this point in the history
)
  • Loading branch information
marcamsn authored Jun 12, 2024
2 parents 1f88fbe + 247ee3d commit cf7571b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ internal abstract class IdentifiableDataHandlerImpl<O>(
relatives: RelationshipItemRelatives?,
)

protected fun beforeCollectionHandled(
protected open fun beforeCollectionHandled(
oCollection: Collection<O>,
params: IdentifiableDataHandlerParams,
): Collection<O> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import org.hisp.dhis.android.core.note.Note
import org.hisp.dhis.android.core.note.internal.NoteDHISVersionManager
import org.hisp.dhis.android.core.note.internal.NoteHandler
import org.hisp.dhis.android.core.note.internal.NoteUniquenessManager
import org.hisp.dhis.android.core.program.ProgramType
import org.hisp.dhis.android.core.program.internal.ProgramStore
import org.hisp.dhis.android.core.relationship.internal.EventRelationshipOrphanCleaner
import org.hisp.dhis.android.core.relationship.internal.RelationshipDHISVersionManager
import org.hisp.dhis.android.core.relationship.internal.RelationshipHandler
Expand All @@ -53,18 +55,33 @@ internal class EventHandler(
relationshipVersionManager: RelationshipDHISVersionManager,
relationshipHandler: RelationshipHandler,
eventStore: EventStore,
private val programStore: ProgramStore,
private val trackedEntityDataValueHandler: TrackedEntityDataValueHandler,
private val noteHandler: NoteHandler,
private val noteVersionManager: NoteDHISVersionManager,
private val noteUniquenessManager: NoteUniquenessManager,
private val relationshipOrphanCleaner: EventRelationshipOrphanCleaner,
) : IdentifiableDataHandlerImpl<Event>(eventStore, relationshipVersionManager, relationshipHandler) {

override fun beforeCollectionHandled(
oCollection: Collection<Event>,
params: IdentifiableDataHandlerParams,
): Collection<Event> {
val programTypes = programStore.selectAll().associate { it.uid() to it.programType() }

val updatedEvents = oCollection.map {
it.takeUnless { programTypes[it.program()] == ProgramType.WITHOUT_REGISTRATION }
?: it.toBuilder().enrollment(null).build()
}

return super.beforeCollectionHandled(updatedEvents, params)
}

override fun beforeObjectHandled(o: Event, params: IdentifiableDataHandlerParams): Event {
return if (GeometryHelper.isValid(o.geometry())) {
o
} else {
Log.i(this.javaClass.simpleName, "Event " + o.uid() + " has invalid geometry value")
Log.i(this::class.simpleName, "Event ${o.uid()} has an invalid geometry value")
o.toBuilder().geometry(null).build()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"program": "lxAQ7Zs9VYR",
"event": "single1",
"status": "COMPLETED",
"enrollment": "u9mt5Z8assp",
"occurredAt": "2018-02-27T00:00:00.000",
"createdAt": "2017-08-07T15:47:25.959",
"completedAt": "2016-02-27T00:00:00.000",
Expand Down Expand Up @@ -112,6 +113,7 @@
"program": "lxAQ7Zs9VYR",
"event": "single2",
"status": "ACTIVE",
"enrollment": "u9mt5Z8assp",
"occurredAt": "2017-02-27T00:00:00.000",
"createdAt": "2018-08-07T15:47:25.959",
"completedAt": "2018-02-27T00:00:00.000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import org.hisp.dhis.android.core.note.Note
import org.hisp.dhis.android.core.note.internal.NoteDHISVersionManager
import org.hisp.dhis.android.core.note.internal.NoteHandler
import org.hisp.dhis.android.core.note.internal.NoteUniquenessManager
import org.hisp.dhis.android.core.program.internal.ProgramStore
import org.hisp.dhis.android.core.relationship.internal.EventRelationshipOrphanCleaner
import org.hisp.dhis.android.core.relationship.internal.RelationshipDHISVersionManager
import org.hisp.dhis.android.core.relationship.internal.RelationshipHandler
Expand All @@ -51,6 +52,7 @@ import org.junit.runners.JUnit4
@RunWith(JUnit4::class)
class EventHandlerShould {
private val eventStore: EventStore = mock()
private val programStore: ProgramStore = mock()
private val trackedEntityDataValueHandler: TrackedEntityDataValueHandler = mock()
private val trackedEntityDataValue: TrackedEntityDataValue = mock()
private val noteHandler: NoteHandler = mock()
Expand Down Expand Up @@ -84,6 +86,7 @@ class EventHandlerShould {
relationshipVersionManager,
relationshipHandler,
eventStore,
programStore,
trackedEntityDataValueHandler,
noteHandler,
noteVersionManager,
Expand Down

0 comments on commit cf7571b

Please sign in to comment.