-
Notifications
You must be signed in to change notification settings - Fork 2
[MS-1087] Add dedicated CoSync model copies of exported classes #1586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,012
−137
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...ts/src/main/java/com/simprints/infra/events/event/cosync/CoSyncEnrolmentRecordEventsV1.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.simprints.infra.events.event.cosync | ||
|
|
||
| import androidx.annotation.Keep | ||
| import com.simprints.infra.events.event.cosync.v1.CoSyncEnrolmentRecordEvent | ||
| import com.simprints.infra.events.event.cosync.v1.toEventDomain | ||
| import com.simprints.infra.events.event.domain.models.EnrolmentRecordEvent | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| /** | ||
| * V1 schema for CoSync enrolment record events. | ||
| * | ||
| * Compatibility: | ||
| * - Old JSON without `schemaVersion` is deserialized as V1 (backward compatible). | ||
| * - Serialized JSON includes `schemaVersion = "1.0"` (forward compatible). | ||
| */ | ||
| @Keep | ||
| @Serializable | ||
| data class CoSyncEnrolmentRecordEventsV1( | ||
| override val schemaVersion: String = SCHEMA_VERSION, | ||
| val events: List<CoSyncEnrolmentRecordEvent>, | ||
| ) : CoSyncEnrolmentRecordEvents { | ||
|
|
||
| override fun toDomainEvents(): List<EnrolmentRecordEvent> = events.map { it.toEventDomain() } | ||
|
|
||
| companion object { | ||
| const val SCHEMA_VERSION = "1.0" | ||
| } | ||
| } |
77 changes: 77 additions & 0 deletions
77
...ents/src/main/java/com/simprints/infra/events/event/cosync/v1/CoSyncBiometricReference.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package com.simprints.infra.events.event.cosync.v1 | ||
|
|
||
| import androidx.annotation.Keep | ||
| import com.simprints.infra.events.event.domain.models.BiometricReference | ||
| import com.simprints.infra.events.event.domain.models.FaceReference | ||
| import com.simprints.infra.events.event.domain.models.FingerprintReference | ||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| /** | ||
| * V1 external schema for biometric references (polymorphic base type). | ||
| * Stable external contract decoupled from internal [BiometricReference]. | ||
| */ | ||
| @Keep | ||
| @Serializable | ||
| sealed class CoSyncBiometricReference { | ||
| abstract val id: String | ||
| abstract val format: String | ||
| } | ||
|
|
||
| @Keep | ||
| @Serializable | ||
| @SerialName("FACE_REFERENCE") | ||
| data class CoSyncFaceReference( | ||
| override val id: String, | ||
| val templates: List<CoSyncFaceTemplate>, | ||
| override val format: String, | ||
| val metadata: Map<String, String>? = null, | ||
| ) : CoSyncBiometricReference() | ||
|
|
||
| @Keep | ||
| @Serializable | ||
| @SerialName("FINGERPRINT_REFERENCE") | ||
| data class CoSyncFingerprintReference( | ||
| override val id: String, | ||
| val templates: List<CoSyncFingerprintTemplate>, | ||
| override val format: String, | ||
| val metadata: Map<String, String>? = null, | ||
| ) : CoSyncBiometricReference() | ||
|
|
||
| fun BiometricReference.toCoSync(): CoSyncBiometricReference = when (this) { | ||
| is FaceReference -> toCoSync() | ||
| is FingerprintReference -> toCoSync() | ||
| } | ||
|
|
||
| fun CoSyncBiometricReference.toEventDomain(): BiometricReference = when (this) { | ||
| is CoSyncFaceReference -> toEventDomain() | ||
| is CoSyncFingerprintReference -> toEventDomain() | ||
| } | ||
|
|
||
| fun FaceReference.toCoSync() = CoSyncFaceReference( | ||
| id = id, | ||
| templates = templates.map { it.toCoSync() }, | ||
| format = format, | ||
| metadata = metadata, | ||
| ) | ||
|
|
||
| fun CoSyncFaceReference.toEventDomain() = FaceReference( | ||
| id = id, | ||
| templates = templates.map { it.toEventDomain() }, | ||
| format = format, | ||
| metadata = metadata, | ||
| ) | ||
|
|
||
| fun FingerprintReference.toCoSync() = CoSyncFingerprintReference( | ||
| id = id, | ||
| templates = templates.map { it.toCoSync() }, | ||
| format = format, | ||
| metadata = metadata, | ||
| ) | ||
|
|
||
| fun CoSyncFingerprintReference.toEventDomain() = FingerprintReference( | ||
| id = id, | ||
| templates = templates.map { it.toEventDomain() }, | ||
| format = format, | ||
| metadata = metadata, | ||
| ) |
72 changes: 72 additions & 0 deletions
72
...ts/src/main/java/com/simprints/infra/events/event/cosync/v1/CoSyncEnrolmentRecordEvent.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package com.simprints.infra.events.event.cosync.v1 | ||
|
|
||
| import androidx.annotation.Keep | ||
| import com.simprints.infra.events.event.domain.models.EnrolmentRecordCreationEvent | ||
| import com.simprints.infra.events.event.domain.models.EnrolmentRecordEvent | ||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| /** | ||
| * V1 external schema for enrolment record events (polymorphic base type). | ||
| * Stable external contract decoupled from internal [EnrolmentRecordEvent]. | ||
| */ | ||
| @Keep | ||
| @Serializable | ||
| sealed class CoSyncEnrolmentRecordEvent { | ||
| abstract val id: String | ||
| } | ||
|
|
||
| /** | ||
| * V1 external schema for enrolment record creation event. | ||
| */ | ||
| @Keep | ||
| @Serializable | ||
| @SerialName("EnrolmentRecordCreation") | ||
| data class CoSyncEnrolmentRecordCreationEvent( | ||
| override val id: String, | ||
| val payload: CoSyncEnrolmentRecordCreationPayload, | ||
| ) : CoSyncEnrolmentRecordEvent() | ||
|
|
||
| @Keep | ||
| @Serializable | ||
| data class CoSyncEnrolmentRecordCreationPayload( | ||
| val subjectId: String, | ||
| val projectId: String, | ||
| val moduleId: CoSyncTokenizableString, | ||
| val attendantId: CoSyncTokenizableString, | ||
| val biometricReferences: List<CoSyncBiometricReference> = emptyList(), | ||
| val externalCredentials: List<CoSyncExternalCredential> = emptyList(), | ||
| ) | ||
|
|
||
| fun EnrolmentRecordEvent.toCoSync(): CoSyncEnrolmentRecordEvent = when (this) { | ||
| is EnrolmentRecordCreationEvent -> toCoSync() | ||
| else -> throw IllegalArgumentException("Unsupported event type for V1: ${this::class.simpleName}") | ||
| } | ||
|
|
||
| fun CoSyncEnrolmentRecordEvent.toEventDomain(): EnrolmentRecordEvent = when (this) { | ||
| is CoSyncEnrolmentRecordCreationEvent -> toEventDomain() | ||
| } | ||
|
|
||
| fun EnrolmentRecordCreationEvent.toCoSync() = CoSyncEnrolmentRecordCreationEvent( | ||
| id = id, | ||
| payload = CoSyncEnrolmentRecordCreationPayload( | ||
| subjectId = payload.subjectId, | ||
| projectId = payload.projectId, | ||
| moduleId = payload.moduleId.toCoSync(), | ||
| attendantId = payload.attendantId.toCoSync(), | ||
| biometricReferences = payload.biometricReferences.map { it.toCoSync() }, | ||
| externalCredentials = payload.externalCredentials.map { it.toCoSync() }, | ||
| ), | ||
| ) | ||
|
|
||
| fun CoSyncEnrolmentRecordCreationEvent.toEventDomain() = EnrolmentRecordCreationEvent( | ||
| id = id, | ||
| payload = EnrolmentRecordCreationEvent.EnrolmentRecordCreationPayload( | ||
| subjectId = payload.subjectId, | ||
| projectId = payload.projectId, | ||
| moduleId = payload.moduleId.toDomain(), | ||
| attendantId = payload.attendantId.toDomain(), | ||
| biometricReferences = payload.biometricReferences.map { it.toEventDomain() }, | ||
| externalCredentials = payload.externalCredentials.map { it.toDomain() }, | ||
| ), | ||
| ) |
36 changes: 36 additions & 0 deletions
36
...ents/src/main/java/com/simprints/infra/events/event/cosync/v1/CoSyncExternalCredential.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package com.simprints.infra.events.event.cosync.v1 | ||
|
|
||
| import androidx.annotation.Keep | ||
| import com.simprints.core.domain.externalcredential.ExternalCredential | ||
| import com.simprints.core.domain.tokenization.TokenizableString | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| /** | ||
| * V1 external schema for external credentials. | ||
| * Stable external contract decoupled from internal [ExternalCredential]. | ||
| */ | ||
| @Keep | ||
| @Serializable | ||
| data class CoSyncExternalCredential( | ||
| val id: String, | ||
| val value: CoSyncTokenizableString, | ||
| val subjectId: String, | ||
| val type: CoSyncExternalCredentialType, | ||
| ) | ||
|
|
||
| fun ExternalCredential.toCoSync() = CoSyncExternalCredential( | ||
| id = id, | ||
| value = value.toCoSync(), | ||
| subjectId = subjectId, | ||
| type = type.toCoSync(), | ||
| ) | ||
|
|
||
| fun CoSyncExternalCredential.toDomain() = ExternalCredential( | ||
| id = id, | ||
| value = when (val domainValue = value.toDomain()) { | ||
| is TokenizableString.Tokenized -> domainValue | ||
| is TokenizableString.Raw -> error("ExternalCredential value must be Tokenized, got Raw for id=$id") | ||
| }, | ||
| subjectId = subjectId, | ||
| type = type.toDomain(), | ||
| ) |
31 changes: 31 additions & 0 deletions
31
.../src/main/java/com/simprints/infra/events/event/cosync/v1/CoSyncExternalCredentialType.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package com.simprints.infra.events.event.cosync.v1 | ||
|
|
||
| import androidx.annotation.Keep | ||
| import com.simprints.core.ExcludedFromGeneratedTestCoverageReports | ||
| import com.simprints.core.domain.externalcredential.ExternalCredentialType | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| /** | ||
| * V1 external schema for external credential types. | ||
| * Stable external contract decoupled from internal [ExternalCredentialType]. | ||
| */ | ||
| @Keep | ||
| @Serializable | ||
| @ExcludedFromGeneratedTestCoverageReports("Enum") | ||
| enum class CoSyncExternalCredentialType { | ||
| NHISCard, | ||
| GhanaIdCard, | ||
| QRCode, | ||
| } | ||
|
|
||
| fun ExternalCredentialType.toCoSync(): CoSyncExternalCredentialType = when (this) { | ||
| ExternalCredentialType.NHISCard -> CoSyncExternalCredentialType.NHISCard | ||
| ExternalCredentialType.GhanaIdCard -> CoSyncExternalCredentialType.GhanaIdCard | ||
| ExternalCredentialType.QRCode -> CoSyncExternalCredentialType.QRCode | ||
| } | ||
|
|
||
| fun CoSyncExternalCredentialType.toDomain(): ExternalCredentialType = when (this) { | ||
| CoSyncExternalCredentialType.NHISCard -> ExternalCredentialType.NHISCard | ||
| CoSyncExternalCredentialType.GhanaIdCard -> ExternalCredentialType.GhanaIdCard | ||
| CoSyncExternalCredentialType.QRCode -> ExternalCredentialType.QRCode | ||
| } |
32 changes: 32 additions & 0 deletions
32
infra/events/src/main/java/com/simprints/infra/events/event/cosync/v1/CoSyncTemplate.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package com.simprints.infra.events.event.cosync.v1 | ||
|
|
||
| import androidx.annotation.Keep | ||
| import com.simprints.infra.events.event.domain.models.FaceTemplate | ||
| import com.simprints.infra.events.event.domain.models.FingerprintTemplate | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| /** V1 external schema for face template. */ | ||
| @Keep | ||
| @Serializable | ||
| data class CoSyncFaceTemplate(val template: String) | ||
|
|
||
| /** V1 external schema for fingerprint template with finger identifier. */ | ||
| @Keep | ||
| @Serializable | ||
| data class CoSyncFingerprintTemplate( | ||
| val template: String, | ||
| val finger: CoSyncTemplateIdentifier, | ||
| ) | ||
|
|
||
| fun FaceTemplate.toCoSync() = CoSyncFaceTemplate(template = template) | ||
| fun CoSyncFaceTemplate.toEventDomain() = FaceTemplate(template = template) | ||
|
|
||
| fun FingerprintTemplate.toCoSync() = CoSyncFingerprintTemplate( | ||
| template = template, | ||
| finger = finger.toCoSync(), | ||
| ) | ||
|
|
||
| fun CoSyncFingerprintTemplate.toEventDomain() = FingerprintTemplate( | ||
| template = template, | ||
| finger = finger.toDomain(), | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.