Skip to content

MS-448 Ad-hoc tokenisation improvements#1520

Merged
luhmirin-s merged 4 commits into
mainfrom
feature/MS-448-tokenisation-improvements
Jan 8, 2026
Merged

MS-448 Ad-hoc tokenisation improvements#1520
luhmirin-s merged 4 commits into
mainfrom
feature/MS-448-tokenisation-improvements

Conversation

@luhmirin-s
Copy link
Copy Markdown
Contributor

@luhmirin-s luhmirin-s commented Jan 6, 2026

JIRA ticket
Will be released in: 2026.1.0

Notable changes

  • Instead of attempting to tokenise the attendant ID and module ID on each config refresh, we can go with a more targeted approach in both use-cases:
    1. For freshly logged-in users (where the values in ActionRequest are not tokenised), we can do a double-check right before returning the action from LoginCheckViewModel and provide the updated value to the orchestrator. This means that values in the action request are processed untokenised at most during the intent parsing and login flow.
    2. For legacy versions, we add an update broadcast receiver (similar to the orchestration cache cleanup) that would trigger sync update and subsequent forced tokenisation if the state of tokenisation keys has changed (from non-existent to existent). As a bonus, this would force all other "new" features to work correctly sooner.

Testing guidance

  • Set up the project for the module scope in sync and identification. Enrol with a fresh install without any record syncs. Instantly, do an identification with the same biometrics.
  • Test case

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)

@cla-bot cla-bot Bot added the ... label Jan 6, 2026
realmToRoomMigrationScheduler.scheduleMigrationWorkerIfNeeded()

// Running tokenization after potential reset and room migration to avoid unnecessary work
enrolmentRecordRepository.tokenizeExistingRecords(project)
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.

Can we also have a flag in the receiver so this doesn't unnecessarily run in 99.9% of cases?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Passing the flag around is too much hustle with little ROI. I have added a check to only run the ad-hoc tokenisation when there were no keys before refresh. This should prevent extra queries at a cost of a single if. :)

try {
val query = EnrolmentRecordQuery(projectId = project.id, hasUntokenizedFields = true)
val tokenizedSubjectsCreateAction = selectEnrolmentRecordLocalDataSource()
val tokenizedRecordsCreateAction = selectEnrolmentRecordLocalDataSource()
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.

Shouldn't this be untokenizedRecordsCreateAction?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

By the end of the call chain the final value is indeed tokenized.

@luhmirin-s luhmirin-s force-pushed the feature/MS-448-tokenisation-improvements branch from b289c83 to bf1afa9 Compare January 7, 2026 10:19
@luhmirin-s
Copy link
Copy Markdown
Contributor Author

@BurningAXE I have reworked the approach after yesterday's conversation. This is an intervention on a similar scale to my previous approach, but it happens much sooner in the execution flow, so it should cover your concerns.

@luhmirin-s luhmirin-s marked this pull request as ready for review January 7, 2026 10:40
@luhmirin-s luhmirin-s requested review from a team, BurningAXE, TristramN, alex-vt, alexandr-simprints, meladRaouf and ybourgery and removed request for a team January 7, 2026 10:40
import com.simprints.infra.orchestration.data.ActionRequest
import javax.inject.Inject

class EnsureActionFieldsTokenisedUseCase @Inject constructor(
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.

nitpick: we use tokenized in other places so I suggest we keep it consistent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, I am always leaning towards "s" and have to continuously correct myself.

oldProject: Project?,
newProject: Project,
) {
if (oldProject?.tokenizationKeys?.isEmpty() == true && newProject.tokenizationKeys.isNotEmpty()) {
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.

Shouldn't this trigger also if oldProject?.tokenizationKeys are null?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm, technically, keys cannot be null, only the whole "oldProject". I will add an explicit check for that just in case.

import com.simprints.infra.enrolment.records.repository.EnrolmentRecordRepository
import javax.inject.Inject

class TokenizeRecordsIfProjectChangedUseCase @Inject constructor(
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.

nitpick: I found this name misleading - thought it meant one project changed to another. Maybe TokenizeRecordsIfKeysChangedUseCase?

ProjectState.PROJECT_PAUSED -> _showAlert.send(LoginCheckError.PROJECT_PAUSED)
ProjectState.PROJECT_ENDED -> startSignInAttempt(actionRequest)
ProjectState.RUNNING -> proceedWithAction(actionRequest)
ProjectState.RUNNING -> proceedWithAction(ensureActionFieldsTokenisedUseCase(actionRequest))
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.

Elegant!

Copy link
Copy Markdown
Contributor

@BurningAXE BurningAXE left a comment

Choose a reason for hiding this comment

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

Awesome!

@luhmirin-s luhmirin-s force-pushed the feature/MS-448-tokenisation-improvements branch from bf1afa9 to d2cd3e7 Compare January 7, 2026 15:53
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jan 7, 2026

@luhmirin-s luhmirin-s merged commit b95a4b0 into main Jan 8, 2026
13 checks passed
@luhmirin-s luhmirin-s deleted the feature/MS-448-tokenisation-improvements branch January 8, 2026 15:09
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