From 3e0d8dd1488155e1121aacf6507c67cc60c4b561 Mon Sep 17 00:00:00 2001 From: Martin Kaeser Date: Wed, 20 Sep 2023 15:10:54 +0200 Subject: [PATCH 1/3] feat(generic bp model): DTO model changes - optional BPN fields for input - bpnL/S/A naming - fixed assigment for isOwner, addressType --- .../gate/api/model/IBaseBusinessPartnerDto.kt | 9 ++++++ .../request/BusinessPartnerInputRequest.kt | 6 +++- .../model/response/BusinessPartnerInputDto.kt | 8 ++++-- .../response/BusinessPartnerOutputDto.kt | 15 ++++------ .../gate/service/BusinessPartnerMappings.kt | 28 +++++++++++-------- 5 files changed, 42 insertions(+), 24 deletions(-) diff --git a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/IBaseBusinessPartnerDto.kt b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/IBaseBusinessPartnerDto.kt index 7b0d463aa..eb487f2cf 100644 --- a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/IBaseBusinessPartnerDto.kt +++ b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/IBaseBusinessPartnerDto.kt @@ -53,4 +53,13 @@ interface IBaseBusinessPartnerDto { @get:Schema(name = "isOwner", description = "True if the sharing member declares itself as the owner of the business partner.") val isOwner: Boolean + + @get:Schema(description = "BPNL") + val bpnL: String? + + @get:Schema(description = "BPNS") + val bpnS: String? + + @get:Schema(description = "BPNA") + val bpnA: String? } diff --git a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/request/BusinessPartnerInputRequest.kt b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/request/BusinessPartnerInputRequest.kt index 1e6ae8a08..b86a317e9 100644 --- a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/request/BusinessPartnerInputRequest.kt +++ b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/request/BusinessPartnerInputRequest.kt @@ -41,6 +41,10 @@ data class BusinessPartnerInputRequest( @get:Schema(description = "Address of the official seat of this business partner.") val postalAddress: BusinessPartnerPostalAddressInputDto, - override val isOwner: Boolean = false + override val isOwner: Boolean = false, + + override val bpnL: String? = null, + override val bpnS: String? = null, + override val bpnA: String? = null ) : IBaseBusinessPartnerDto diff --git a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/response/BusinessPartnerInputDto.kt b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/response/BusinessPartnerInputDto.kt index f7a7062c4..e783523ba 100644 --- a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/response/BusinessPartnerInputDto.kt +++ b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/response/BusinessPartnerInputDto.kt @@ -42,10 +42,14 @@ data class BusinessPartnerInputDto( override val isOwner: Boolean, + override val bpnL: String?, + override val bpnS: String?, + override val bpnA: String?, + @get:Schema(description = CommonDescription.createdAt) val createdAt: Instant, @get:Schema(description = CommonDescription.updatedAt) - val updatedAt: Instant, + val updatedAt: Instant - ) : IBaseBusinessPartnerDto +) : IBaseBusinessPartnerDto diff --git a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/response/BusinessPartnerOutputDto.kt b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/response/BusinessPartnerOutputDto.kt index e736caa79..b1490aa9e 100644 --- a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/response/BusinessPartnerOutputDto.kt +++ b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/response/BusinessPartnerOutputDto.kt @@ -42,19 +42,14 @@ data class BusinessPartnerOutputDto( override val isOwner: Boolean, - @get:Schema(description = "BPNA") - val bpna: String, - - @get:Schema(description = "BPNS") - val bpns: String?, - - @get:Schema(description = "BPNL") - val bpnl: String, + override val bpnL: String, + override val bpnS: String?, + override val bpnA: String, @get:Schema(description = CommonDescription.createdAt) val createdAt: Instant, @get:Schema(description = CommonDescription.updatedAt) - val updatedAt: Instant, + val updatedAt: Instant - ) : IBaseBusinessPartnerDto +) : IBaseBusinessPartnerDto diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/BusinessPartnerMappings.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/BusinessPartnerMappings.kt index 516187ba4..a09524564 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/BusinessPartnerMappings.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/BusinessPartnerMappings.kt @@ -43,13 +43,16 @@ class BusinessPartnerMappings { externalId = entity.externalId, nameParts = entity.nameParts, shortName = entity.shortName, - legalForm = entity.legalForm, identifiers = entity.identifiers.map(::toIdentifierDto), + legalForm = entity.legalForm, states = entity.states.map(::toStateDto), classifications = entity.classifications.map(::toClassificationDto), roles = entity.roles, postalAddress = toPostalAddressInputDto(entity.postalAddress), - isOwner = entity.isOwner ?: false, // TODO should be mandatory in entity + isOwner = entity.isOwner, + bpnL = entity.bpnL, + bpnS = entity.bpnS, + bpnA = entity.bpnA, createdAt = entity.createdAt, updatedAt = entity.updatedAt ) @@ -60,16 +63,16 @@ class BusinessPartnerMappings { externalId = entity.externalId, nameParts = entity.nameParts, shortName = entity.shortName, - legalForm = entity.legalForm, identifiers = entity.identifiers.map(::toIdentifierDto), + legalForm = entity.legalForm, states = entity.states.map(::toStateDto), classifications = entity.classifications.map(::toClassificationDto), roles = entity.roles, postalAddress = toPostalAddressOutputDto(entity.postalAddress), - isOwner = entity.isOwner ?: false, // TODO should be mandatory in entity - bpnl = entity.bpnL ?: throw NullPointerException("bpnL is null"), - bpns = entity.bpnS, - bpna = entity.bpnA ?: throw NullPointerException("bpnA is null"), + isOwner = entity.isOwner, + bpnL = entity.bpnL ?: throw NullPointerException("bpnL is null"), + bpnS = entity.bpnS, + bpnA = entity.bpnA ?: throw NullPointerException("bpnA is null"), createdAt = entity.createdAt, updatedAt = entity.updatedAt ) @@ -87,9 +90,9 @@ class BusinessPartnerMappings { shortName = dto.shortName, legalForm = dto.legalForm, isOwner = dto.isOwner, - bpnL = null, - bpnS = null, - bpnA = null, + bpnL = dto.bpnL, + bpnS = dto.bpnS, + bpnA = dto.bpnA, postalAddress = toPostalAddress(dto.postalAddress) ) } @@ -103,6 +106,9 @@ class BusinessPartnerMappings { entity.shortName = dto.shortName entity.legalForm = dto.legalForm entity.isOwner = dto.isOwner + entity.bpnL = dto.bpnL + entity.bpnS = dto.bpnS + entity.bpnA = dto.bpnA updatePostalAddress(entity.postalAddress, dto.postalAddress) } @@ -122,7 +128,7 @@ class BusinessPartnerMappings { private fun toPostalAddress(dto: BusinessPartnerPostalAddressInputDto) = PostalAddress( - addressType = dto.addressType ?: AddressType.AdditionalAddress, // TODO should be optional in entity + addressType = dto.addressType, physicalPostalAddress = dto.physicalPostalAddress.let(::toPhysicalPostalAddress), alternativePostalAddress = dto.alternativePostalAddress?.let(::toAlternativePostalAddress) ) From 93f6df6d6f7b08fd4d322eb25d4ecefb4eca65bc Mon Sep 17 00:00:00 2001 From: Martin Kaeser Date: Wed, 20 Sep 2023 15:30:03 +0200 Subject: [PATCH 2/3] feat(generic bp model): DTO model changes - improved OpenAPI description --- .../bpdm/gate/api/model/IBaseBusinessPartnerDto.kt | 12 ++++++------ .../api/model/response/BusinessPartnerOutputDto.kt | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/IBaseBusinessPartnerDto.kt b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/IBaseBusinessPartnerDto.kt index eb487f2cf..aec5bc18e 100644 --- a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/IBaseBusinessPartnerDto.kt +++ b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/IBaseBusinessPartnerDto.kt @@ -30,25 +30,25 @@ interface IBaseBusinessPartnerDto { @get:Schema(description = CommonDescription.externalId) val externalId: String - @get:Schema(description = "") + @get:ArraySchema(arraySchema = Schema(description = "The list of name parts to accommodate the different number of name fields in different systems.")) val nameParts: List - @get:Schema(description = "Abbreviated name or shorthand") + @get:Schema(description = "Abbreviated name or shorthand.") val shortName: String? - @get:ArraySchema(arraySchema = Schema(description = "The list of identifiers of the business partner.")) + @get:ArraySchema(arraySchema = Schema(description = "The list of identifiers of the business partner. Sorted and duplicates are removed.")) val identifiers: Collection @get:Schema(description = "Technical key of the legal form.") val legalForm: String? - @get:ArraySchema(arraySchema = Schema(description = "The list of (temporary) states of the business partner.")) + @get:ArraySchema(arraySchema = Schema(description = "The list of (temporary) states of the business partner. Sorted and duplicates are removed.")) val states: Collection - @get:ArraySchema(arraySchema = Schema(description = "The list of classifications of the legal entity, such as a specific industry.")) + @get:ArraySchema(arraySchema = Schema(description = "The list of classifications of the business partner, such as a specific industry. Sorted and duplicates are removed.")) val classifications: Collection - @get:ArraySchema(arraySchema = Schema(description = CommonDescription.roles)) + @get:ArraySchema(arraySchema = Schema(description = "Roles this business partner takes in relation to the sharing member. Sorted and duplicates are removed.")) val roles: Collection @get:Schema(name = "isOwner", description = "True if the sharing member declares itself as the owner of the business partner.") diff --git a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/response/BusinessPartnerOutputDto.kt b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/response/BusinessPartnerOutputDto.kt index b1490aa9e..e4559e855 100644 --- a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/response/BusinessPartnerOutputDto.kt +++ b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/response/BusinessPartnerOutputDto.kt @@ -26,7 +26,7 @@ import org.eclipse.tractusx.bpdm.gate.api.model.* import java.time.Instant -@Schema(description = "Generic business partner output with external id", requiredProperties = ["externalId", "postalAddress", "bpna", "bpnl"]) +@Schema(description = "Generic business partner output with external id", requiredProperties = ["externalId", "postalAddress", "bpnL", "bpnA"]) data class BusinessPartnerOutputDto( override val externalId: String, override val nameParts: List = emptyList(), From e9f06af57c2d604ce7c29da0a07b5891e04ec37b Mon Sep 17 00:00:00 2001 From: Martin Kaeser Date: Thu, 21 Sep 2023 09:25:20 +0200 Subject: [PATCH 3/3] feat(generic bp model): DTO model changes - improved OpenAPI description & error handling --- .../bpdm/gate/api/model/IBaseBusinessPartnerDto.kt | 8 ++++---- .../tractusx/bpdm/gate/service/BusinessPartnerMappings.kt | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/IBaseBusinessPartnerDto.kt b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/IBaseBusinessPartnerDto.kt index aec5bc18e..b9bf812f5 100644 --- a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/IBaseBusinessPartnerDto.kt +++ b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/IBaseBusinessPartnerDto.kt @@ -36,19 +36,19 @@ interface IBaseBusinessPartnerDto { @get:Schema(description = "Abbreviated name or shorthand.") val shortName: String? - @get:ArraySchema(arraySchema = Schema(description = "The list of identifiers of the business partner. Sorted and duplicates are removed.")) + @get:ArraySchema(arraySchema = Schema(description = "The list of identifiers of the business partner. Sorted and duplicates removed by the service.")) val identifiers: Collection @get:Schema(description = "Technical key of the legal form.") val legalForm: String? - @get:ArraySchema(arraySchema = Schema(description = "The list of (temporary) states of the business partner. Sorted and duplicates are removed.")) + @get:ArraySchema(arraySchema = Schema(description = "The list of (temporary) states of the business partner. Sorted and duplicates removed by the service.")) val states: Collection - @get:ArraySchema(arraySchema = Schema(description = "The list of classifications of the business partner, such as a specific industry. Sorted and duplicates are removed.")) + @get:ArraySchema(arraySchema = Schema(description = "The list of classifications of the business partner, such as a specific industry. Sorted and duplicates removed by the service.")) val classifications: Collection - @get:ArraySchema(arraySchema = Schema(description = "Roles this business partner takes in relation to the sharing member. Sorted and duplicates are removed.")) + @get:ArraySchema(arraySchema = Schema(description = "Roles this business partner takes in relation to the sharing member. Sorted and duplicates removed by the service.")) val roles: Collection @get:Schema(name = "isOwner", description = "True if the sharing member declares itself as the owner of the business partner.") diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/BusinessPartnerMappings.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/BusinessPartnerMappings.kt index a09524564..fe0aa93f1 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/BusinessPartnerMappings.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/BusinessPartnerMappings.kt @@ -22,6 +22,7 @@ package org.eclipse.tractusx.bpdm.gate.service import org.eclipse.tractusx.bpdm.common.dto.AlternativePostalAddressDto import org.eclipse.tractusx.bpdm.common.dto.ClassificationDto import org.eclipse.tractusx.bpdm.common.dto.GeoCoordinateDto +import org.eclipse.tractusx.bpdm.common.exception.BpdmNullMappingException import org.eclipse.tractusx.bpdm.common.model.StageType import org.eclipse.tractusx.bpdm.common.util.replace import org.eclipse.tractusx.bpdm.gate.api.model.* @@ -70,9 +71,11 @@ class BusinessPartnerMappings { roles = entity.roles, postalAddress = toPostalAddressOutputDto(entity.postalAddress), isOwner = entity.isOwner, - bpnL = entity.bpnL ?: throw NullPointerException("bpnL is null"), + bpnL = entity.bpnL + ?: throw BpdmNullMappingException(BusinessPartner::class, BusinessPartnerOutputDto::class, BusinessPartner::bpnL, entity.externalId), bpnS = entity.bpnS, - bpnA = entity.bpnA ?: throw NullPointerException("bpnA is null"), + bpnA = entity.bpnA + ?: throw BpdmNullMappingException(BusinessPartner::class, BusinessPartnerOutputDto::class, BusinessPartner::bpnA, entity.externalId), createdAt = entity.createdAt, updatedAt = entity.updatedAt )