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 @@ -169,26 +169,45 @@ internal class CommCareIdentityDataSource @Inject constructor(
coSyncEnrolmentRecordEvents
?.events
?.filterIsInstance<EnrolmentRecordCreationEvent>()
?.filterNot { event ->
?.filter { event ->
// [MS-852] Plain strings from CommCare might be tokenized or untokenized. The only way to properly compare them
// is by trying to decrypt the values to check if already tokenized, and then compare the values
(query.subjectId != null && query.subjectId != event.payload.subjectId) ||
!compareImplicitTokenizedStringsUseCase(
query.attendantId,
event.payload.attendantId,
TokenKeyType.AttendantId,
project,
) ||
!compareImplicitTokenizedStringsUseCase(
query.moduleId,
event.payload.moduleId,
TokenKeyType.ModuleId,
project,
)
isSubjectIdNullOrMatching(query, event) &&
isAttendantIdNullOrMatching(query, event, project) &&
isModuleIdNullOrMatching(query, event, project)
}
}.orEmpty()
}

private fun isSubjectIdNullOrMatching(
query: SubjectQuery,
event: EnrolmentRecordCreationEvent,
): Boolean = query.subjectId == null || query.subjectId == event.payload.subjectId

private fun isAttendantIdNullOrMatching(
query: SubjectQuery,
event: EnrolmentRecordCreationEvent,
project: Project,
): Boolean = query.attendantId == null ||
compareImplicitTokenizedStringsUseCase(
query.attendantId,
event.payload.attendantId,
TokenKeyType.AttendantId,
project,
)

private fun isModuleIdNullOrMatching(
query: SubjectQuery,
event: EnrolmentRecordCreationEvent,
project: Project,
): Boolean = query.moduleId == null ||
compareImplicitTokenizedStringsUseCase(
query.moduleId,
event.payload.moduleId,
TokenKeyType.ModuleId,
project,
)

private fun getSubjectActionsValue(caseDataCursor: Cursor): String {
while (caseDataCursor.moveToNext()) {
val key = caseDataCursor.getString(caseDataCursor.getColumnIndexOrThrow(COLUMN_DATUM_ID))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.simprints.core.domain.face.FaceSample
import com.simprints.core.domain.fingerprint.FingerprintSample
import com.simprints.core.domain.fingerprint.IFingerIdentifier.LEFT_INDEX_FINGER
import com.simprints.core.domain.fingerprint.IFingerIdentifier.LEFT_THUMB
import com.simprints.core.domain.tokenization.TokenizableString
import com.simprints.core.tools.json.JsonHelper
import com.simprints.core.tools.utils.EncodingUtils
import com.simprints.infra.config.store.models.Project
Expand Down Expand Up @@ -259,7 +260,14 @@ class CommCareIdentityDataSourceTest {
SUBJECT_ACTIONS_FACE_2,
)
val templateFormat = "ROC_1_23"
val query = SubjectQuery(faceSampleFormat = templateFormat)
val query = SubjectQuery(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the tests failing with the old implementation now?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No Tests were OK.
I just added more parameters to one of the queries so that the tests covers all the flows in the filtering method

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is if they didn't catch the bug maybe they weren't :D

faceSampleFormat = templateFormat,
attendantId = TokenizableString.Tokenized(
value = "AdySMrjuy7uq0Dcxov3rUFIw66uXTFrKd0BnzSr9MYXl5maWEpyKQT8AUdcPuVHUWpOkO88=",
),
moduleId = TokenizableString.Tokenized(value = "AWuA3H0WGtHI2uod+ePZ3yiWTt9etQ=="),
subjectId = "b26c91bc-b307-4131-80c3-55090ba5dbf2",
)
val range = 0..expectedFaceIdentities.size
val actualIdentities = dataSource.loadFaceIdentities(query, range, project = project) {}

Expand Down