Skip to content

Commit

Permalink
code clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
Santosh Pingle committed Oct 27, 2023
1 parent 5423ea8 commit 3b0adce
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ abstract class FhirSyncWorker(appContext: Context, workerParams: WorkerParameter

val synchronizer =
FhirSynchronizer(
applicationContext,
getFhirEngine(),
Uploader(dataSource),
DownloaderImpl(dataSource, getDownloadWorkManager()),
getConflictResolver(),
FhirEngineProvider.getFhirDataStore(applicationContext),
)

val job =
Expand Down Expand Up @@ -101,7 +101,7 @@ abstract class FhirSyncWorker(appContext: Context, workerParams: WorkerParameter
// await/join is needed to collect states completely
kotlin.runCatching { job.join() }.onFailure(Timber::w)

// setProgress(output)
setProgress(output)

Timber.d("Received result from worker $result and sending output $output")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

package com.google.android.fhir.sync

import android.content.Context
import com.google.android.fhir.FhirEngine
import com.google.android.fhir.FhirEngineProvider
import com.google.android.fhir.sync.download.DownloadState
import com.google.android.fhir.sync.download.Downloader
import com.google.android.fhir.sync.upload.LocalChangesFetchMode
Expand Down Expand Up @@ -46,18 +44,16 @@ data class ResourceSyncException(val resourceType: ResourceType, val exception:

/** Class that helps synchronize the data source and save it in the local database */
internal class FhirSynchronizer(
context: Context,
private val fhirEngine: FhirEngine,
private val uploader: Uploader,
private val downloader: Downloader,
private val conflictResolver: ConflictResolver,
private val datastoreUtil: FhirDataStore,
) {

private val _syncState = MutableSharedFlow<SyncJobStatus>()
val syncState: SharedFlow<SyncJobStatus> = _syncState

private val datastoreUtil = FhirEngineProvider.getFhirDataStore(context)

private suspend fun setSyncState(state: SyncJobStatus) = _syncState.emit(state)

private suspend fun setSyncState(result: SyncResult): SyncJobStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.google.android.fhir.sync

import androidx.test.core.app.ApplicationProvider
import com.google.android.fhir.LocalChangeToken
import com.google.android.fhir.sync.download.DownloadState
import com.google.android.fhir.sync.download.Downloader
Expand Down Expand Up @@ -49,18 +48,20 @@ class FhirSynchronizerTest {

@Mock private lateinit var conflictResolver: ConflictResolver

@Mock private lateinit var fhirDataStore: FhirDataStore

private lateinit var fhirSynchronizer: FhirSynchronizer

@Before
fun setUp() {
MockitoAnnotations.openMocks(this)
fhirSynchronizer =
FhirSynchronizer(
ApplicationProvider.getApplicationContext(),
TestFhirEngineImpl,
uploader,
downloader,
conflictResolver,
fhirDataStore,
)
}

Expand Down

0 comments on commit 3b0adce

Please sign in to comment.