-
Notifications
You must be signed in to change notification settings - Fork 1
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
SDIT-2021 Cater for retries to the mapping creation by performing an upsert #369
Conversation
@PutMapping("/migration") | ||
@Operation( | ||
summary = "Creates or updates a prison person migration mapping", | ||
description = "Creates or updates a mapping between nomis prisoner numbers and prison person history ids. Requires ROLE_NOMIS_PRISONPERSON", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When testing we found that sometimes a prisoner migration is retried despite all records being created in DPS and the mapping service. As DPS is idempotent and just overwrites the previous migration we need the same behaviour in the mapping service, hence switching to a PUT.
private suspend fun PrisonPersonMigrationMappingRequest.update(): PrisonPersonMigrationMapping = | ||
template.update<PrisonPersonMigrationMapping>() | ||
.inTable("prison_person_migration_mapping") | ||
.matching( | ||
query( | ||
where("nomis_prisoner_number").`is`(nomisPrisonerNumber) | ||
.and(where("migration_type").`is`(migrationType)) | ||
.and(where("label").`is`(label)), | ||
), | ||
) | ||
.apply(update("dps_ids", dpsIds.toString())) | ||
.awaitSingle() | ||
.let { find()!! } | ||
|
||
private suspend fun PrisonPersonMigrationMappingRequest.insert(): PrisonPersonMigrationMapping = | ||
template.insert<PrisonPersonMigrationMapping>() | ||
.using( | ||
PrisonPersonMigrationMapping( | ||
nomisPrisonerNumber = nomisPrisonerNumber, | ||
migrationType = migrationType, | ||
dpsIds = dpsIds.toString(), | ||
label = label, | ||
), | ||
) | ||
.awaitSingle() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spring data R2DBC still doesn't support composite entity keys so we needed another way. I thought I'd try out the template instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.