Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import com.quran.shared.syncengine.conflict.ConflictResolver
import com.quran.shared.syncengine.conflict.ConflictDetectionResult
import com.quran.shared.syncengine.conflict.ResourceConflict
import com.quran.shared.syncengine.model.SyncBookmark
import com.quran.shared.syncengine.preprocessing.LocalMutationsPreprocessor
import com.quran.shared.syncengine.preprocessing.RemoteMutationsPreprocessor
import com.quran.shared.syncengine.preprocessing.BookmarksLocalMutationsPreprocessor
import com.quran.shared.syncengine.preprocessing.BookmarksRemoteMutationsPreprocessor
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.contentOrNull
Expand Down Expand Up @@ -115,14 +115,14 @@ internal class BookmarksSyncAdapter(
private fun preprocessLocalMutations(
mutations: List<LocalModelMutation<SyncBookmark>>
): List<LocalModelMutation<SyncBookmark>> {
val preprocessor = LocalMutationsPreprocessor()
val preprocessor = BookmarksLocalMutationsPreprocessor()
return preprocessor.preprocess(mutations)
}

private suspend fun preprocessRemoteMutations(
mutations: List<RemoteModelMutation<SyncBookmark>>
): List<RemoteModelMutation<SyncBookmark>> {
val preprocessor = RemoteMutationsPreprocessor { remoteIds ->
val preprocessor = BookmarksRemoteMutationsPreprocessor { remoteIds ->
configurations.localDataFetcher.checkLocalExistence(remoteIds)
}
return preprocessor.preprocess(mutations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import com.quran.shared.syncengine.conflict.ConflictResolutionResult
import com.quran.shared.syncengine.conflict.ConflictResolver
import com.quran.shared.syncengine.conflict.ResourceConflict
import com.quran.shared.syncengine.model.SyncBookmark
import com.quran.shared.syncengine.preprocessing.LocalMutationsPreprocessor
import com.quran.shared.syncengine.preprocessing.RemoteMutationsPreprocessor
import com.quran.shared.syncengine.preprocessing.BookmarksLocalMutationsPreprocessor
import com.quran.shared.syncengine.preprocessing.BookmarksRemoteMutationsPreprocessor

/**
* Pure business logic executor for bookmark synchronization operations.
Expand Down Expand Up @@ -103,15 +103,15 @@ class BookmarksSynchronizationExecutor {
private fun preprocessLocalMutations(
localMutations: List<LocalModelMutation<SyncBookmark>>
): List<LocalModelMutation<SyncBookmark>> {
val preprocessor = LocalMutationsPreprocessor()
val preprocessor = BookmarksLocalMutationsPreprocessor()
return preprocessor.preprocess(localMutations)
}

private suspend fun preprocessRemoteMutations(
remoteMutations: List<RemoteModelMutation<SyncBookmark>>,
checkLocalExistence: suspend (List<String>) -> Map<String, Boolean>
): List<RemoteModelMutation<SyncBookmark>> {
val preprocessor = RemoteMutationsPreprocessor(checkLocalExistence)
val preprocessor = BookmarksRemoteMutationsPreprocessor(checkLocalExistence)
return preprocessor.preprocess(remoteMutations)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ object SynchronizationClientBuilder {
notesConfigurations: NotesSynchronizationConfigurations? = null,
httpClient: HttpClient? = null
): SynchronizationClient {
val adapters = buildList<SyncResourceAdapter> {
val adapters = buildList {
add(BookmarksSyncAdapter(bookmarksConfigurations))
collectionsConfigurations?.let { add(CollectionsSyncAdapter(it)) }
collectionBookmarksConfigurations?.let { add(CollectionBookmarksSyncAdapter(it)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.quran.shared.syncengine.model.SyncBookmark
import com.quran.shared.syncengine.model.SyncBookmarkKey
import com.quran.shared.syncengine.model.conflictKey

class LocalMutationsPreprocessor {
class BookmarksLocalMutationsPreprocessor {

/**
* Preprocesses local mutations and throws an error if illogical scenarios are detected.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.quran.shared.mutations.Mutation
import com.quran.shared.mutations.RemoteModelMutation
import com.quran.shared.syncengine.model.SyncBookmark

class RemoteMutationsPreprocessor(
class BookmarksRemoteMutationsPreprocessor(
private val checkLocalExistence: suspend (List<String>) -> Map<String, Boolean>
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import kotlin.test.assertFailsWith
import kotlin.test.assertTrue
import kotlin.time.Instant

class LocalMutationsPreprocessorTest {
class BookmarksLocalMutationsPreprocessorTest {

private val preprocessor = LocalMutationsPreprocessor()
private val preprocessor = BookmarksLocalMutationsPreprocessor()

@Test
fun `should return empty list when no mutations provided`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import kotlin.test.assertEquals
import kotlin.test.assertTrue
import kotlin.time.Instant

class RemoteMutationsPreprocessorTest {
class BookmarksRemoteMutationsPreprocessorTest {

@Test
fun `test preprocess with empty mutations list`() = runTest {
// Arrange
val checkLocalExistence = createMockExistenceChecker(emptySet())
val preprocessor = RemoteMutationsPreprocessor(checkLocalExistence)
val preprocessor = BookmarksRemoteMutationsPreprocessor(checkLocalExistence)
val remoteMutations = emptyList<RemoteModelMutation<SyncBookmark>>()

// Act
Expand All @@ -31,7 +31,7 @@ class RemoteMutationsPreprocessorTest {
fun `test preprocess with only CREATED mutations`() = runTest {
// Arrange
val checkLocalExistence = createMockExistenceChecker(emptySet())
val preprocessor = RemoteMutationsPreprocessor(checkLocalExistence)
val preprocessor = BookmarksRemoteMutationsPreprocessor(checkLocalExistence)
val remoteMutations = listOf(
RemoteModelMutation<SyncBookmark>(
model = PageBookmark("new-1", 10, Instant.fromEpochMilliseconds(1000)),
Expand Down Expand Up @@ -59,7 +59,7 @@ class RemoteMutationsPreprocessorTest {
// Arrange
val existingRemoteIDs = setOf("existing-1")
val checkLocalExistence = createMockExistenceChecker(existingRemoteIDs)
val preprocessor = RemoteMutationsPreprocessor(checkLocalExistence)
val preprocessor = BookmarksRemoteMutationsPreprocessor(checkLocalExistence)
val remoteMutations = listOf(
RemoteModelMutation<SyncBookmark>(
model = PageBookmark("existing-1", 10, Instant.fromEpochMilliseconds(1000)),
Expand All @@ -86,7 +86,7 @@ class RemoteMutationsPreprocessorTest {
// Arrange
val existingRemoteIDs = setOf("existing-1")
val checkLocalExistence = createMockExistenceChecker(existingRemoteIDs)
val preprocessor = RemoteMutationsPreprocessor(checkLocalExistence)
val preprocessor = BookmarksRemoteMutationsPreprocessor(checkLocalExistence)
val remoteMutations = listOf(
RemoteModelMutation<SyncBookmark>(
model = PageBookmark("existing-1", 10, Instant.fromEpochMilliseconds(1000)),
Expand Down Expand Up @@ -118,7 +118,7 @@ class RemoteMutationsPreprocessorTest {
// Arrange
val existingRemoteIDs = setOf("existing-1", "existing-2")
val checkLocalExistence = createMockExistenceChecker(existingRemoteIDs)
val preprocessor = RemoteMutationsPreprocessor(checkLocalExistence)
val preprocessor = BookmarksRemoteMutationsPreprocessor(checkLocalExistence)
val remoteMutations = listOf(
RemoteModelMutation<SyncBookmark>(
model = PageBookmark("existing-1", 10, Instant.fromEpochMilliseconds(1000)),
Expand Down Expand Up @@ -150,7 +150,7 @@ class RemoteMutationsPreprocessorTest {
// Arrange
val existingRemoteIDs = setOf("existing-1")
val checkLocalExistence = createMockExistenceChecker(existingRemoteIDs)
val preprocessor = RemoteMutationsPreprocessor(checkLocalExistence)
val preprocessor = BookmarksRemoteMutationsPreprocessor(checkLocalExistence)
val remoteMutations = listOf(
RemoteModelMutation<SyncBookmark>(
model = PageBookmark("new-1", 10, Instant.fromEpochMilliseconds(1000)),
Expand Down Expand Up @@ -178,7 +178,7 @@ class RemoteMutationsPreprocessorTest {
// Arrange
val existingRemoteIDs = setOf("existing-1", "existing-2")
val checkLocalExistence = createMockExistenceChecker(existingRemoteIDs)
val preprocessor = RemoteMutationsPreprocessor(checkLocalExistence)
val preprocessor = BookmarksRemoteMutationsPreprocessor(checkLocalExistence)
val remoteMutations = listOf(
// CREATED mutations (should be kept)
RemoteModelMutation<SyncBookmark>(
Expand Down Expand Up @@ -236,7 +236,7 @@ class RemoteMutationsPreprocessorTest {
fun `test preprocess when local data fetcher returns empty existence map`() = runTest {
// Arrange
val checkLocalExistence = createMockExistenceChecker(emptySet())
val preprocessor = RemoteMutationsPreprocessor(checkLocalExistence)
val preprocessor = BookmarksRemoteMutationsPreprocessor(checkLocalExistence)
val remoteMutations = listOf(
RemoteModelMutation<SyncBookmark>(
model = PageBookmark("any-id", 10, Instant.fromEpochMilliseconds(1000)),
Expand Down Expand Up @@ -264,7 +264,7 @@ class RemoteMutationsPreprocessorTest {
// Arrange
val existingRemoteIDs = setOf("existing-1", "existing-2")
val checkLocalExistence = createMockExistenceChecker(existingRemoteIDs)
val preprocessor = RemoteMutationsPreprocessor(checkLocalExistence)
val preprocessor = BookmarksRemoteMutationsPreprocessor(checkLocalExistence)
val remoteMutations = listOf(
RemoteModelMutation<SyncBookmark>(
model = PageBookmark("existing-1", 10, Instant.fromEpochMilliseconds(1000)),
Expand Down Expand Up @@ -303,7 +303,7 @@ class RemoteMutationsPreprocessorTest {
// Arrange
val existingRemoteIDs = setOf("existing-1", "existing-3")
val checkLocalExistence = createMockExistenceChecker(existingRemoteIDs)
val preprocessor = RemoteMutationsPreprocessor(checkLocalExistence)
val preprocessor = BookmarksRemoteMutationsPreprocessor(checkLocalExistence)

// Create mutations in a specific order
val remoteMutations = listOf(
Expand Down