Skip to content

Commit

Permalink
Merge pull request #712 from catenax-ng/feat/replace_address_type
Browse files Browse the repository at this point in the history
feat(pool): added Address Type to LogisticAddressVerboseDto
  • Loading branch information
nicoprow authored Jan 12, 2024
2 parents d3431d8 + 1802a18 commit e179584
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -121,6 +122,7 @@ fun LogisticAddress.toDto(): LogisticAddressVerboseDto {
physicalPostalAddress = physicalPostalAddress.toDto(),
alternativePostalAddress = alternativePostalAddress?.toDto(),
confidenceCriteria = confidenceCriteria.toDto(),
addressType = getAddressType(this)
)
}

Expand Down Expand Up @@ -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.")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)

Expand Down Expand Up @@ -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,
)
Expand All @@ -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,
)
)
Expand All @@ -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,
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -284,7 +288,8 @@ object BusinessPartnerVerboseValues {
site = site1,
mainAddress = addressPartner1.copy(
bpnSite = site1.bpns,
isMainAddress = true
isMainAddress = true,
addressType = AddressType.SiteMainAddress
),
index = "1"
)
Expand All @@ -293,7 +298,8 @@ object BusinessPartnerVerboseValues {
site = site2,
mainAddress = addressPartner2.copy(
bpnSite = site2.bpns,
isMainAddress = true
isMainAddress = true,
addressType = AddressType.SiteMainAddress
),
index = "2"
)
Expand All @@ -302,7 +308,8 @@ object BusinessPartnerVerboseValues {
site = site3,
mainAddress = addressPartner3.copy(
bpnSite = site3.bpns,
isMainAddress = true
isMainAddress = true,
addressType = AddressType.SiteMainAddress
),
index = "3"
)
Expand Down Expand Up @@ -440,7 +447,8 @@ object BusinessPartnerVerboseValues {
),
legalAddress = addressPartner1.copy(
bpnLegalEntity = legalEntity1.legalEntity.bpnl,
isLegalAddress = true
isLegalAddress = true,
addressType = AddressType.LegalAddress
),
index = "1"
)
Expand All @@ -460,7 +468,8 @@ object BusinessPartnerVerboseValues {
),
legalAddress = addressPartner2.copy(
bpnLegalEntity = legalEntity2.legalEntity.bpnl,
isLegalAddress = true
isLegalAddress = true,
addressType = AddressType.LegalAddress
),
index = "2"
)
Expand All @@ -480,7 +489,8 @@ object BusinessPartnerVerboseValues {
),
legalAddress = addressPartner3.copy(
bpnLegalEntity = legalEntity3.legalEntity.bpnl,
isLegalAddress = true
isLegalAddress = true,
addressType = AddressType.LegalAddress
),
index = "3"
)
Expand Down

0 comments on commit e179584

Please sign in to comment.