From a11a94267739c168b7f4798d97e08f6f50d353b0 Mon Sep 17 00:00:00 2001 From: rschneider <97682836+rainer-exxcellent@users.noreply.github.com> Date: Thu, 25 May 2023 14:44:41 +0200 Subject: [PATCH] feat(api): #172 Rename BPN fields - fix tests --- .../bridge/dummy/service/PoolUpdateService.kt | 6 ++-- .../request/AddressPartnerUpdateRequest.kt | 2 +- .../LegalEntityPartnerUpdateRequest.kt | 2 +- .../model/request/SitePartnerUpdateRequest.kt | 2 +- .../saas/service/SaasToRequestMapper.kt | 8 ++--- .../service/BusinessPartnerBuildService.kt | 16 +++++----- .../pool/controller/AddressControllerIT.kt | 24 ++++++++++----- .../controller/LegalEntityControllerIT.kt | 6 ++-- .../bpdm/pool/controller/SiteControllerIT.kt | 19 +++++++----- .../bpdm/pool/service/PartnerChangelogIT.kt | 2 +- .../tractusx/bpdm/pool/util/RequestValues.kt | 30 +++++++++---------- 11 files changed, 65 insertions(+), 52 deletions(-) diff --git a/bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/service/PoolUpdateService.kt b/bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/service/PoolUpdateService.kt index 096b9864b..2daab39d4 100644 --- a/bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/service/PoolUpdateService.kt +++ b/bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/service/PoolUpdateService.kt @@ -53,7 +53,7 @@ class PoolUpdateService( val updateRequests = entriesToUpdate.map { LegalEntityPartnerUpdateRequest( legalEntity = it.legalEntity, - bpn = it.bpn!! + bpnl = it.bpn!! ) } @@ -90,7 +90,7 @@ class PoolUpdateService( val updateRequests = entriesToUpdate.map { SitePartnerUpdateRequest( site = it.site, - bpn = it.bpn!! + bpns = it.bpn!! ) } @@ -142,7 +142,7 @@ class PoolUpdateService( val updateRequests = entriesToUpdate.map { AddressPartnerUpdateRequest( address = it.address, - bpn = it.bpn!! + bpna = it.bpn!! ) } diff --git a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/request/AddressPartnerUpdateRequest.kt b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/request/AddressPartnerUpdateRequest.kt index ea44fd0c9..f82b0609e 100644 --- a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/request/AddressPartnerUpdateRequest.kt +++ b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/request/AddressPartnerUpdateRequest.kt @@ -29,7 +29,7 @@ import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializ @Schema(name = "AddressPartnerUpdateRequest", description = "Request for updating a business partner record of type address") data class AddressPartnerUpdateRequest( @Schema(description = "Business Partner Number of this address") - val bpn: String, + val bpna: String, @field:JsonUnwrapped val address: LogisticAddressDto diff --git a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/request/LegalEntityPartnerUpdateRequest.kt b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/request/LegalEntityPartnerUpdateRequest.kt index 16b5f24c1..12595b58b 100644 --- a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/request/LegalEntityPartnerUpdateRequest.kt +++ b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/request/LegalEntityPartnerUpdateRequest.kt @@ -29,7 +29,7 @@ import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializ @Schema(name = "LegalEntityUpdateRequest", description = "Request for updating a business partner record of type legal entity") data class LegalEntityPartnerUpdateRequest( @Schema(description = "Business Partner Number") - val bpn: String, + val bpnl: String, @field:JsonUnwrapped val legalEntity: LegalEntityDto diff --git a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/request/SitePartnerUpdateRequest.kt b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/request/SitePartnerUpdateRequest.kt index 8d82e544a..b3c5589b0 100644 --- a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/request/SitePartnerUpdateRequest.kt +++ b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/request/SitePartnerUpdateRequest.kt @@ -29,7 +29,7 @@ import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializ @Schema(name = "SitePartnerUpdateRequest", description = "Request for updating a business partner record of type site") data class SitePartnerUpdateRequest( @Schema(description = "Business Partner Number of this site") - val bpn: String, + val bpns: String, @field:JsonUnwrapped val site: SiteDto diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/saas/service/SaasToRequestMapper.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/saas/service/SaasToRequestMapper.kt index abe47a4de..63b4ead2b 100644 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/saas/service/SaasToRequestMapper.kt +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/saas/service/SaasToRequestMapper.kt @@ -26,8 +26,8 @@ import org.eclipse.tractusx.bpdm.common.dto.response.type.TypeKeyNameDto import org.eclipse.tractusx.bpdm.common.dto.saas.BusinessPartnerSaas import org.eclipse.tractusx.bpdm.common.dto.saas.LegalFormSaas import org.eclipse.tractusx.bpdm.common.dto.saas.TypeKeyNameUrlSaas -import org.eclipse.tractusx.bpdm.common.service.SaasMappings.toLogisticAddressDto import org.eclipse.tractusx.bpdm.common.service.SaasMappings.toLegalEntityDto +import org.eclipse.tractusx.bpdm.common.service.SaasMappings.toLogisticAddressDto import org.eclipse.tractusx.bpdm.common.service.SaasMappings.toSiteDto import org.eclipse.tractusx.bpdm.pool.api.model.request.* import org.eclipse.tractusx.bpdm.pool.component.saas.dto.BusinessPartnerWithBpn @@ -57,7 +57,7 @@ class SaasToRequestMapper { fun toLegalEntityUpdateRequest(partnerWithBpn: BusinessPartnerWithBpn): LegalEntityPartnerUpdateRequest { return LegalEntityPartnerUpdateRequest( - bpn = partnerWithBpn.bpn, + bpnl = partnerWithBpn.bpn, legalEntity = partnerWithBpn.partner.toLegalEntityDto() ) } @@ -91,7 +91,7 @@ class SaasToRequestMapper { fun toSiteUpdateRequest(partnerWithBpn: BusinessPartnerWithBpn): SitePartnerUpdateRequest { return SitePartnerUpdateRequest( - bpn = partnerWithBpn.bpn, + bpns = partnerWithBpn.bpn, site = partnerWithBpn.partner.toSiteDto() ) } @@ -124,7 +124,7 @@ class SaasToRequestMapper { fun toAddressUpdateRequest(partnerWithBpn: BusinessPartnerWithBpn): AddressPartnerUpdateRequest { return AddressPartnerUpdateRequest( - bpn = partnerWithBpn.bpn, + bpna = partnerWithBpn.bpn, address = partnerWithBpn.partner.toLogisticAddressDto() ) } diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/BusinessPartnerBuildService.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/BusinessPartnerBuildService.kt index be4210b61..e79abebab 100644 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/BusinessPartnerBuildService.kt +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/BusinessPartnerBuildService.kt @@ -163,7 +163,7 @@ class BusinessPartnerBuildService( val legalEntityMetadataMap = metadataMappingService.mapRequests(requests.map { it.legalEntity }) val addressMetadataMap = metadataMappingService.mapRequests(requests.map { it.legalEntity.legalAddress }) - val bpnsToFetch = requests.map { it.bpn } + val bpnsToFetch = requests.map { it.bpnl } val legalEntities = legalEntityRepository.findDistinctByBpnIn(bpnsToFetch) businessPartnerFetchService.fetchDependenciesWithLegalAddress(legalEntities) @@ -172,7 +172,7 @@ class BusinessPartnerBuildService( ErrorInfo(LegalEntityUpdateError.LegalEntityNotFound, "Legal entity $it not updated: BPNL not found", it) } - val requestByBpnMap = requests.associateBy { it.bpn } + val requestByBpnMap = requests.associateBy { it.bpnl } legalEntities.forEach { val request = requestByBpnMap.get(it.bpn)!! updateLegalEntity(it, request.legalEntity, legalEntityMetadataMap) @@ -193,7 +193,7 @@ class BusinessPartnerBuildService( val addressMetadataMap = metadataMappingService.mapRequests(requests.map { it.site.mainAddress }) - val bpnsToFetch = requests.map { it.bpn } + val bpnsToFetch = requests.map { it.bpns } val sites = siteRepository.findDistinctByBpnIn(bpnsToFetch) val bpnsNotFetched = bpnsToFetch.minus(sites.map { it.bpn }.toSet()) @@ -204,7 +204,7 @@ class BusinessPartnerBuildService( changelogService.createChangelogEntries(sites.map { ChangelogEntryDto(it.bpn, ChangelogType.UPDATE, ChangelogSubject.SITE) }) changelogService.createChangelogEntries(sites.map { ChangelogEntryDto(it.mainAddress.bpn, ChangelogType.UPDATE, ChangelogSubject.ADDRESS) }) - val requestByBpnMap = requests.associateBy { it.bpn } + val requestByBpnMap = requests.associateBy { it.bpns } sites.forEach { val request = requestByBpnMap[it.bpn]!! updateSite(it, request.site) @@ -218,14 +218,14 @@ class BusinessPartnerBuildService( fun updateAddresses(requests: Collection): AddressPartnerUpdateResponseWrapper { logger.info { "Update ${requests.size} business partner addresses" } - val validAddresses = logisticAddressRepository.findDistinctByBpnIn(requests.map { it.bpn }) + val validAddresses = logisticAddressRepository.findDistinctByBpnIn(requests.map { it.bpna }) val validBpns = validAddresses.map { it.bpn }.toHashSet() - val (validRequests, invalidRequests) = requests.partition { validBpns.contains(it.bpn) } + val (validRequests, invalidRequests) = requests.partition { validBpns.contains(it.bpna) } val errors = invalidRequests.map { - ErrorInfo(AddressUpdateError.AddressNotFound, "Address ${it.bpn} not updated: BPNA not found", it.bpn) + ErrorInfo(AddressUpdateError.AddressNotFound, "Address ${it.bpna} not updated: BPNA not found", it.bpna) } - val requestByBpnMap = requests.associateBy { it.bpn } + val requestByBpnMap = requests.associateBy { it.bpna } val metadataMap = metadataMappingService.mapRequests(validRequests.map { it.address }) validAddresses.forEach { updateLogisticAddress(it, requestByBpnMap[it.bpn]!!.address, metadataMap) } diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/AddressControllerIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/AddressControllerIT.kt index 5de6f41d6..8bc95690e 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/AddressControllerIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/AddressControllerIT.kt @@ -376,9 +376,9 @@ class AddressControllerIT @Autowired constructor( ) val toUpdate = listOf( - RequestValues.addressPartnerUpdate1.copy(bpn = bpnA2), - RequestValues.addressPartnerUpdate2.copy(bpn = bpnA3), - RequestValues.addressPartnerUpdate3.copy(bpn = bpnA1) + RequestValues.addressPartnerUpdate1.copy(bpna = bpnA2), + RequestValues.addressPartnerUpdate2.copy(bpna = bpnA3), + RequestValues.addressPartnerUpdate3.copy(bpna = bpnA1) ) val response = poolClient.addresses().updateAddresses(toUpdate) @@ -417,9 +417,9 @@ class AddressControllerIT @Autowired constructor( val firstInvalidBpn = "BPNLXXXXXXXX" val secondInvalidBpn = "BPNAXXXXXXXX" val toUpdate = listOf( - RequestValues.addressPartnerUpdate2.copy(bpn = bpnA1), - RequestValues.addressPartnerUpdate2.copy(bpn = firstInvalidBpn), - RequestValues.addressPartnerUpdate3.copy(bpn = secondInvalidBpn) + RequestValues.addressPartnerUpdate2.copy(bpna = bpnA1), + RequestValues.addressPartnerUpdate2.copy(bpna = firstInvalidBpn), + RequestValues.addressPartnerUpdate3.copy(bpna = secondInvalidBpn) ) val response = poolClient.addresses().updateAddresses(toUpdate) @@ -435,7 +435,11 @@ class AddressControllerIT @Autowired constructor( actuals.forEach { assertThat(it.address.bpna).matches(testHelpers.bpnAPattern) } testHelpers.assertRecursively(actuals) - .ignoringFields("address.bpn", "address.bpnLegalEntity", "address.bpnSite") + .ignoringFields( + AddressPartnerCreateResponse::address.name + "." + LogisticAddressResponse::bpna.name, + AddressPartnerCreateResponse::address.name + "." + LogisticAddressResponse::bpnLegalEntity.name, + AddressPartnerCreateResponse::address.name + "." + LogisticAddressResponse::bpnSite.name + ) .isEqualTo(expected) } @@ -443,7 +447,11 @@ class AddressControllerIT @Autowired constructor( actuals.forEach { assertThat(it.bpna).matches(testHelpers.bpnAPattern) } testHelpers.assertRecursively(actuals) - .ignoringFields("bpn", "bpnLegalEntity", "bpnSite") + .ignoringFields( + LogisticAddressResponse::bpna.name, + LogisticAddressResponse::bpnLegalEntity.name, + LogisticAddressResponse::bpnSite.name + ) .isEqualTo(expected) } diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/LegalEntityControllerIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/LegalEntityControllerIT.kt index 56956d1ae..e5b9ac768 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/LegalEntityControllerIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/LegalEntityControllerIT.kt @@ -167,7 +167,7 @@ class LegalEntityControllerIT @Autowired constructor( } val toUpdate = RequestValues.legalEntityUpdate3.copy( - bpn = givenBpnL + bpnl = givenBpnL ) val response = poolClient.legalEntities().updateBusinessPartners(listOf(toUpdate)) @@ -190,8 +190,8 @@ class LegalEntityControllerIT @Autowired constructor( val bpnA = createdEntity.legalAddress.bpna val toUpdate = listOf( - RequestValues.legalEntityUpdate3.copy(bpn = "NONEXISTENT"), - RequestValues.legalEntityUpdate3.copy(bpn = bpnL) + RequestValues.legalEntityUpdate3.copy(bpnl = "NONEXISTENT"), + RequestValues.legalEntityUpdate3.copy(bpnl = bpnL) ) val expected = with(ResponseValues.legalEntityUpsert3) { diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/SiteControllerIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/SiteControllerIT.kt index dbb926e4d..1942544b2 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/SiteControllerIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/SiteControllerIT.kt @@ -244,9 +244,9 @@ class SiteControllerIT @Autowired constructor( ) val toUpdate = listOf( - RequestValues.siteUpdate1.copy(bpn = bpnS3), - RequestValues.siteUpdate2.copy(bpn = bpnS1), - RequestValues.siteUpdate3.copy(bpn = bpnS2) + RequestValues.siteUpdate1.copy(bpns = bpnS3), + RequestValues.siteUpdate2.copy(bpns = bpnS1), + RequestValues.siteUpdate3.copy(bpns = bpnS2) ) val response = poolClient.sites().updateSite(toUpdate) @@ -280,9 +280,9 @@ class SiteControllerIT @Autowired constructor( ) val toUpdate = listOf( - RequestValues.siteUpdate1.copy(bpn = bpnS2), - RequestValues.siteUpdate2.copy(bpn = bpnS1), - RequestValues.siteUpdate3.copy(bpn = "NONEXISTENT"), + RequestValues.siteUpdate1.copy(bpns = bpnS2), + RequestValues.siteUpdate2.copy(bpns = bpnS1), + RequestValues.siteUpdate3.copy(bpns = "NONEXISTENT"), ) val response = poolClient.sites().updateSite(toUpdate) @@ -353,7 +353,12 @@ class SiteControllerIT @Autowired constructor( actuals.forEach { assertThat(it.site.bpns).matches(testHelpers.bpnSPattern) } testHelpers.assertRecursively(actuals) - .ignoringFields("site.bpn", "site.bpnLegalEntity", "mainAddress.bpn", "mainAddress.bpnSite") + .ignoringFields( + SitePartnerCreateResponse::site.name + "." + SiteResponse::bpns.name, + SitePartnerCreateResponse::site.name + "." + SiteResponse::bpnLegalEntity.name, + SitePartnerCreateResponse::mainAddress.name + "." + LogisticAddressResponse::bpna.name, + SitePartnerCreateResponse::mainAddress.name + "." + LogisticAddressResponse::bpnSite.name + ) .isEqualTo(expected) } diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/service/PartnerChangelogIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/service/PartnerChangelogIT.kt index e19e65fbd..b913dfd33 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/service/PartnerChangelogIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/service/PartnerChangelogIT.kt @@ -95,7 +95,7 @@ class PartnerChangelogIT @Autowired constructor( // prepare modified partner to import val modifiedPartnersToImport = listOf( - RequestValues.legalEntityUpdate3.copy(bpn = bpnL1) + RequestValues.legalEntityUpdate3.copy(bpnl = bpnL1) ) val timestampBetweenCreateAndUpdate = Instant.now() diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/RequestValues.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/RequestValues.kt index f104335c4..a0d2e8f0b 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/RequestValues.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/RequestValues.kt @@ -198,17 +198,17 @@ object RequestValues { ) val legalEntityUpdate1 = LegalEntityPartnerUpdateRequest( - bpn = CommonValues.bpnL1, + bpnl = CommonValues.bpnL1, legalEntity = legalEntityCreate1.legalEntity ) val legalEntityUpdate2 = LegalEntityPartnerUpdateRequest( - bpn = CommonValues.bpnL2, + bpnl = CommonValues.bpnL2, legalEntity = legalEntityCreate2.legalEntity ) val legalEntityUpdate3 = LegalEntityPartnerUpdateRequest( - bpn = CommonValues.bpnL3, + bpnl = CommonValues.bpnL3, legalEntity = legalEntityCreate3.legalEntity ) @@ -219,7 +219,7 @@ object RequestValues { mainAddress = logisticAddress1 ), index = CommonValues.index1, - bpnParent = legalEntityUpdate1.bpn + bpnParent = legalEntityUpdate1.bpnl ) val siteCreate2 = SitePartnerCreateRequest( @@ -229,7 +229,7 @@ object RequestValues { mainAddress = logisticAddress2 ), index = CommonValues.index2, - bpnParent = legalEntityUpdate2.bpn + bpnParent = legalEntityUpdate2.bpnl ) val siteCreate3 = SitePartnerCreateRequest( @@ -239,54 +239,54 @@ object RequestValues { mainAddress = logisticAddress3 ), index = CommonValues.index3, - bpnParent = legalEntityUpdate3.bpn + bpnParent = legalEntityUpdate3.bpnl ) val siteUpdate1 = SitePartnerUpdateRequest( - bpn = CommonValues.bpnS1, + bpns = CommonValues.bpnS1, site = siteCreate1.site ) val siteUpdate2 = SitePartnerUpdateRequest( - bpn = CommonValues.bpnS2, + bpns = CommonValues.bpnS2, site = siteCreate2.site ) val siteUpdate3 = SitePartnerUpdateRequest( - bpn = CommonValues.bpnS3, + bpns = CommonValues.bpnS3, site = siteCreate3.site ) val addressPartnerCreate1 = AddressPartnerCreateRequest( address = logisticAddress1, - bpnParent = legalEntityUpdate1.bpn, + bpnParent = legalEntityUpdate1.bpnl, index = CommonValues.index1 ) val addressPartnerCreate2 = AddressPartnerCreateRequest( address = logisticAddress2, - bpnParent = legalEntityUpdate2.bpn, + bpnParent = legalEntityUpdate2.bpnl, index = CommonValues.index2 ) val addressPartnerCreate3 = AddressPartnerCreateRequest( address = logisticAddress3, - bpnParent = legalEntityUpdate3.bpn, + bpnParent = legalEntityUpdate3.bpnl, index = CommonValues.index3 ) val addressPartnerUpdate1 = AddressPartnerUpdateRequest( - bpn = CommonValues.bpnA1, + bpna = CommonValues.bpnA1, address = logisticAddress1 ) val addressPartnerUpdate2 = AddressPartnerUpdateRequest( - bpn = CommonValues.bpnA2, + bpna = CommonValues.bpnA2, address = logisticAddress2 ) val addressPartnerUpdate3 = AddressPartnerUpdateRequest( - bpn = CommonValues.bpnA3, + bpna = CommonValues.bpnA3, address = logisticAddress3 )