Skip to content

Commit

Permalink
Fix build 💚
Browse files Browse the repository at this point in the history
  • Loading branch information
ndegwamartin committed Sep 24, 2024
1 parent d3e1933 commit 8ee27c0
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 66 deletions.
1 change: 1 addition & 0 deletions android/engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ configurations {

dependencies {
implementation(libs.play.services.tasks)
implementation(libs.gms.play.services.location)
coreLibraryDesugaring(libs.core.desugar)

// Library dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,15 @@ constructor(
@ApplicationContext open val context: Context,
) {

suspend inline fun <reified T : Resource> loadResource(resourceId: String): T? {
return withContext(dispatcherProvider.io()) { fhirEngine.loadResource(resourceId) }
}
suspend inline fun <reified T : Resource> loadResource(resourceId: String): T? =
fhirEngine.loadResource(resourceId)

suspend fun loadResource(resourceId: String, resourceType: ResourceType): Resource =
withContext(dispatcherProvider.io()) { fhirEngine.get(resourceType, resourceId) }
fhirEngine.get(resourceType, resourceId)

suspend fun loadResource(reference: Reference) =
withContext(dispatcherProvider.io()) {
IdType(reference.reference).let {
fhirEngine.get(ResourceType.fromCode(it.resourceType), it.idPart)
}
IdType(reference.reference).let {
fhirEngine.get(ResourceType.fromCode(it.resourceType), it.idPart)
}

suspend inline fun <reified T : Resource> searchResourceFor(
Expand All @@ -135,19 +132,17 @@ constructor(
dataQueries: List<DataQuery> = listOf(),
configComputedRuleValues: Map<String, Any>,
): List<T> =
withContext(dispatcherProvider.io()) {
fhirEngine
.batchedSearch<T> {
filterByResourceTypeId(token, subjectType, subjectId)
dataQueries.forEach {
filterBy(
dataQuery = it,
configComputedRuleValues = configComputedRuleValues,
)
}
fhirEngine

Check warning on line 135 in android/engine/src/main/java/org/smartregister/fhircore/engine/data/local/DefaultRepository.kt

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/data/local/DefaultRepository.kt#L135

Added line #L135 was not covered by tests
.batchedSearch<T> {
filterByResourceTypeId(token, subjectType, subjectId)
dataQueries.forEach {
filterBy(
dataQuery = it,
configComputedRuleValues = configComputedRuleValues,

Check warning on line 141 in android/engine/src/main/java/org/smartregister/fhircore/engine/data/local/DefaultRepository.kt

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/data/local/DefaultRepository.kt#L137-L141

Added lines #L137 - L141 were not covered by tests
)
}
.map { it.resource }
}
}
.map { it.resource }

Check warning on line 145 in android/engine/src/main/java/org/smartregister/fhircore/engine/data/local/DefaultRepository.kt

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/data/local/DefaultRepository.kt#L145

Added line #L145 was not covered by tests

suspend inline fun <reified R : Resource> search(search: Search) =
fhirEngine.batchedSearch<R>(search).map { it.resource }
Expand All @@ -162,17 +157,13 @@ constructor(
* param [addResourceTags]
*/
suspend fun create(addResourceTags: Boolean = true, vararg resource: Resource): List<String> {
return withContext(dispatcherProvider.io()) {
preProcessResources(addResourceTags, *resource)
fhirEngine.create(*resource)
}
preProcessResources(addResourceTags, *resource)
return fhirEngine.create(*resource)
}

suspend fun createRemote(addResourceTags: Boolean = true, vararg resource: Resource) {
return withContext(dispatcherProvider.io()) {
preProcessResources(addResourceTags, *resource)
fhirEngine.create(*resource, isLocalOnly = true)
}
preProcessResources(addResourceTags, *resource)
fhirEngine.create(*resource, isLocalOnly = true)
}

private fun preProcessResources(addResourceTags: Boolean, vararg resource: Resource) {
Expand All @@ -198,23 +189,19 @@ constructor(
resourceId: String,
softDelete: Boolean = false,
) {
withContext(dispatcherProvider.io()) {
if (softDelete) {
val resource = fhirEngine.get(resourceType, resourceId)
softDelete(resource)
} else {
fhirEngine.delete(resourceType, resourceId)
}
if (softDelete) {
val resource = fhirEngine.get(resourceType, resourceId)
softDelete(resource)

Check warning on line 194 in android/engine/src/main/java/org/smartregister/fhircore/engine/data/local/DefaultRepository.kt

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/data/local/DefaultRepository.kt#L193-L194

Added lines #L193 - L194 were not covered by tests
} else {
fhirEngine.delete(resourceType, resourceId)
}
}

suspend fun delete(resource: Resource, softDelete: Boolean = false) {
withContext(dispatcherProvider.io()) {
if (softDelete) {
softDelete(resource)
} else {
fhirEngine.delete(resource.resourceType, resource.logicalId)
}
if (softDelete) {
softDelete(resource)

Check warning on line 202 in android/engine/src/main/java/org/smartregister/fhircore/engine/data/local/DefaultRepository.kt

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/data/local/DefaultRepository.kt#L202

Added line #L202 was not covered by tests
} else {
fhirEngine.delete(resource.resourceType, resource.logicalId)
}
}

Expand Down Expand Up @@ -243,24 +230,20 @@ constructor(
* param [addMandatoryTags]
*/
suspend fun <R : Resource> addOrUpdate(addMandatoryTags: Boolean = true, resource: R) {
return withContext(dispatcherProvider.io()) {
resource.updateLastUpdated()
try {
fhirEngine.get(resource.resourceType, resource.logicalId).run {
val updateFrom = updateFrom(resource)
fhirEngine.update(updateFrom)
}
} catch (resourceNotFoundException: ResourceNotFoundException) {
create(addMandatoryTags, resource)
resource.updateLastUpdated()
try {
fhirEngine.get(resource.resourceType, resource.logicalId).run {
val updateFrom = updateFrom(resource)
fhirEngine.update(updateFrom)
}
} catch (resourceNotFoundException: ResourceNotFoundException) {
create(addMandatoryTags, resource)
}
}

suspend fun <R : Resource> update(resource: R) {
return withContext(dispatcherProvider.io()) {
resource.updateLastUpdated()
fhirEngine.update(resource)
}
resource.updateLastUpdated()
fhirEngine.update(resource)
}

suspend fun loadManagingEntity(group: Group) =
Expand Down Expand Up @@ -904,7 +887,7 @@ constructor(
val updatedResource =
parser.parseResource(resourceDefinition, updatedResourceDocument.jsonString())
updatedResource.setId(updatedResource.idElement.idPart)
withContext(dispatcherProvider.io()) { fhirEngine.update(updatedResource as Resource) }
fhirEngine.update(updatedResource as Resource)
}

private fun getJsonContent(jsonElement: JsonElement): Any? {
Expand Down Expand Up @@ -935,9 +918,7 @@ constructor(

suspend fun purge(resource: Resource, forcePurge: Boolean) {
try {
withContext(dispatcherProvider.io()) {
fhirEngine.purge(resource.resourceType, resource.logicalId, forcePurge)
}
fhirEngine.purge(resource.resourceType, resource.logicalId, forcePurge)
} catch (resourceNotFoundException: ResourceNotFoundException) {
Timber.e(
"Purge failed -> Resource with ID ${resource.logicalId} does not exist",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ import org.smartregister.fhircore.engine.domain.model.ResourceFilterExpression
import org.smartregister.fhircore.engine.domain.model.RuleConfig
import org.smartregister.fhircore.engine.robolectric.RobolectricTest
import org.smartregister.fhircore.engine.rulesengine.ConfigRulesExecutor
import org.smartregister.fhircore.engine.util.DefaultDispatcherProvider
import org.smartregister.fhircore.engine.util.SharedPreferencesHelper
import org.smartregister.fhircore.engine.util.extension.asReference
import org.smartregister.fhircore.engine.util.extension.formatDate
Expand Down Expand Up @@ -128,16 +129,19 @@ class DefaultRepositoryTest : RobolectricTest() {
private val application = ApplicationProvider.getApplicationContext<Application>()
private val configurationRegistry: ConfigurationRegistry = Faker.buildTestConfigurationRegistry()
private val context = ApplicationProvider.getApplicationContext<HiltTestApplication>()
private lateinit var dispatcherProvider: DefaultDispatcherProvider
private lateinit var sharedPreferenceHelper: SharedPreferencesHelper
private lateinit var defaultRepository: DefaultRepository

@Before
fun setUp() {
hiltRule.inject()
sharedPreferenceHelper = SharedPreferencesHelper(application, gson)
dispatcherProvider = DefaultDispatcherProvider()
defaultRepository =
DefaultRepository(
fhirEngine = fhirEngine,
dispatcherProvider = dispatcherProvider,
sharedPreferencesHelper = sharedPreferenceHelper,
configurationRegistry = configurationRegistry,
configService = configService,
Expand Down Expand Up @@ -550,6 +554,7 @@ class DefaultRepositoryTest : RobolectricTest() {
spyk(
DefaultRepository(
fhirEngine = fhirEngine,
dispatcherProvider = dispatcherProvider,
sharedPreferencesHelper = mockk(),
configurationRegistry = mockk(),
configService = mockk(),
Expand Down Expand Up @@ -627,6 +632,7 @@ class DefaultRepositoryTest : RobolectricTest() {
spyk(
DefaultRepository(
fhirEngine = fhirEngine,
dispatcherProvider = dispatcherProvider,
sharedPreferencesHelper = mockk(),
configurationRegistry = mockk(),
configService = mockk(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import org.smartregister.fhircore.engine.domain.model.SyncLocationState
import org.smartregister.fhircore.engine.robolectric.RobolectricTest
import org.smartregister.fhircore.engine.rule.CoroutineTestRule
import org.smartregister.fhircore.engine.rulesengine.RulesFactory
import org.smartregister.fhircore.engine.util.DispatcherProvider
import org.smartregister.fhircore.engine.util.extension.asReference
import org.smartregister.fhircore.engine.util.extension.encodeJson
import org.smartregister.fhircore.engine.util.fhirpath.FhirPathDataExtractor
Expand Down Expand Up @@ -98,6 +99,8 @@ class RegisterRepositoryTest : RobolectricTest() {

@Inject lateinit var fhirPathDataExtractor: FhirPathDataExtractor

@Inject lateinit var dispatcherProvider: DispatcherProvider

@Inject lateinit var fhirEngine: FhirEngine

@Inject lateinit var parser: IParser
Expand All @@ -112,6 +115,7 @@ class RegisterRepositoryTest : RobolectricTest() {
spyk(
RegisterRepository(
fhirEngine = fhirEngine,
dispatcherProvider = dispatcherProvider,
sharedPreferencesHelper = mockk(),
configurationRegistry = configurationRegistry,
configService = mockk(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class FhirResourceExpireWorkerTest : RobolectricTest() {
spyk(
DefaultRepository(
fhirEngine = fhirEngine,
dispatcherProvider = dispatcherProvider,
sharedPreferencesHelper = mockk(),
configurationRegistry = configurationRegistry,
configService = mockk(),
Expand Down
3 changes: 1 addition & 2 deletions android/geowidget/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
<receiver
tools:replace="android:exported"
android:name="io.ona.kujaku.receivers.KujakuNetworkChangeReceiver"
android:exported="false"
tools:replace="exported">
android:exported="false">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
Expand Down
1 change: 1 addition & 0 deletions android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ foundation = { group = "androidx.compose.foundation", name = "foundation", versi
fragment-ktx = { group = "androidx.fragment", name = "fragment-ktx", version.ref = "fragment-ktx" }
fragment-testing = { group = "androidx.fragment", name = "fragment-testing", version.ref = "fragment-ktx" }
glide = { group = "com.github.bumptech.glide", name = "glide", version.ref = "glide" }
gms-play-services-location = { group = "com.google.android.gms", name = "play-services-location", version.ref = "playServicesLocation" }
gradle = { module = "com.android.tools.build:gradle", version.ref = "gradle" }
gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" }
hilt-compiler = { group = "androidx.hilt", name = "hilt-compiler", version.ref = "hilt" }
Expand Down
1 change: 1 addition & 0 deletions android/quest/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ tasks.withType<Test> {
configurations { all { exclude(group = "xpp3") } }

dependencies {
implementation(libs.gms.play.services.location)
coreLibraryDesugaring(libs.core.desugar)

// Application dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ constructor(
override val fhirPathDataExtractor: FhirPathDataExtractor,
override val parser: IParser,
@ApplicationContext override val context: Context,
val dispatcherProvider: DispatcherProvider,
override val dispatcherProvider: DispatcherProvider,
) :
DefaultRepository(
fhirEngine = fhirEngine,
Expand All @@ -68,6 +68,7 @@ constructor(
fhirPathDataExtractor = fhirPathDataExtractor,
parser = parser,
context = context,
dispatcherProvider = dispatcherProvider,
) {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import org.smartregister.fhircore.engine.domain.model.ActionParameter
import org.smartregister.fhircore.engine.domain.model.ActionParameterType
import org.smartregister.fhircore.engine.domain.model.SnackBarMessageConfig
import org.smartregister.fhircore.engine.rulesengine.ResourceDataRulesExecutor
import org.smartregister.fhircore.engine.util.DispatcherProvider
import org.smartregister.fhircore.engine.util.SharedPreferenceKey
import org.smartregister.fhircore.engine.util.SharedPreferencesHelper
import org.smartregister.fhircore.engine.util.extension.extractLogicalIdUuid
Expand All @@ -58,6 +59,7 @@ class GeoWidgetLauncherViewModel
@Inject
constructor(
val defaultRepository: DefaultRepository,
val dispatcherProvider: DispatcherProvider,
val sharedPreferencesHelper: SharedPreferencesHelper,
val resourceDataRulesExecutor: ResourceDataRulesExecutor,
val configurationRegistry: ConfigurationRegistry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class MeasureReportPagingSourceTest : RobolectricTest() {
spyk(
RegisterRepository(
fhirEngine = fhirEngine,
dispatcherProvider = dispatcherProvider,
sharedPreferencesHelper = mockk(),
configurationRegistry = configurationRegistry,
configService = mockk(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class MeasureReportRepositoryTest : RobolectricTest() {
spyk(
RegisterRepository(
fhirEngine = fhirEngine,
dispatcherProvider = dispatcherProvider,
sharedPreferencesHelper = mockk(),
configurationRegistry = configurationRegistry,
configService = mockk(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class PdfLauncherViewModelTest : RobolectricTest() {
defaultRepository =
DefaultRepository(
fhirEngine = fhirEngine,
dispatcherProvider = mockk(),
sharedPreferencesHelper = mockk(),
configurationRegistry = mockk(),
configService = mockk(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import org.smartregister.fhircore.engine.domain.model.FhirResourceConfig
import org.smartregister.fhircore.engine.domain.model.ResourceConfig
import org.smartregister.fhircore.engine.domain.model.SnackBarMessageConfig
import org.smartregister.fhircore.engine.rulesengine.ResourceDataRulesExecutor
import org.smartregister.fhircore.engine.util.DefaultDispatcherProvider
import org.smartregister.fhircore.engine.util.SharedPreferencesHelper
import org.smartregister.fhircore.geowidget.model.GeoJsonFeature
import org.smartregister.fhircore.quest.app.fakes.Faker
Expand All @@ -61,6 +62,8 @@ class GeoWidgetLauncherViewModelTest : RobolectricTest() {

@Inject lateinit var defaultRepository: DefaultRepository

@Inject lateinit var dispatcherProvider: DefaultDispatcherProvider

@Inject lateinit var sharedPreferencesHelper: SharedPreferencesHelper

@Inject lateinit var resourceDataRulesExecutor: ResourceDataRulesExecutor
Expand Down Expand Up @@ -98,6 +101,7 @@ class GeoWidgetLauncherViewModelTest : RobolectricTest() {
viewModel =
GeoWidgetLauncherViewModel(
defaultRepository = defaultRepository,
dispatcherProvider = dispatcherProvider,
sharedPreferencesHelper = sharedPreferencesHelper,
resourceDataRulesExecutor = resourceDataRulesExecutor,
configurationRegistry = configurationRegistry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import org.smartregister.fhircore.engine.domain.model.OverflowMenuItemConfig
import org.smartregister.fhircore.engine.domain.model.RepositoryResourceData
import org.smartregister.fhircore.engine.domain.model.ResourceData
import org.smartregister.fhircore.engine.rulesengine.ResourceDataRulesExecutor
import org.smartregister.fhircore.engine.util.DefaultDispatcherProvider
import org.smartregister.fhircore.engine.util.DispatcherProvider
import org.smartregister.fhircore.engine.util.extension.BLACK_COLOR_HEX_CODE
import org.smartregister.fhircore.engine.util.extension.getActivity
Expand Down Expand Up @@ -98,6 +99,7 @@ class ProfileViewModelTest : RobolectricTest() {
spyk(
RegisterRepository(
fhirEngine = mockk(),
dispatcherProvider = DefaultDispatcherProvider(),
sharedPreferencesHelper = mockk(),
configurationRegistry = configurationRegistry,
configService = mockk(),
Expand Down
Loading

0 comments on commit 8ee27c0

Please sign in to comment.