Skip to content

Commit

Permalink
Merge pull request #689 from catenax-ng/feat/generic-add-names
Browse files Browse the repository at this point in the history
Feat: Add Site Name and Address Name to Generic Business Partner Model
  • Loading branch information
nicoprow authored Dec 29, 2023
2 parents c19a27e + 4735d25 commit 0d670d5
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ class CleaningServiceDummy(
}

fun createSiteRepresentation(genericPartner: BusinessPartnerGenericDto, siteAddressReference: LogisticAddressDto): SiteDto {
val legalName = genericPartner.nameParts.joinToString(" ")
val bpnReferenceDto = createBpnReference(genericPartner.site.siteBpn)
return genericPartner.toSiteDto(bpnReferenceDto, legalName, siteAddressReference)
return genericPartner.toSiteDto(bpnReferenceDto, siteAddressReference)
}

fun createBpnReference(bpn: String?): BpnReferenceDto {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,21 @@ fun BusinessPartnerGenericDto.toLogisticAddressDto(bpnReferenceDto: BpnReference
return LogisticAddressDto(
bpnAReference = bpnReferenceDto,
hasChanged = address.addressType == AddressType.AdditionalAddress,
name = nameParts.joinToString(" "),
name = address.name,
states = emptyList(),
identifiers = emptyList(),
physicalPostalAddress = address.physicalPostalAddress,
alternativePostalAddress = address.alternativePostalAddress
)
}

fun BusinessPartnerGenericDto.toSiteDto(bpnReferenceDto: BpnReferenceDto, legalName: String, siteAddressReference: LogisticAddressDto): SiteDto {
fun BusinessPartnerGenericDto.toSiteDto(bpnReferenceDto: BpnReferenceDto, siteAddressReference: LogisticAddressDto): SiteDto {


return SiteDto(
bpnSReference = bpnReferenceDto,
hasChanged = address.addressType in setOf(AddressType.SiteMainAddress, AddressType.LegalAndSiteMainAddress),
name = legalName,
name = site.name,
states = states.mapNotNull { it.toSiteState() },
mainAddress = siteAddressReference

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ object CommonValues {
const val fixedTaskId = "taskid-123123"

private val nameParts = listOf("Part1", "Part2")
private val siteName = "Site Name"
private val addressName = "Address Name"
private const val shortName = "ShortName"
private val identifiers = listOf(
BusinessPartnerIdentifierDto(
Expand Down Expand Up @@ -109,7 +111,9 @@ object CommonValues {
shortName = shortName,
legalForm = legalForm,
classifications = classifications
)
),
site = SiteRepresentation(name = siteName),
address = AddressRepresentation(name = addressName)
)


Expand Down Expand Up @@ -185,14 +189,14 @@ object CommonValues {

val expectedSiteDto = SiteDto(
hasChanged = true,
name = nameParts.joinToString(" "),
name = siteName,
states = states.mapNotNull { it.toSiteState() },
)

val expectedLogisticAddressDto = LogisticAddressDto(

hasChanged = true,
name = nameParts.joinToString(" "),
name = addressName,
states = emptyList(),
identifiers = emptyList(),
physicalPostalAddress = physicalPostalAddress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,19 @@ interface IBaseLegalEntityRepresentation {
interface IBaseSiteRepresentation {
@get:Schema(description = "The BPNS of the site, on which the business partner provides a view.")
val siteBpn: String?

@get:Schema(description = "The name of the site, on which the business partner provides a view. This is not according to official registers but according to the name the owner chooses.")
val name: String?
}

@Schema(description = "An address representation adds context information to the address, on which the business partner provides a view. Additionally, it contains most of the information from the assigned address.")
interface IBaseAddressRepresentation : IBaseBusinessPartnerPostalAddressDto {
@get:Schema(description = "The BPNA of the address, on which the business partner provides a view.")
val addressBpn: String?

@get:Schema(description = "The name of the address, on which the business partner provides a view. This is not according to official registers but according to the name the sharing members agree on, such as the name of a gate or any other additional names that designate the address in common parlance.")
val name: String?

@get:Schema(description = "One of the address types: Legal Address, Site Main Address, Legal and Site Main Address, Additional Address. ")
override val addressType: AddressType?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ data class LegalEntityRepresentationInputDto(
) : IBaseLegalEntityRepresentation

data class SiteRepresentationInputDto(
override val siteBpn: String? = null
override val siteBpn: String? = null,
override val name: String? = null
) : IBaseSiteRepresentation

data class AddressRepresentationInputDto(
override val addressBpn: String? = null,
override val name: String? = null,
override val addressType: AddressType? = null,
override val physicalPostalAddress: PhysicalPostalAddressDto = PhysicalPostalAddressDto(),
override val alternativePostalAddress: AlternativePostalAddressDto = AlternativePostalAddressDto()
override val alternativePostalAddress: AlternativePostalAddressDto = AlternativePostalAddressDto(),
) : IBaseAddressRepresentation
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ data class LegalEntityRepresentationOutputDto(
description = "Site properties of business partner output data"
)
data class SiteRepresentationOutputDto(
override val siteBpn: String? = null
override val siteBpn: String? = null,
override val name: String? = null
) : IBaseSiteRepresentation

@Schema(
Expand All @@ -74,7 +75,8 @@ data class SiteRepresentationOutputDto(
)
data class AddressComponentOutputDto(
override val addressBpn: String,
override val addressType: AddressType? = null,
override val name: String? = null,
override val addressType: AddressType?,
override val physicalPostalAddress: PhysicalPostalAddressDto = PhysicalPostalAddressDto(),
override val alternativePostalAddress: AlternativePostalAddressDto = AlternativePostalAddressDto()
override val alternativePostalAddress: AlternativePostalAddressDto = AlternativePostalAddressDto(),
) : IBaseAddressRepresentation
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ class BusinessPartner(
@Column(name = "legal_name")
var legalName: String? = null,

@Column(name = "site_name")
var siteName: String? = null,

@Column(name = "address_name")
var addressName: String? = null,

@Column(name = "legal_form")
var legalForm: String? = null,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class BusinessPartnerMappings {
classifications = dto.legalEntity.classifications.mapNotNull(::toClassification).toSortedSet(),
shortName = dto.legalEntity.shortName,
legalName = dto.legalEntity.legalName,
siteName = dto.site.name,
addressName = dto.address.name,
legalForm = dto.legalEntity.legalForm,
isOwnCompanyData = dto.isOwnCompanyData,
bpnL = dto.legalEntity.legalEntityBpn,
Expand All @@ -100,13 +102,15 @@ class BusinessPartnerMappings {

private fun toSiteComponentInputDto(entity: BusinessPartner): SiteRepresentationInputDto {
return SiteRepresentationInputDto(
siteBpn = entity.bpnS
siteBpn = entity.bpnS,
name = entity.siteName
)
}

private fun toAddressComponentInputDto(entity: BusinessPartner): AddressRepresentationInputDto {
return AddressRepresentationInputDto(
addressBpn = entity.bpnA,
name = entity.addressName,
addressType = entity.postalAddress.addressType,
physicalPostalAddress = entity.postalAddress.physicalPostalAddress?.toPhysicalPostalAddress() ?: PhysicalPostalAddressDto(),
alternativePostalAddress = entity.postalAddress.alternativePostalAddress?.toAlternativePostalAddressDto() ?: AlternativePostalAddressDto()
Expand All @@ -130,7 +134,8 @@ class BusinessPartnerMappings {

private fun toSiteComponentOutputDto(entity: BusinessPartner): SiteRepresentationOutputDto {
return SiteRepresentationOutputDto(
siteBpn = entity.bpnS
siteBpn = entity.bpnS,
name = entity.siteName
)
}

Expand All @@ -142,6 +147,7 @@ class BusinessPartnerMappings {
BusinessPartner::bpnA,
entity.externalId
),
entity.addressName,
addressType = entity.postalAddress.addressType,
physicalPostalAddress = entity.postalAddress.physicalPostalAddress?.toPhysicalPostalAddress() ?: PhysicalPostalAddressDto(),
alternativePostalAddress = entity.postalAddress.alternativePostalAddress?.toAlternativePostalAddressDto() ?: AlternativePostalAddressDto()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ class BusinessPartnerService(
entity.roles != persistedBP.roles ||
entity.shortName != persistedBP.shortName ||
entity.legalName != persistedBP.legalName ||
entity.siteName != persistedBP.siteName ||
entity.addressName != persistedBP.addressName ||
entity.legalForm != persistedBP.legalForm ||
entity.isOwnCompanyData != persistedBP.isOwnCompanyData ||
entity.bpnL != persistedBP.bpnL ||
Expand Down Expand Up @@ -245,6 +247,8 @@ class BusinessPartnerService(
stage = fromPartner.stage
shortName = fromPartner.shortName
legalName = fromPartner.legalName
siteName = fromPartner.siteName
addressName = fromPartner.addressName
legalForm = fromPartner.legalForm
isOwnCompanyData = fromPartner.isOwnCompanyData
bpnL = fromPartner.bpnL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class OrchestratorMappings(
ownerBpnL = getOwnerBpnL(entity),
legalEntity = toLegalEntityComponentDto(entity),
site = toSiteComponentDto(entity),
address = toAddressComponentDto(entity.bpnA, entity.postalAddress)
address = toAddressComponentDto(entity)

)

Expand All @@ -60,13 +60,15 @@ class OrchestratorMappings(

private fun toSiteComponentDto(entity: BusinessPartner) = SiteRepresentation(
siteBpn = entity.bpnS,
name = entity.siteName
)

private fun toAddressComponentDto(bpnA: String?, entity: PostalAddress) = AddressRepresentation(
addressBpn = bpnA,
addressType = entity.addressType,
physicalPostalAddress = entity.physicalPostalAddress?.let(::toPhysicalPostalAddressDto),
alternativePostalAddress = entity.alternativePostalAddress?.let(this::toAlternativePostalAddressDto)
private fun toAddressComponentDto(entity: BusinessPartner) = AddressRepresentation(
addressBpn = entity.bpnA,
name = entity.addressName,
addressType = entity.postalAddress.addressType,
physicalPostalAddress = entity.postalAddress.physicalPostalAddress?.let(::toPhysicalPostalAddressDto),
alternativePostalAddress = entity.postalAddress.alternativePostalAddress?.let(this::toAlternativePostalAddressDto)
)

private fun toClassificationDto(entity: Classification) =
Expand Down Expand Up @@ -150,6 +152,8 @@ class OrchestratorMappings(
shortName = dto.legalEntity.shortName,
identifiers = dto.identifiers.mapNotNull { toIdentifier(it) }.toSortedSet(),
legalName = dto.legalEntity.legalName,
siteName = dto.site.name,
addressName = dto.address.name,
legalForm = dto.legalEntity.legalForm,
states = dto.states.mapNotNull { toState(it) }.toSortedSet(),
classifications = dto.legalEntity.classifications.map { toClassification(it) }.toSortedSet(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE business_partners
ADD COLUMN site_name VARCHAR(255);

ALTER TABLE business_partners
ADD COLUMN address_name VARCHAR(255);
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ internal class BusinessPartnerIT @Autowired constructor(
nameParts = mutableListOf("testNameParts", "testNameParts2", "testNameParts3", "testNameParts4", "testNameParts5"),
shortName = "testShortName",
legalName = "testLegalName",
siteName = "testSiteName",
addressName = "testAddressName",
legalForm = "testLegalForm",
isOwnCompanyData = true,
bpnA = "testAddressBpn",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ object BusinessPartnerGenericValues {
),
site = SiteRepresentation(
siteBpn = "000000123BBB222",
name = "Site Name"
),
address = AddressRepresentation(
addressBpn = "000000123CCC333",
name = "Address Name",
addressType = AddressType.AdditionalAddress,
physicalPostalAddress = PhysicalPostalAddressDto(
geographicCoordinates = GeoCoordinateDto(0.5f, 0.5f, 0.5f),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ object BusinessPartnerNonVerboseValues {

val bpPostalAddressInputDtoMinimal = AddressRepresentationInputDto(
addressType = null,
name = null,
physicalPostalAddress = physicalAddressMinimal
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,12 @@ object BusinessPartnerVerboseValues {
classifications = listOf(bpClassification1, bpClassification2, bpClassification3)
),
site = SiteRepresentationInputDto(
siteBpn = null
siteBpn = null,
name = "Site Name"
),
address = AddressRepresentationInputDto(
addressBpn = "BPNA0000000001XY",
name = "Address Name",
addressType = AddressType.LegalAddress,
physicalPostalAddress = postalAddress2,
alternativePostalAddress = alternativeAddressFull
Expand Down Expand Up @@ -622,9 +624,11 @@ object BusinessPartnerVerboseValues {
),
site = SiteRepresentationInputDto(
siteBpn = "BPNS0000000003X9",
name = "Site Name 3"
),
address = AddressRepresentationInputDto(
addressBpn = "BPNA0000000001XY",
name = "Address Name 3",
addressType = AddressType.LegalAndSiteMainAddress,
physicalPostalAddress = physicalAddressChina,
alternativePostalAddress = AlternativePostalAddressDto()
Expand All @@ -651,9 +655,11 @@ object BusinessPartnerVerboseValues {
),
site = SiteRepresentationInputDto(
siteBpn = "BPNS0000000003X9",
name = "Site Name 4"
),
address = AddressRepresentationInputDto(
addressBpn = "BPNA0000000001XY",
name = "Address Name 4",
addressType = AddressType.LegalAddress,
physicalPostalAddress = postalAddress2,
alternativePostalAddress = alternativeAddressFull
Expand All @@ -680,9 +686,11 @@ object BusinessPartnerVerboseValues {
),
site = SiteRepresentationInputDto(
siteBpn = "BPNS0000000003X9",
name = "Site Name 5"
),
address = AddressRepresentationInputDto(
addressBpn = "BPNA0000000001XY",
name = "Address Name 5",
addressType = AddressType.LegalAddress,
physicalPostalAddress = postalAddress2,
alternativePostalAddress = alternativeAddressFull
Expand Down Expand Up @@ -741,10 +749,12 @@ object BusinessPartnerVerboseValues {
)
),
site = SiteRepresentationOutputDto(
siteBpn = "000000123BBB222"
siteBpn = "000000123BBB222",
name = "Site Name"
),
address = AddressComponentOutputDto(
addressBpn = "000000123CCC333",
name = "Address Name",
addressType = AddressType.AdditionalAddress,
physicalPostalAddress = PhysicalPostalAddressDto(
geographicCoordinates = GeoCoordinateDto(0.5f, 0.5f, 0.5f),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ data class LegalEntityRepresentation(
) : IBaseLegalEntityRepresentation

data class SiteRepresentation(
override val siteBpn: String? = null
override val siteBpn: String? = null,
override val name: String? = null
) : IBaseSiteRepresentation

data class AddressRepresentation(
override val addressBpn: String? = null,
override val name: String? = null,
override val addressType: AddressType? = null,
override val physicalPostalAddress: PhysicalPostalAddressDto? = null,
override val alternativePostalAddress: AlternativePostalAddressDto? = null
override val alternativePostalAddress: AlternativePostalAddressDto? = null,
) : IBaseAddressRepresentation


Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ object BusinessPartnerTestValues {
)
),
site = SiteRepresentation(
siteBpn = "BPNSTEST"
siteBpn = "BPNSTEST",
name = "site name"
),
address = AddressRepresentation(
addressBpn = "BPNATEST",
name = "address name",
addressType = AddressType.AdditionalAddress,
physicalPostalAddress = PhysicalPostalAddressDto(
geographicCoordinates = GeoCoordinateDto(0.5f, 0.5f, 0.5f),
Expand Down Expand Up @@ -167,10 +169,12 @@ object BusinessPartnerTestValues {
)
),
site = SiteRepresentation(
siteBpn = "BPNSTEST-2"
siteBpn = "BPNSTEST-2",
name = "site name 2"
),
address = AddressRepresentation(
addressBpn = "BPNATEST-2",
name = "address name 2",
addressType = AddressType.LegalAddress,
physicalPostalAddress = PhysicalPostalAddressDto(
geographicCoordinates = GeoCoordinateDto(0.4f, 0.4f, 0.4f),
Expand Down

0 comments on commit 0d670d5

Please sign in to comment.