Skip to content

Commit

Permalink
Merge pull request #905 from eclipse-tractusx/fix/duplicate-output
Browse files Browse the repository at this point in the history
fix(gate): duplication of business partner output in rare circumstances
  • Loading branch information
nicoprow authored May 12, 2024
2 parents 50b1cd0 + f35112e commit 10e45c3
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 10e45c3

Please sign in to comment.