Skip to content

Commit

Permalink
fix(Cleaning Dummy): duplication check not distinguishing very well b…
Browse files Browse the repository at this point in the history
…etween sites and addresses of the same legal entity

- introduce more precise BPN references to better distinguish between differen business partner names
- take the uncategorized name parts into account if no categorized business partner name is specified
  • Loading branch information
nicoprow committed Aug 23, 2024
1 parent 25e4c9c commit 6949265
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ For changes to the BPDM Helm charts please consult the [changelog](charts/bpdm/C
- BPDM Pool & Gate: Reduce standard batch size for golden record task processing ([#1032](https://github.com/eclipse-tractusx/bpdm/pull/1032))

- BPDM Orchestrator: Fix possible out-of-memory exception during the execution of large volumes of tasks ([#1029](https://github.com/eclipse-tractusx/bpdm/pull/1029))
- BPDM Cleaning Service Dummy: Improve duplication check to better distinguish between incoming business partners

## [6.1.0] - [2024-07-15]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Service
import java.time.Instant
import java.time.temporal.ChronoUnit
import java.util.*

@Service
class CleaningServiceDummy(
Expand Down Expand Up @@ -101,16 +102,19 @@ class CleaningServiceDummy(
?: businessPartner.additionalAddress
?: PostalAddress.empty

val legalAddressBpnReference = addressToClean.bpnReference
.toRequestIfNotBpn(businessPartner.legalEntityReference(), businessPartner.siteReference(), businessPartner.legalAddressReference())

return with(businessPartner.legalEntity){
copy(
bpnReference = bpnReference.toRequestIfNotBpn(businessPartner.createLegalEntityReferenceValue()),
bpnReference = bpnReference.toRequestIfNotBpn(businessPartner.legalEntityReference()),
legalName = legalName ?: businessPartner.uncategorized.nameParts.joinToString(""),
identifiers = identifiers.takeIf { it.isNotEmpty() } ?: businessPartner.uncategorized.identifiers,
states = states.takeIf { it.isNotEmpty() } ?: businessPartner.uncategorized.states,
confidenceCriteria = dummyConfidenceCriteria.copy(sharedByOwner = sharedByOwner),
hasChanged = businessPartner.type == GoldenRecordType.LegalEntity,
isCatenaXMemberData = sharedByOwner,
legalAddress = cleanAddress(addressToClean, businessPartner.createLegalAddressReferenceValue(), true, sharedByOwner),
legalAddress = cleanAddress(addressToClean, legalAddressBpnReference, true, sharedByOwner),
)
}
}
Expand All @@ -127,12 +131,15 @@ class CleaningServiceDummy(
?: PostalAddress.empty
}

val siteMainBpnReference = addressToClean?.bpnReference
?.toRequestIfNotBpn(businessPartner.legalAddressReference(), businessPartner.siteReference(), businessPartner.siteMainAddressReference())

with(site){
copy(
bpnReference = bpnReference.toRequestIfNotBpn(businessPartner.createSiteReferenceValue()),
bpnReference = bpnReference.toRequestIfNotBpn(businessPartner.legalEntityReference(), businessPartner.siteReference()),
confidenceCriteria = dummyConfidenceCriteria.copy(sharedByOwner = sharedByOwner),
hasChanged = businessPartner.type == GoldenRecordType.Site,
siteMainAddress = addressToClean?.let { cleanAddress(addressToClean, businessPartner.createSiteMainAddressReferenceValue(), true, sharedByOwner) }
siteMainAddress = addressToClean?.let { cleanAddress(addressToClean, siteMainBpnReference!!, true, sharedByOwner) }
)
}
}
Expand All @@ -142,46 +149,48 @@ class CleaningServiceDummy(
return businessPartner.additionalAddress?.let {
cleanAddress(
it,
businessPartner.createAdditionalAddressReferenceValue(),
it.bpnReference.toRequestIfNotBpn(businessPartner.legalEntityReference(), businessPartner.siteReference(), businessPartner.addressReference()),
businessPartner.type == GoldenRecordType.Address,
sharedByOwner
)
}
}


private fun cleanAddress(addressToClean: PostalAddress, requestId: String, hasChanged: Boolean, sharedByOwner: Boolean): PostalAddress {
private fun cleanAddress(addressToClean: PostalAddress, bpnReference: BpnReference, hasChanged: Boolean, sharedByOwner: Boolean): PostalAddress {
return addressToClean.copy(
bpnReference = addressToClean.bpnReference.toRequestIfNotBpn(requestId),
bpnReference = bpnReference,
hasChanged = hasChanged,
confidenceCriteria = dummyConfidenceCriteria.copy(sharedByOwner = sharedByOwner)
)
}

private fun BusinessPartner.createLegalEntityReferenceValue() =
"LEGAL_ENTITY" + (legalEntity.legalName ?: nameParts.joinToString(" "))
private fun BusinessPartner.legalEntityReference() =
"LEGAL_ENTITY${legalEntity.legalName ?: namePartsName()}".toUUID()

private fun BusinessPartner.siteReference() = "S_${site?.siteName ?: namePartsName()}".toUUID()

private fun BusinessPartner.createSiteReferenceValue() =
"SITE" + createLegalEntityReferenceValue() + (site?.siteName ?: "")
private fun BusinessPartner.addressReference() = "A_${additionalAddress?.addressName ?: namePartsName()}".toUUID()

private fun BusinessPartner.createSiteMainAddressReferenceValue() =
"SITE_MAIN_ADDRESS" + createSiteReferenceValue()
private fun BusinessPartner.namePartsName() = uncategorized.nameParts.joinToString(" ")

private fun BusinessPartner.createLegalAddressReferenceValue() =
"LEGAL_ADDRESS" + createLegalEntityReferenceValue()
private fun BusinessPartner.legalAddressReference() = "LEGAL_ADDRESS".toUUID()

private fun BusinessPartner.siteMainAddressReference() = "SITE_MAIN_ADDRESS".toUUID()

private fun BusinessPartner.createAdditionalAddressReferenceValue() =
"ADDITIONAL_ADDRESS" + (additionalAddress?.addressName ?: "") + createSiteReferenceValue()

private fun generateBpnRequestIdentifier(fromString: String) =
BpnReference(fromString.toUUID().toString(), null, BpnReferenceType.BpnRequestIdentifier)
private fun generateBpnRequestIdentifier(legalEntityReference: UUID, siteReference: UUID? = null, addressReference: UUID? = null): BpnReference{
val siteReferenceString = siteReference?.let { "${siteReference}_" } ?: ""
val addressReferenceString = addressReference?.let { "${addressReference}_" } ?: ""
return BpnReference( addressReferenceString + siteReferenceString + legalEntityReference.toString(), null, BpnReferenceType.BpnRequestIdentifier)
}



private fun BpnReference.toRequestIfNotBpn(requestId: String) =
private fun BpnReference.toRequestIfNotBpn(legalEntityReference: UUID, siteReference: UUID? = null, additionalAddressReference: UUID? = null) =
if(referenceType == BpnReferenceType.Bpn)
this
else
generateBpnRequestIdentifier(requestId)
generateBpnRequestIdentifier(legalEntityReference, siteReference, additionalAddressReference)

}

0 comments on commit 6949265

Please sign in to comment.