Skip to content

Commit

Permalink
Remvoe deprecated dependeny lookups in ProjectResetter
Browse files Browse the repository at this point in the history
  • Loading branch information
seadowg committed Jul 31, 2024
1 parent f6aaaee commit e878244
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<StoragePaths>,
private val propertyManager: PropertyManager,
private val settingsProvider: SettingsProvider,
private val formsRepositoryProvider: FormsRepositoryProvider,
private val savepointsRepositoryProvider: SavepointsRepositoryProvider,
private val formsRepositoryProvider: ProjectDependencyFactory<FormsRepository>,
private val savepointsRepositoryProvider: ProjectDependencyFactory<SavepointsRepository>,
private val instancesDataService: InstancesDataService,
private val projectId: String,
private val entitiesRepositoryFactory: ProjectDependencyFactory<EntitiesRepository>
) {
private val storagePaths = storagePathProvider.create(projectId)

private var failedResetActions = mutableListOf<Int>()

Expand All @@ -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)
}

Expand All @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class FormsRepositoryProviderTest {
formsDir.absolutePath,
"",
cacheDir.absolutePath,
metaDir.absolutePath
metaDir.absolutePath,
"",
""
)
},
mock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class InstancesRepositoryProviderTest {
"",
instancesDir.absolutePath,
"",
dbDir.absolutePath
dbDir.absolutePath,
"",
""
)
}

Expand Down

0 comments on commit e878244

Please sign in to comment.