diff --git a/collect_app/src/main/java/org/odk/collect/android/projects/ProjectResetter.kt b/collect_app/src/main/java/org/odk/collect/android/projects/ProjectResetter.kt index e144535c0d6..57fcc979c57 100644 --- a/collect_app/src/main/java/org/odk/collect/android/projects/ProjectResetter.kt +++ b/collect_app/src/main/java/org/odk/collect/android/projects/ProjectResetter.kt @@ -17,27 +17,27 @@ package org.odk.collect.android.projects import org.odk.collect.android.fastexternalitemset.ItemsetDbAdapter import org.odk.collect.android.instancemanagement.InstancesDataService -import org.odk.collect.android.storage.StoragePathProvider -import org.odk.collect.android.storage.StorageSubdirectory -import org.odk.collect.android.utilities.FormsRepositoryProvider -import org.odk.collect.android.utilities.SavepointsRepositoryProvider +import org.odk.collect.android.storage.StoragePaths import org.odk.collect.android.utilities.WebCredentialsUtils import org.odk.collect.entities.storage.EntitiesRepository +import org.odk.collect.forms.FormsRepository +import org.odk.collect.forms.savepoints.SavepointsRepository import org.odk.collect.metadata.PropertyManager import org.odk.collect.projects.ProjectDependencyFactory import org.odk.collect.settings.SettingsProvider import java.io.File class ProjectResetter( - private val storagePathProvider: StoragePathProvider, + storagePathProvider: ProjectDependencyFactory, private val propertyManager: PropertyManager, private val settingsProvider: SettingsProvider, - private val formsRepositoryProvider: FormsRepositoryProvider, - private val savepointsRepositoryProvider: SavepointsRepositoryProvider, + private val formsRepositoryProvider: ProjectDependencyFactory, + private val savepointsRepositoryProvider: ProjectDependencyFactory, private val instancesDataService: InstancesDataService, private val projectId: String, private val entitiesRepositoryFactory: ProjectDependencyFactory ) { + private val storagePaths = storagePathProvider.create(projectId) private var failedResetActions = mutableListOf() @@ -62,7 +62,7 @@ class ProjectResetter( settingsProvider.getProtectedSettings().clear() settingsProvider.getProtectedSettings().setDefaultForAllSettingsWithoutValues() - if (!deleteFolderContent(storagePathProvider.getOdkDirPath(StorageSubdirectory.SETTINGS))) { + if (!deleteFolderContent(storagePaths.settingsDir)) { failedResetActions.add(ResetAction.RESET_PREFERENCES) } @@ -73,30 +73,31 @@ class ProjectResetter( entitiesRepositoryFactory.create(projectId).clear() if (!instancesDataService.deleteAll(projectId) || - !deleteFolderContent(storagePathProvider.getOdkDirPath(StorageSubdirectory.INSTANCES))) { + !deleteFolderContent(storagePaths.instancesDir) + ) { failedResetActions.add(ResetAction.RESET_INSTANCES) } } private fun resetForms() { - formsRepositoryProvider.create().deleteAll() + formsRepositoryProvider.create(projectId).deleteAll() - File(storagePathProvider.getOdkDirPath(StorageSubdirectory.METADATA) + File.separator + ItemsetDbAdapter.DATABASE_NAME).delete() + File(storagePaths.metaDir + File.separator + ItemsetDbAdapter.DATABASE_NAME).delete() - if (!deleteFolderContent(storagePathProvider.getOdkDirPath(StorageSubdirectory.FORMS))) { + if (!deleteFolderContent(storagePaths.formsDir)) { failedResetActions.add(ResetAction.RESET_FORMS) } } private fun resetLayers() { - if (!deleteFolderContent(storagePathProvider.getOdkDirPath(StorageSubdirectory.LAYERS))) { + if (!deleteFolderContent(storagePaths.layersDir)) { failedResetActions.add(ResetAction.RESET_LAYERS) } } private fun resetCache() { - savepointsRepositoryProvider.create().deleteAll() - if (!deleteFolderContent(storagePathProvider.getOdkDirPath(StorageSubdirectory.CACHE))) { + savepointsRepositoryProvider.create(projectId).deleteAll() + if (!deleteFolderContent(storagePaths.cacheDir)) { failedResetActions.add(ResetAction.RESET_CACHE) } } diff --git a/collect_app/src/main/java/org/odk/collect/android/storage/StoragePathProvider.kt b/collect_app/src/main/java/org/odk/collect/android/storage/StoragePathProvider.kt index d080cdd434e..36f0a1a3751 100644 --- a/collect_app/src/main/java/org/odk/collect/android/storage/StoragePathProvider.kt +++ b/collect_app/src/main/java/org/odk/collect/android/storage/StoragePathProvider.kt @@ -88,7 +88,9 @@ class StoragePathProvider( getOdkDirPath(StorageSubdirectory.FORMS, projectId), getOdkDirPath(StorageSubdirectory.INSTANCES, projectId), getOdkDirPath(StorageSubdirectory.CACHE, projectId), - getOdkDirPath(StorageSubdirectory.METADATA, projectId) + getOdkDirPath(StorageSubdirectory.METADATA, projectId), + getOdkDirPath(StorageSubdirectory.SETTINGS, projectId), + getOdkDirPath(StorageSubdirectory.LAYERS, projectId) ) } } diff --git a/collect_app/src/main/java/org/odk/collect/android/storage/StoragePaths.kt b/collect_app/src/main/java/org/odk/collect/android/storage/StoragePaths.kt index d68ae7e33d0..7d8fe3b6d29 100644 --- a/collect_app/src/main/java/org/odk/collect/android/storage/StoragePaths.kt +++ b/collect_app/src/main/java/org/odk/collect/android/storage/StoragePaths.kt @@ -5,5 +5,7 @@ data class StoragePaths( val formsDir: String, val instancesDir: String, val cacheDir: String, - val metaDir: String + val metaDir: String, + val settingsDir: String, + val layersDir: String ) diff --git a/collect_app/src/test/java/org/odk/collect/android/utilities/FormsRepositoryProviderTest.kt b/collect_app/src/test/java/org/odk/collect/android/utilities/FormsRepositoryProviderTest.kt index 71b20b4f32a..07f85d3fe1a 100644 --- a/collect_app/src/test/java/org/odk/collect/android/utilities/FormsRepositoryProviderTest.kt +++ b/collect_app/src/test/java/org/odk/collect/android/utilities/FormsRepositoryProviderTest.kt @@ -33,7 +33,9 @@ class FormsRepositoryProviderTest { formsDir.absolutePath, "", cacheDir.absolutePath, - metaDir.absolutePath + metaDir.absolutePath, + "", + "" ) }, mock() diff --git a/collect_app/src/test/java/org/odk/collect/android/utilities/InstancesRepositoryProviderTest.kt b/collect_app/src/test/java/org/odk/collect/android/utilities/InstancesRepositoryProviderTest.kt index e51a89525a6..091f1ec46df 100644 --- a/collect_app/src/test/java/org/odk/collect/android/utilities/InstancesRepositoryProviderTest.kt +++ b/collect_app/src/test/java/org/odk/collect/android/utilities/InstancesRepositoryProviderTest.kt @@ -26,7 +26,9 @@ class InstancesRepositoryProviderTest { "", instancesDir.absolutePath, "", - dbDir.absolutePath + dbDir.absolutePath, + "", + "" ) }