Skip to content

Commit

Permalink
fix(gate): duplication of business partner output in rare circumstances
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoprow committed May 12, 2024
1 parent 50b1cd0 commit f35112e
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class BusinessPartnerService(

fun upsertBusinessPartnersOutputFromCandidates(entityCandidates: List<BusinessPartnerDb>, ownerBpnl: String?): List<BusinessPartnerDb> {
logger.debug { "Upsert output from candidates $entityCandidates" }
return OwnerContext(ownerBpnl).upsertBusinessPartnersOutputFromCandidates(entityCandidates)
val candidateSet = entityCandidates.groupBy { it.externalId }.map { group -> group.value.last() }
return OwnerContext(ownerBpnl).upsertBusinessPartnersOutputFromCandidates(candidateSet)
}

inner class OwnerContext(
Expand Down Expand Up @@ -154,7 +155,7 @@ class BusinessPartnerService(
}

private fun assertInputStageExists(externalIds: Collection<String>) {
val existingExternalIds = businessPartnerRepository.findByStageAndExternalIdIn(StageType.Input, externalIds)
val existingExternalIds = businessPartnerRepository.findByStageAndAssociatedOwnerBpnlAndExternalIdIn(StageType.Input, ownerBpnl, externalIds, Pageable.unpaged())
.map { it.externalId }
.toSet()

Expand Down

0 comments on commit f35112e

Please sign in to comment.