Skip to content

Commit

Permalink
Merge pull request #910 from eclipse-tractusx/fix/dummy-cx-member
Browse files Browse the repository at this point in the history
fix(Dummy): not setting isCxMemberData to true for owned records
  • Loading branch information
nicoprow authored May 14, 2024
2 parents 0e8f3a8 + d5c0f77 commit 46b4f66
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,21 @@ class CleaningServiceDummy(

fun processCleaningTask(reservedTask: TaskStepReservationEntryDto): TaskStepResultEntryDto {
val businessPartner = reservedTask.businessPartner
val sharedByOwner = businessPartner.owningCompany?.isNotBlank() ?: false

val cleanedBusinessPartner = BusinessPartner(
nameParts = businessPartner.nameParts,
uncategorized = businessPartner.uncategorized,
owningCompany = businessPartner.owningCompany,
legalEntity = cleanLegalEntity(businessPartner),
site = cleanSite(businessPartner),
additionalAddress = cleanAdditionalAddress(businessPartner)
legalEntity = cleanLegalEntity(businessPartner, sharedByOwner),
site = cleanSite(businessPartner, sharedByOwner),
additionalAddress = cleanAdditionalAddress(businessPartner, sharedByOwner)
)

return TaskStepResultEntryDto(reservedTask.taskId, cleanedBusinessPartner)
}

private fun cleanLegalEntity(businessPartner: BusinessPartner): LegalEntity {
private fun cleanLegalEntity(businessPartner: BusinessPartner, sharedByOwner: Boolean): LegalEntity {
val addressToClean = businessPartner.legalEntity.legalAddress.takeIf { it != PostalAddress.empty }
?: businessPartner.uncategorized.address
?: businessPartner.site?.siteMainAddress
Expand All @@ -106,14 +107,15 @@ class CleaningServiceDummy(
legalName = legalName ?: businessPartner.uncategorized.nameParts.joinToString(""),
identifiers = identifiers.takeIf { it.isNotEmpty() } ?: businessPartner.uncategorized.identifiers,
states = states.takeIf { it.isNotEmpty() } ?: businessPartner.uncategorized.states,
confidenceCriteria = dummyConfidenceCriteria,
confidenceCriteria = dummyConfidenceCriteria.copy(sharedByOwner = sharedByOwner),
hasChanged = businessPartner.type == GoldenRecordType.LegalEntity,
legalAddress = cleanAddress(addressToClean, businessPartner.createLegalAddressReferenceValue(), true),
isCatenaXMemberData = sharedByOwner,
legalAddress = cleanAddress(addressToClean, businessPartner.createLegalAddressReferenceValue(), true, sharedByOwner),
)
}
}

private fun cleanSite(businessPartner: BusinessPartner): Site?{
private fun cleanSite(businessPartner: BusinessPartner, sharedByOwner: Boolean): Site?{
return businessPartner.site?.let { site ->

val addressToClean = if(site.siteMainIsLegalAddress){
Expand All @@ -128,29 +130,31 @@ class CleaningServiceDummy(
with(site){
copy(
bpnReference = bpnReference.toRequestIfNotBpn(businessPartner.createSiteReferenceValue()),
confidenceCriteria = dummyConfidenceCriteria,
confidenceCriteria = dummyConfidenceCriteria.copy(sharedByOwner = sharedByOwner),
hasChanged = businessPartner.type == GoldenRecordType.Site,
siteMainAddress = addressToClean?.let { cleanAddress(addressToClean, businessPartner.createSiteMainAddressReferenceValue(), true) }
siteMainAddress = addressToClean?.let { cleanAddress(addressToClean, businessPartner.createSiteMainAddressReferenceValue(), true, sharedByOwner) }
)
}
}
}

private fun cleanAdditionalAddress(businessPartner: BusinessPartner): PostalAddress? {
private fun cleanAdditionalAddress(businessPartner: BusinessPartner, sharedByOwner: Boolean): PostalAddress? {
return businessPartner.additionalAddress?.let {
cleanAddress(
it,
businessPartner.createAdditionalAddressReferenceValue(),
businessPartner.type == GoldenRecordType.Address)
businessPartner.type == GoldenRecordType.Address,
sharedByOwner
)
}
}


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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class CleaningServiceApiCallsTest @Autowired constructor(
val fixedTaskId = "1"
val businessPartnerFactory = BusinessPartnerTestDataFactory()
val defaultBpnRequest = BpnReference("IGNORED", null, BpnReferenceType.BpnRequestIdentifier)
val expectedConfidenceCriteria = cleaningServiceDummy.dummyConfidenceCriteria.copy(sharedByOwner = true)

@BeforeEach
fun beforeEach() {
Expand All @@ -97,8 +98,9 @@ class CleaningServiceApiCallsTest @Autowired constructor(
.copyWithBpnReferences(defaultBpnRequest)
.copyWithLegalAddress(mockedBusinessPartner.uncategorized.address!!)
.copyWithSiteMainAddress(mockedBusinessPartner.uncategorized.address!!)
.copyWithConfidenceCriteria(cleaningServiceDummy.dummyConfidenceCriteria)
.copyWithConfidenceCriteria(expectedConfidenceCriteria)
.copyWithHasChanged(false, false, true)
.copyAsCxMemberData()
)

// Call the method under test
Expand All @@ -123,8 +125,9 @@ class CleaningServiceApiCallsTest @Autowired constructor(
mockedBusinessPartner
.copyWithLegalAddress(mockedBusinessPartner.uncategorized.address!!)
.copyWithSiteMainAddress(mockedBusinessPartner.uncategorized.address!!)
.copyWithConfidenceCriteria(cleaningServiceDummy.dummyConfidenceCriteria)
.copyWithConfidenceCriteria(expectedConfidenceCriteria)
.copyWithHasChanged(false, false, true)
.copyAsCxMemberData()
)

// Call the method under test
Expand All @@ -150,8 +153,9 @@ class CleaningServiceApiCallsTest @Autowired constructor(
mockedBusinessPartner
.copyWithBpnReferences(defaultBpnRequest)
.copyWithLegalAddress(mockedBusinessPartner.uncategorized.address!!)
.copyWithConfidenceCriteria(cleaningServiceDummy.dummyConfidenceCriteria)
.copyWithConfidenceCriteria(expectedConfidenceCriteria)
.copyWithHasChanged(false, false, true)
.copyAsCxMemberData()
)

// Call the method under test
Expand All @@ -175,8 +179,9 @@ class CleaningServiceApiCallsTest @Autowired constructor(
val expectedResponse = createResultRequest(
mockedBusinessPartner
.copyWithLegalAddress(mockedBusinessPartner.uncategorized.address!!)
.copyWithConfidenceCriteria(cleaningServiceDummy.dummyConfidenceCriteria)
.copyWithConfidenceCriteria(expectedConfidenceCriteria)
.copyWithHasChanged(false, false, true)
.copyAsCxMemberData()
)

// Call the method under test
Expand All @@ -202,8 +207,9 @@ class CleaningServiceApiCallsTest @Autowired constructor(
mockedBusinessPartner
.copyWithBpnReferences(defaultBpnRequest)
.copyWithLegalAddress(mockedBusinessPartner.uncategorized.address!!)
.copyWithConfidenceCriteria(cleaningServiceDummy.dummyConfidenceCriteria)
.copyWithConfidenceCriteria(expectedConfidenceCriteria)
.copyWithHasChanged(false, true, false)
.copyAsCxMemberData()
)

// Call the method under test
Expand All @@ -227,8 +233,9 @@ class CleaningServiceApiCallsTest @Autowired constructor(
val expectedResponse = createResultRequest(
mockedBusinessPartner
.copyWithLegalAddress(mockedBusinessPartner.uncategorized.address!!)
.copyWithConfidenceCriteria(cleaningServiceDummy.dummyConfidenceCriteria)
.copyWithConfidenceCriteria(expectedConfidenceCriteria)
.copyWithHasChanged(false, true, false)
.copyAsCxMemberData()
)

// Call the method under test
Expand All @@ -253,8 +260,9 @@ class CleaningServiceApiCallsTest @Autowired constructor(
val expectedResponse = createResultRequest(
mockedBusinessPartner
.copyWithBpnReferences(defaultBpnRequest)
.copyWithConfidenceCriteria(cleaningServiceDummy.dummyConfidenceCriteria)
.copyWithConfidenceCriteria(expectedConfidenceCriteria)
.copyWithHasChanged(false, true, false)
.copyAsCxMemberData()
)

// Call the method under test
Expand All @@ -277,8 +285,9 @@ class CleaningServiceApiCallsTest @Autowired constructor(
//Create expectations
val expectedResponse = createResultRequest(
mockedBusinessPartner
.copyWithConfidenceCriteria(cleaningServiceDummy.dummyConfidenceCriteria)
.copyWithConfidenceCriteria(expectedConfidenceCriteria)
.copyWithHasChanged(false, true, false)
.copyAsCxMemberData()
)

// Call the method under test
Expand All @@ -304,8 +313,9 @@ class CleaningServiceApiCallsTest @Autowired constructor(
mockedBusinessPartner
.copyWithBpnReferences(defaultBpnRequest)
.copyWithLegalAddress(mockedBusinessPartner.uncategorized.address!!)
.copyWithConfidenceCriteria(cleaningServiceDummy.dummyConfidenceCriteria)
.copyWithConfidenceCriteria(expectedConfidenceCriteria)
.copyWithHasChanged(true, false, false)
.copyAsCxMemberData()
)

// Call the method under test
Expand All @@ -329,8 +339,9 @@ class CleaningServiceApiCallsTest @Autowired constructor(
val expectedResponse = createResultRequest(
mockedBusinessPartner
.copyWithLegalAddress(mockedBusinessPartner.uncategorized.address!!)
.copyWithConfidenceCriteria(cleaningServiceDummy.dummyConfidenceCriteria)
.copyWithConfidenceCriteria(expectedConfidenceCriteria)
.copyWithHasChanged(true, false, false)
.copyAsCxMemberData()
)

// Call the method under test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,9 @@ fun BusinessPartner.copyWithBpnRequests() =
legalEntity = legalEntity.copy(bpnReference = legalEntity.bpnReference.copy(referenceType = BpnReferenceType.BpnRequestIdentifier)),
site = site?.copy(bpnReference = site!!.bpnReference.copy(referenceType = BpnReferenceType.BpnRequestIdentifier)),
additionalAddress = additionalAddress?.copy(bpnReference = additionalAddress!!.bpnReference.copy(referenceType = BpnReferenceType.BpnRequestIdentifier))
)

fun BusinessPartner.copyAsCxMemberData() =
copy(
legalEntity = legalEntity.copy(isCatenaXMemberData = true)
)

0 comments on commit 46b4f66

Please sign in to comment.