Skip to content

Commit

Permalink
Merge pull request #6466 from seadowg/static-csv-property
Browse files Browse the repository at this point in the history
Set user property when there is a static CSV and entity list clash
  • Loading branch information
seadowg authored Oct 23, 2024
2 parents 14b8a59 + 2b12da6 commit 49c74d9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TaskSpecWorker(
override fun doWork(): Result {
val cellularOnly = inputData.getBoolean(DATA_CELLULAR_ONLY, false)
if (cellularOnly && connectivityProvider.currentNetwork != Scheduler.NetworkType.CELLULAR) {
Analytics.setUserProperty("EncounteredMeteredNonCellularInTasks", "true")
Analytics.setUserProperty("SawMeteredNonCellular", "true")
return Result.retry()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.odk.collect.android.formmanagement

import org.odk.collect.analytics.Analytics
import org.odk.collect.android.formmanagement.download.FormDownloadException
import org.odk.collect.android.formmanagement.download.FormDownloader
import org.odk.collect.android.utilities.FileUtils
Expand Down Expand Up @@ -111,14 +112,28 @@ object ServerFormUseCases {
}

if (mediaFile.isEntityList) {
val dataset = mediaFile.filename.substringBefore(".csv")
LocalEntityUseCases.updateLocalEntitiesFromServer(dataset, tempMediaFile, entitiesRepository)
val entityListName = getEntityListFromFileName(mediaFile)
LocalEntityUseCases.updateLocalEntitiesFromServer(entityListName, tempMediaFile, entitiesRepository)
} else {
/**
* Track CSVs that have names that clash with entity lists in the project. If
* these CSVs are being used as part of a `select_one_from_file` question, the
* instance ID will be the file name with the extension removed.
*/
val isCsv = mediaFile.filename.endsWith(".csv")
val mostLikelyInstanceId = getEntityListFromFileName(mediaFile)
if (isCsv && entitiesRepository.getLists().contains(mostLikelyInstanceId)) {
Analytics.setUserProperty("HasEntityListCollision", "true")
}
}
}

return atLeastOneNewMediaFileDetected
}

private fun getEntityListFromFileName(mediaFile: MediaFile) =
mediaFile.filename.substringBefore(".csv")

private fun searchForExistingMediaFile(
formsRepository: FormsRepository,
formToDownload: ServerFormDetails,
Expand Down

0 comments on commit 49c74d9

Please sign in to comment.