Skip to content

Commit

Permalink
[ANDROSDK-1866] Refactor code to remove enrollments on the beforeColl…
Browse files Browse the repository at this point in the history
…ectionHandled method
  • Loading branch information
marcamsn committed Jun 11, 2024
1 parent f79efd1 commit 0769151
Showing 1 changed file with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,27 @@ internal class EventHandler(
private val relationshipOrphanCleaner: EventRelationshipOrphanCleaner,
) : IdentifiableDataHandlerImpl<Event>(eventStore, relationshipVersionManager, relationshipHandler) {

private var programTypes = mutableMapOf<String, ProgramType?>()

override fun beforeCollectionHandled(
oCollection: Collection<Event>,
params: IdentifiableDataHandlerParams,
): Collection<Event> {
programStore.selectAll().forEach {
programTypes[it.uid()] = it.programType()
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(oCollection, params)

return super.beforeCollectionHandled(updatedEvents, params)
}

override fun beforeObjectHandled(o: Event, params: IdentifiableDataHandlerParams): Event {
val builder = o.toBuilder()

if (programTypes[o.program()] == ProgramType.WITHOUT_REGISTRATION) {
builder.enrollment(null)
}

if (!GeometryHelper.isValid(o.geometry())) {
Log.i(this.javaClass.simpleName, "Event " + o.uid() + " has invalid geometry value")
builder.geometry(null)
return if (GeometryHelper.isValid(o.geometry())) {
o
} else {
Log.i(this::class.simpleName, "Event ${o.uid()} has an invalid geometry value")
o.toBuilder().geometry(null).build()
}

return builder.build()
}

override fun afterObjectHandled(
Expand Down Expand Up @@ -127,10 +123,6 @@ internal class EventHandler(
}
}
}
override fun afterCollectionHandled(oCollection: Collection<Event>?, params: IdentifiableDataHandlerParams) {
programTypes.clear()
super.afterCollectionHandled(oCollection, params)
}

override fun deleteIfCondition(o: Event): Boolean {
val validEventDate = o.eventDate() != null ||
Expand Down

0 comments on commit 0769151

Please sign in to comment.