Skip to content

[MS-1087] Add dedicated CoSync model copies of exported classes#1586

Open
BurningAXE wants to merge 1 commit intomainfrom
cosync-polymorphic-versioning
Open

[MS-1087] Add dedicated CoSync model copies of exported classes#1586
BurningAXE wants to merge 1 commit intomainfrom
cosync-polymorphic-versioning

Conversation

@BurningAXE
Copy link
Contributor

@BurningAXE BurningAXE commented Feb 13, 2026

JIRA ticket
Will be released in: 2026.2.0
Design doc

Notable changes

  • Adds dedicated CoSync copies of exported domain models. This way if domain models evolve in a non-compatible way, we'll be forced to update the converters and thus handle compatibility with exported data
  • Exported events have a schemaVersion property starting with version 1.0 for the current state of affairs
  • Missing schemaVersion (for all data exported so far) will default to 1.0
  • Non-breaking changes (adding properties with default/nullable values) will bump the minor version
  • Breaking changes (removing or renaming properties, new fields with no default/non-optional values) will bump the major version. This will result in another set of classes (V2) and all version sets will need to convert to current domain models.

Testing guidance

  • Export data for CoSync and parse it back
  • Get data exported with a previous version and parse it with the new
  • Export data with the new version and parse it with an old version

Additional work checklist

  • Effect on other features and security has been considered
  • Design document marked as "In development" (if applicable)
  • External (Gitbook) and internal (Confluence) Documentation is up to date (or ticket created)
  • Test cases in Testiny are up to date (or ticket created)
  • Other teams notified about the changes (if applicable)

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a versioned, dedicated CoSync wire-format model for enrolment record “subject actions” JSON, decoupling CommCare/Client-API payloads from internal domain event models and adding schema version routing.

Changes:

  • Replace CoSyncEnrolmentRecordEvents from a simple @Serializable wrapper to a versioned sealed interface with a custom schemaVersion-based deserializer.
  • Add V1 CoSync model classes (+ mapping) for enrolment record creation events, tokenizable strings, biometric references/templates, and external credentials.
  • Update CommCare parsing call sites and the client-api subject-actions generator to use toDomainEvents() / V1 serialization.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
infra/events/src/main/java/com/simprints/infra/events/event/cosync/CoSyncEnrolmentRecordEvents.kt Introduces versioned CoSync events interface + schemaVersion-based polymorphic deserialization.
infra/events/src/main/java/com/simprints/infra/events/event/cosync/CoSyncEnrolmentRecordEventsV1.kt Adds V1 wrapper model with schemaVersion and domain mapping.
infra/events/src/main/java/com/simprints/infra/events/event/cosync/v1/EnrolmentRecordEventV1.kt Adds V1 event + payload schema and domain ↔ CoSync mappings.
infra/events/src/main/java/com/simprints/infra/events/event/cosync/v1/BiometricReferenceV1.kt Adds V1 biometric reference schemas and mappings.
infra/events/src/main/java/com/simprints/infra/events/event/cosync/v1/TemplateV1.kt Adds V1 face/fingerprint template schemas and mappings.
infra/events/src/main/java/com/simprints/infra/events/event/cosync/v1/SampleIdentifierV1.kt Adds V1 sample identifier enum and mappings to TemplateIdentifier.
infra/events/src/main/java/com/simprints/infra/events/event/cosync/v1/TokenizableStringV1.kt Adds V1 tokenizable-string schema + custom JSON serializer for backward compatibility.
infra/events/src/main/java/com/simprints/infra/events/event/cosync/v1/ExternalCredentialV1.kt Adds V1 external credential schema and mapping to domain.
infra/events/src/main/java/com/simprints/infra/events/event/cosync/v1/ExternalCredentialTypeV1.kt Adds V1 external credential type enum and mappings.
infra/events/src/test/java/com/simprints/infra/events/event/cosync/CoSyncEnrolmentRecordEventsVersioningTest.kt Adds tests for schemaVersion routing and round-trip serialization/deserialization.
infra/event-sync/src/main/java/com/simprints/infra/eventsync/event/commcare/CommCareEventDataSource.kt Updates CommCare parsing to use toDomainEvents() instead of .events.
infra/enrolment-records/repository/src/main/java/com/simprints/infra/enrolment/records/repository/commcare/CommCareCandidateRecordDataSource.kt Updates CommCare parsing to use toDomainEvents() instead of .events.
feature/client-api/src/main/java/com/simprints/feature/clientapi/usecases/GetEnrolmentCreationEventForRecordUseCase.kt Serializes subject-actions using CoSyncEnrolmentRecordEventsV1 and V1 mappings.

/**
* V1 external schema for tokenizable strings.
*
* Stable external contract decoupled from internal [TokenizableString].
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

The KDoc claims this is a “stable external contract decoupled from internal TokenizableString”, but the serialized discriminator values are still the internal strings (e.g. "TokenizableString.Tokenized"/"TokenizableString.Raw"). Either adjust the documentation to reflect that it intentionally mirrors the internal encoding for compatibility, or change the discriminator values to an explicitly external/stable set (e.g. "TOKENIZED"/"RAW").

Suggested change
* Stable external contract decoupled from internal [TokenizableString].
* Stable external contract for serializing tokenizable strings.
* Discriminator values intentionally mirror internal [TokenizableString] class names
* (e.g. "TokenizableString.Tokenized" / "TokenizableString.Raw") for backward compatibility.

Copilot uses AI. Check for mistakes.
@BurningAXE BurningAXE force-pushed the cosync-polymorphic-versioning branch from bdde12f to 6227aec Compare February 13, 2026 11:48
@BurningAXE BurningAXE requested review from a team, TristramN, alex-vt, alexandr-simprints, luhmirin-s, meladRaouf and ybourgery and removed request for a team February 13, 2026 12:24
@BurningAXE BurningAXE marked this pull request as ready for review February 13, 2026 14:58
@BurningAXE BurningAXE force-pushed the cosync-polymorphic-versioning branch from 6227aec to d9b9511 Compare February 13, 2026 16:03
@BurningAXE BurningAXE force-pushed the cosync-polymorphic-versioning branch from d9b9511 to 456f95b Compare February 16, 2026 17:29
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
59.6% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants