diff --git a/bpdm-common/src/main/kotlin/org/eclipse/tractusx/bpdm/common/dto/openapidescription/LogisticAddressDescription.kt b/bpdm-common/src/main/kotlin/org/eclipse/tractusx/bpdm/common/dto/openapidescription/LogisticAddressDescription.kt index 88552f555..f08593bc0 100644 --- a/bpdm-common/src/main/kotlin/org/eclipse/tractusx/bpdm/common/dto/openapidescription/LogisticAddressDescription.kt +++ b/bpdm-common/src/main/kotlin/org/eclipse/tractusx/bpdm/common/dto/openapidescription/LogisticAddressDescription.kt @@ -60,4 +60,8 @@ object LogisticAddressDescription { const val siteExternalId = "The identifier which uniquely identifies (in the internal system landscape of the sharing member) " + "the business partner, representing the site, that the address belongs to." const val address = "Address information" + + const val addressType = "Indicates the address type, the legal address to a legal entity or the main address to a site, " + + "an additional address, or both legal and site address." + + "The site main address is where typically the main entrance or the reception is located, or where the mail is delivered to." } \ No newline at end of file diff --git a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/LogisticAddressVerboseDto.kt b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/LogisticAddressVerboseDto.kt index 2dd490ef0..c3d77a615 100644 --- a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/LogisticAddressVerboseDto.kt +++ b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/LogisticAddressVerboseDto.kt @@ -20,6 +20,7 @@ package org.eclipse.tractusx.bpdm.pool.api.model import io.swagger.v3.oas.annotations.media.Schema +import org.eclipse.tractusx.bpdm.common.dto.AddressType import org.eclipse.tractusx.bpdm.common.dto.IBaseLogisticAddressDto import org.eclipse.tractusx.bpdm.common.dto.openapidescription.CommonDescription import org.eclipse.tractusx.bpdm.common.dto.openapidescription.LogisticAddressDescription @@ -57,6 +58,8 @@ data class LogisticAddressVerboseDto( @get:Schema(description = CommonDescription.updatedAt) val updatedAt: Instant, - override val confidenceCriteria: ConfidenceCriteriaDto + override val confidenceCriteria: ConfidenceCriteriaDto, + @get:Schema(name = "addressType", description = LogisticAddressDescription.addressType) + val addressType: AddressType? = null, ) : IBaseLogisticAddressDto diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/ResponseMappings.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/ResponseMappings.kt index cadbdaddc..bdf7d68c0 100644 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/ResponseMappings.kt +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/ResponseMappings.kt @@ -19,6 +19,7 @@ package org.eclipse.tractusx.bpdm.pool.service +import org.eclipse.tractusx.bpdm.common.dto.AddressType import org.eclipse.tractusx.bpdm.common.dto.GeoCoordinateDto import org.eclipse.tractusx.bpdm.common.dto.PageDto import org.eclipse.tractusx.bpdm.common.dto.TypeKeyNameVerboseDto @@ -121,6 +122,7 @@ fun LogisticAddress.toDto(): LogisticAddressVerboseDto { physicalPostalAddress = physicalPostalAddress.toDto(), alternativePostalAddress = alternativePostalAddress?.toDto(), confidenceCriteria = confidenceCriteria.toDto(), + addressType = getAddressType(this) ) } @@ -284,3 +286,19 @@ fun ConfidenceCriteria.toDto(): ConfidenceCriteriaDto = nextConfidenceCheckAt, confidenceLevel ) + +private fun getAddressType(logisticAddress: LogisticAddress): AddressType { + return when { + logisticAddress.legalEntity?.legalAddress == logisticAddress && + logisticAddress.site?.mainAddress == logisticAddress -> AddressType.LegalAndSiteMainAddress + + logisticAddress.legalEntity?.legalAddress != logisticAddress && + logisticAddress.site?.mainAddress != logisticAddress -> AddressType.AdditionalAddress + + logisticAddress.legalEntity?.legalAddress == logisticAddress -> AddressType.LegalAddress + + logisticAddress.site?.mainAddress == logisticAddress -> AddressType.SiteMainAddress + + else -> throw IllegalStateException("Unable to determine address type.") + } +} \ No newline at end of file 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 50170ba98..d842867aa 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 @@ -20,6 +20,7 @@ package org.eclipse.tractusx.bpdm.pool.controller import org.assertj.core.api.Assertions.assertThat +import org.eclipse.tractusx.bpdm.common.dto.AddressType import org.eclipse.tractusx.bpdm.common.dto.PaginationRequest import org.eclipse.tractusx.bpdm.pool.Application import org.eclipse.tractusx.bpdm.pool.api.client.PoolApiClient @@ -161,7 +162,7 @@ class AddressControllerIT @Autowired constructor( val searchResult = poolClient.addresses.searchAddresses(searchRequest, PaginationRequest()) val expected = listOf( - BusinessPartnerVerboseValues.addressPartner2.copy(isLegalAddress = true), + BusinessPartnerVerboseValues.addressPartner2.copy(isLegalAddress = true, addressType = AddressType.LegalAddress), BusinessPartnerVerboseValues.addressPartner3 ) @@ -207,7 +208,7 @@ class AddressControllerIT @Autowired constructor( .let { assertAddressesAreEqual( it.content, listOf( - BusinessPartnerVerboseValues.addressPartner1.copy(isMainAddress = true), + BusinessPartnerVerboseValues.addressPartner1.copy(isMainAddress = true, addressType = AddressType.SiteMainAddress), BusinessPartnerVerboseValues.addressPartner1, BusinessPartnerVerboseValues.addressPartner2, ) @@ -220,7 +221,7 @@ class AddressControllerIT @Autowired constructor( .let { assertAddressesAreEqual( it.content, listOf( - BusinessPartnerVerboseValues.addressPartner2.copy(isMainAddress = true), + BusinessPartnerVerboseValues.addressPartner2.copy(isMainAddress = true, addressType = AddressType.SiteMainAddress), BusinessPartnerVerboseValues.addressPartner3, ) ) @@ -233,11 +234,11 @@ class AddressControllerIT @Autowired constructor( assertAddressesAreEqual( it.content, listOf( // site1 - BusinessPartnerVerboseValues.addressPartner1.copy(isMainAddress = true), + BusinessPartnerVerboseValues.addressPartner1.copy(isMainAddress = true, addressType = AddressType.SiteMainAddress), BusinessPartnerVerboseValues.addressPartner1, BusinessPartnerVerboseValues.addressPartner2, // site2 - BusinessPartnerVerboseValues.addressPartner2.copy(isMainAddress = true), + BusinessPartnerVerboseValues.addressPartner2.copy(isMainAddress = true, addressType = AddressType.SiteMainAddress), BusinessPartnerVerboseValues.addressPartner3, ) ) 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 dedf0afb3..b2f8acf00 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 @@ -20,6 +20,7 @@ package org.eclipse.tractusx.bpdm.pool.controller import org.assertj.core.api.Assertions.assertThat +import org.eclipse.tractusx.bpdm.common.dto.AddressType import org.eclipse.tractusx.bpdm.common.dto.PageDto import org.eclipse.tractusx.bpdm.common.dto.PaginationRequest import org.eclipse.tractusx.bpdm.pool.Application @@ -110,11 +111,19 @@ class SiteControllerIT @Autowired constructor( val expectedSiteWithReference1 = SiteWithMainAddressVerboseDto( site = BusinessPartnerVerboseValues.site1.copy(bpnLegalEntity = bpnL), - mainAddress = BusinessPartnerVerboseValues.addressPartner1.copy(isMainAddress = true, bpnSite = BusinessPartnerVerboseValues.site1.bpns) + mainAddress = BusinessPartnerVerboseValues.addressPartner1.copy( + isMainAddress = true, + addressType = AddressType.SiteMainAddress, + bpnSite = BusinessPartnerVerboseValues.site1.bpns + ) ) val expectedSiteWithReference2 = SiteWithMainAddressVerboseDto( site = BusinessPartnerVerboseValues.site2.copy(bpnLegalEntity = bpnL), - mainAddress = BusinessPartnerVerboseValues.addressPartner2.copy(isMainAddress = true, bpnSite = BusinessPartnerVerboseValues.site2.bpns) + mainAddress = BusinessPartnerVerboseValues.addressPartner2.copy( + isMainAddress = true, + addressType = AddressType.SiteMainAddress, + bpnSite = BusinessPartnerVerboseValues.site2.bpns + ) ) testHelpers.assertRecursively(searchResult.content) @@ -157,17 +166,29 @@ class SiteControllerIT @Autowired constructor( val expectedSiteWithReference1 = SiteWithMainAddressVerboseDto( site = BusinessPartnerVerboseValues.site1.copy(bpnLegalEntity = bpnL1), - mainAddress = BusinessPartnerVerboseValues.addressPartner1.copy(isMainAddress = true, bpnSite = BusinessPartnerVerboseValues.site1.bpns) + mainAddress = BusinessPartnerVerboseValues.addressPartner1.copy( + isMainAddress = true, + addressType = AddressType.SiteMainAddress, + bpnSite = BusinessPartnerVerboseValues.site1.bpns + ) ) val expectedSiteWithReference2 = SiteWithMainAddressVerboseDto( site = BusinessPartnerVerboseValues.site2.copy(bpnLegalEntity = bpnL1), - mainAddress = BusinessPartnerVerboseValues.addressPartner2.copy(isMainAddress = true, bpnSite = BusinessPartnerVerboseValues.site2.bpns) + mainAddress = BusinessPartnerVerboseValues.addressPartner2.copy( + isMainAddress = true, + addressType = AddressType.SiteMainAddress, + bpnSite = BusinessPartnerVerboseValues.site2.bpns + ) ) val expectedSiteWithReference3 = SiteWithMainAddressVerboseDto( site = BusinessPartnerVerboseValues.site3.copy(bpnLegalEntity = bpnL2), - mainAddress = BusinessPartnerVerboseValues.addressPartner3.copy(isMainAddress = true, bpnSite = BusinessPartnerVerboseValues.site3.bpns) + mainAddress = BusinessPartnerVerboseValues.addressPartner3.copy( + isMainAddress = true, + addressType = AddressType.SiteMainAddress, + bpnSite = BusinessPartnerVerboseValues.site3.bpns + ) ) testHelpers.assertRecursively(searchResult.content) @@ -518,11 +539,21 @@ class SiteControllerIT @Autowired constructor( val bpnL1 = createdStructures[0].legalEntity.legalEntity.bpnl val legalAddress1: LogisticAddressVerboseDto = - BusinessPartnerVerboseValues.addressPartner1.copy(isMainAddress = true, bpnSite = BusinessPartnerVerboseValues.site1.bpns, bpna = "BPNA0000000001YN") + BusinessPartnerVerboseValues.addressPartner1.copy( + isMainAddress = true, + addressType = AddressType.SiteMainAddress, + bpnSite = BusinessPartnerVerboseValues.site1.bpns, + bpna = "BPNA0000000001YN" + ) val site1 = BusinessPartnerVerboseValues.site1.copy(bpnLegalEntity = bpnL1) val legalAddress2: LogisticAddressVerboseDto = - BusinessPartnerVerboseValues.addressPartner2.copy(isMainAddress = true, bpnSite = BusinessPartnerVerboseValues.site2.bpns, bpna = "BPNA0000000002XY") + BusinessPartnerVerboseValues.addressPartner2.copy( + isMainAddress = true, + addressType = AddressType.SiteMainAddress, + bpnSite = BusinessPartnerVerboseValues.site2.bpns, + bpna = "BPNA0000000002XY" + ) val site2 = BusinessPartnerVerboseValues.site2.copy(bpnLegalEntity = bpnL1) val expectedFirstPage = PageDto( diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/BusinessPartnerVerboseValues.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/BusinessPartnerVerboseValues.kt index 89f8dbf4f..5184b8b50 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/BusinessPartnerVerboseValues.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/BusinessPartnerVerboseValues.kt @@ -21,6 +21,7 @@ package org.eclipse.tractusx.bpdm.pool.util import com.neovisionaries.i18n.CountryCode import com.neovisionaries.i18n.LanguageCode +import org.eclipse.tractusx.bpdm.common.dto.AddressType import org.eclipse.tractusx.bpdm.common.dto.TypeKeyNameVerboseDto import org.eclipse.tractusx.bpdm.common.model.BusinessStateType import org.eclipse.tractusx.bpdm.common.model.ClassificationType @@ -212,7 +213,8 @@ object BusinessPartnerVerboseValues { bpnSite = null, confidenceCriteria = confidenceCriteria1, createdAt = Instant.now(), - updatedAt = Instant.now() + updatedAt = Instant.now(), + addressType = AddressType.AdditionalAddress ) val addressPartner2 = LogisticAddressVerboseDto( @@ -222,7 +224,8 @@ object BusinessPartnerVerboseValues { bpnSite = null, confidenceCriteria = confidenceCriteria2, createdAt = Instant.now(), - updatedAt = Instant.now() + updatedAt = Instant.now(), + addressType = AddressType.AdditionalAddress ) val addressPartner3 = LogisticAddressVerboseDto( @@ -232,7 +235,8 @@ object BusinessPartnerVerboseValues { bpnSite = null, confidenceCriteria = confidenceCriteria3, createdAt = Instant.now(), - updatedAt = Instant.now() + updatedAt = Instant.now(), + addressType = AddressType.AdditionalAddress ) val addressPartnerCreate1 = AddressPartnerCreateVerboseDto( @@ -284,7 +288,8 @@ object BusinessPartnerVerboseValues { site = site1, mainAddress = addressPartner1.copy( bpnSite = site1.bpns, - isMainAddress = true + isMainAddress = true, + addressType = AddressType.SiteMainAddress ), index = "1" ) @@ -293,7 +298,8 @@ object BusinessPartnerVerboseValues { site = site2, mainAddress = addressPartner2.copy( bpnSite = site2.bpns, - isMainAddress = true + isMainAddress = true, + addressType = AddressType.SiteMainAddress ), index = "2" ) @@ -302,7 +308,8 @@ object BusinessPartnerVerboseValues { site = site3, mainAddress = addressPartner3.copy( bpnSite = site3.bpns, - isMainAddress = true + isMainAddress = true, + addressType = AddressType.SiteMainAddress ), index = "3" ) @@ -440,7 +447,8 @@ object BusinessPartnerVerboseValues { ), legalAddress = addressPartner1.copy( bpnLegalEntity = legalEntity1.legalEntity.bpnl, - isLegalAddress = true + isLegalAddress = true, + addressType = AddressType.LegalAddress ), index = "1" ) @@ -460,7 +468,8 @@ object BusinessPartnerVerboseValues { ), legalAddress = addressPartner2.copy( bpnLegalEntity = legalEntity2.legalEntity.bpnl, - isLegalAddress = true + isLegalAddress = true, + addressType = AddressType.LegalAddress ), index = "2" ) @@ -480,7 +489,8 @@ object BusinessPartnerVerboseValues { ), legalAddress = addressPartner3.copy( bpnLegalEntity = legalEntity3.legalEntity.bpnl, - isLegalAddress = true + isLegalAddress = true, + addressType = AddressType.LegalAddress ), index = "3" )