From 3cbb2fb373a82de50c63ae5ac7b1c6683407e27c Mon Sep 17 00:00:00 2001 From: alexsilva Date: Tue, 28 Nov 2023 16:12:14 +0000 Subject: [PATCH] fix(leaning-service-dummy) - Changed hasChanged variable to be vased on Address Type --- .../service/GenericBusinessPartnerMappings.kt | 8 +++++--- .../cleaning/service/CleaningServiceDummyTest.kt | 14 +++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/service/GenericBusinessPartnerMappings.kt b/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/service/GenericBusinessPartnerMappings.kt index b7f9769cb..c05c59b00 100644 --- a/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/service/GenericBusinessPartnerMappings.kt +++ b/bpdm-cleaning-service-dummy/src/main/kotlin/org/eclipse/tractusx/bpdm/cleaning/service/GenericBusinessPartnerMappings.kt @@ -20,6 +20,7 @@ package org.eclipse.tractusx.bpdm.cleaning.service +import org.eclipse.tractusx.bpdm.common.dto.AddressType import org.eclipse.tractusx.orchestrator.api.model.* @@ -27,7 +28,7 @@ fun BusinessPartnerGenericDto.toLegalEntityDto(bpnReferenceDto: BpnReferenceDto, return LegalEntityDto( bpnLReference = bpnReferenceDto, - hasChanged = true, + hasChanged = postalAddress.addressType in setOf(AddressType.LegalAddress, AddressType.LegalAndSiteMainAddress), legalName = nameParts.joinToString(" "), legalShortName = shortName, identifiers = identifiers.mapNotNull { it.toLegalEntityIdentifierDto() }, @@ -66,9 +67,10 @@ fun BusinessPartnerStateDto.toSiteState(): SiteStateDto? { fun BusinessPartnerGenericDto.toLogisticAddressDto(bpnReferenceDto: BpnReferenceDto): LogisticAddressDto { + return LogisticAddressDto( bpnAReference = bpnReferenceDto, - hasChanged = true, + hasChanged = postalAddress.addressType == AddressType.AdditionalAddress, name = nameParts.joinToString(" "), states = emptyList(), identifiers = emptyList(), @@ -82,7 +84,7 @@ fun BusinessPartnerGenericDto.toSiteDto(bpnReferenceDto: BpnReferenceDto, legalN return SiteDto( bpnSReference = bpnReferenceDto, - hasChanged = true, + hasChanged = postalAddress.addressType in setOf(AddressType.SiteMainAddress, AddressType.LegalAndSiteMainAddress), name = legalName, states = states.mapNotNull { it.toSiteState() }, mainAddress = siteAddressReference diff --git a/bpdm-cleaning-service-dummy/src/test/kotlin/org/eclipse/tractusx/bpdm/cleaning/service/CleaningServiceDummyTest.kt b/bpdm-cleaning-service-dummy/src/test/kotlin/org/eclipse/tractusx/bpdm/cleaning/service/CleaningServiceDummyTest.kt index ff0062f1f..d9f9089b7 100644 --- a/bpdm-cleaning-service-dummy/src/test/kotlin/org/eclipse/tractusx/bpdm/cleaning/service/CleaningServiceDummyTest.kt +++ b/bpdm-cleaning-service-dummy/src/test/kotlin/org/eclipse/tractusx/bpdm/cleaning/service/CleaningServiceDummyTest.kt @@ -66,7 +66,7 @@ class CleaningServiceDummyTest @Autowired constructor( val expectedAddress = expectedLogisticAddressDto.copy(bpnAReference = BpnReferenceDto(expectedBpnA.toString(), BpnReferenceType.Bpn)) - val expectedLegalEntity = expectedLegalEntityDto.copy(legalAddress = expectedLogisticAddressDto) + val expectedLegalEntity = expectedLegalEntityDto.copy(legalAddress = expectedLogisticAddressDto, hasChanged = false) assertRecursively(resultedAddress).isEqualTo(expectedAddress) @@ -97,7 +97,7 @@ class CleaningServiceDummyTest @Autowired constructor( val expectedAddress = expectedLogisticAddressDto.copy() - val expectedLegalEntity = expectedLegalEntityDto.copy(legalAddress = expectedLogisticAddressDto) + val expectedLegalEntity = expectedLegalEntityDto.copy(legalAddress = expectedLogisticAddressDto, hasChanged = false) // bpnAReference since they are generated assertRecursively(resultedAddress).ignoringFields("bpnAReference").isEqualTo(expectedAddress) @@ -130,6 +130,7 @@ class CleaningServiceDummyTest @Autowired constructor( val expectedLegalEntity = expectedLegalEntityDto.copy( legalAddress = expectedLogisticAddressDto.copy( + hasChanged = false, bpnAReference = BpnReferenceDto( expectedBpnA.toString(), BpnReferenceType.Bpn @@ -174,7 +175,9 @@ class CleaningServiceDummyTest @Autowired constructor( val expectedLegalEntity = expectedLegalEntityDto.copy( + hasChanged = true, legalAddress = expectedLogisticAddressDto.copy( + hasChanged = false, bpnAReference = BpnReferenceDto( expectedBpnA.toString(), BpnReferenceType.Bpn @@ -183,7 +186,8 @@ class CleaningServiceDummyTest @Autowired constructor( ) val expectedSite = expectedSiteDto.copy( - mainAddress = expectedLogisticAddressDto.copy(bpnAReference = BpnReferenceDto(expectedBpnA.toString(), BpnReferenceType.Bpn)), + hasChanged = true, + mainAddress = expectedLogisticAddressDto.copy(bpnAReference = BpnReferenceDto(expectedBpnA.toString(), BpnReferenceType.Bpn), hasChanged = false), bpnSReference = BpnReferenceDto(expectedBpnS.toString(), BpnReferenceType.Bpn) ) @@ -222,9 +226,9 @@ class CleaningServiceDummyTest @Autowired constructor( assertNotEquals(resultedAddress?.bpnAReference?.referenceValue, resultedLegalEntity?.legalAddress?.bpnAReference?.referenceValue) assertNotEquals(resultedAddress?.bpnAReference?.referenceValue, resultedSite?.mainAddress?.bpnAReference?.referenceValue) - val expectedLegalEntity = expectedLegalEntityDto.copy(legalAddress = expectedLogisticAddressDto.copy()) + val expectedLegalEntity = expectedLegalEntityDto.copy(legalAddress = expectedLogisticAddressDto.copy(hasChanged = false), hasChanged = false) - val expectedSite = expectedSiteDto.copy(mainAddress = expectedLogisticAddressDto.copy()) + val expectedSite = expectedSiteDto.copy(mainAddress = expectedLogisticAddressDto.copy(hasChanged = false), hasChanged = true) // ignoring bpnLReference and legalAddress.bpnAReference since they are generated