From ec261f72de6c5f0ae83e0a9773f45776968e31a2 Mon Sep 17 00:00:00 2001 From: Martin Kaeser Date: Thu, 21 Sep 2023 16:39:50 +0200 Subject: [PATCH] feat(generic bp model): Make fields in Business Partner Input optional --- .../bridge/dummy/dto/DtoConversionHelper.kt | 39 +++++++++++--- .../bridge/dummy/service/PoolUpdateService.kt | 4 +- .../model/AlternativePostalAddressGateDto.kt | 51 ++++++++++++++++++ ....kt => BusinessPartnerPostalAddressDto.kt} | 11 ++-- .../gate/api/model/LogisticAddressGateDto.kt | 3 +- .../api/model/PhysicalPostalAddressGateDto.kt | 33 ++++++------ .../request/BusinessPartnerInputRequest.kt | 6 +-- .../model/response/BusinessPartnerInputDto.kt | 10 ++-- .../response/BusinessPartnerOutputDto.kt | 9 ++-- .../gate/entity/AlternativePostalAddress.kt | 9 ++-- .../bpdm/gate/entity/PhysicalPostalAddress.kt | 5 +- .../bpdm/gate/entity/generic/PostalAddress.kt | 2 +- .../gate/service/BusinessPartnerMappings.kt | 53 ++++++++++--------- .../bpdm/gate/service/ResponseMappings.kt | 6 +-- ...15__make_postal_adress_fields_nullable.sql | 5 ++ .../gate/entity/generic/BusinessPartnerIT.kt | 6 +-- 16 files changed, 170 insertions(+), 82 deletions(-) create mode 100644 bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/AlternativePostalAddressGateDto.kt rename bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/{BusinessPartnerPostalAddressOutputDto.kt => BusinessPartnerPostalAddressDto.kt} (81%) create mode 100644 bpdm-gate/src/main/resources/db/migration/V4_0_0_15__make_postal_adress_fields_nullable.sql diff --git a/bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/dto/DtoConversionHelper.kt b/bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/dto/DtoConversionHelper.kt index 880192c68..8ca6378a9 100644 --- a/bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/dto/DtoConversionHelper.kt +++ b/bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/dto/DtoConversionHelper.kt @@ -21,7 +21,9 @@ package com.catenax.bpdm.bridge.dummy.dto import org.eclipse.tractusx.bpdm.common.dto.* import org.eclipse.tractusx.bpdm.common.dto.response.* +import org.eclipse.tractusx.bpdm.common.exception.BpdmNullMappingException import org.eclipse.tractusx.bpdm.gate.api.model.* +import kotlin.reflect.KProperty fun gateToPoolLogisticAddress(gateDto: LogisticAddressGateDto): LogisticAddressDto { return LogisticAddressDto( @@ -29,16 +31,41 @@ fun gateToPoolLogisticAddress(gateDto: LogisticAddressGateDto): LogisticAddressD states = gateDto.states, identifiers = gateDto.identifiers, physicalPostalAddress = gateToPoolPhysicalAddress(gateDto.physicalPostalAddress), - alternativePostalAddress = gateDto.alternativePostalAddress + alternativePostalAddress = gateDto.alternativePostalAddress?.let(::gateToPoolAlternativeAddress) + ) +} + +fun gateToPoolAlternativeAddress(gateDto: AlternativePostalAddressGateDto): AlternativePostalAddressDto { + fun buildNullMappingException(nullField: KProperty<*>) = + BpdmNullMappingException(AlternativePostalAddressGateDto::class, AlternativePostalAddressDto::class, nullField) + + return AlternativePostalAddressDto( + geographicCoordinates = gateDto.geographicCoordinates, + country = gateDto.country + ?: throw buildNullMappingException(AlternativePostalAddressGateDto::country), + administrativeAreaLevel1 = gateDto.administrativeAreaLevel1, + postalCode = gateDto.postalCode, + city = gateDto.city + ?: throw buildNullMappingException(AlternativePostalAddressGateDto::city), + deliveryServiceType = gateDto.deliveryServiceType + ?: throw buildNullMappingException(AlternativePostalAddressGateDto::deliveryServiceType), + deliveryServiceQualifier = gateDto.deliveryServiceQualifier, + deliveryServiceNumber = gateDto.deliveryServiceNumber + ?: throw buildNullMappingException(AlternativePostalAddressGateDto::deliveryServiceNumber) ) } fun gateToPoolPhysicalAddress(gateDto: PhysicalPostalAddressGateDto): PhysicalPostalAddressDto { + fun buildNullMappingException(nullField: KProperty<*>) = + BpdmNullMappingException(PhysicalPostalAddressGateDto::class, PhysicalPostalAddressDto::class, nullField) + return PhysicalPostalAddressDto( geographicCoordinates = gateDto.geographicCoordinates, - country = gateDto.country, + country = gateDto.country + ?: throw buildNullMappingException(PhysicalPostalAddressGateDto::country), postalCode = gateDto.postalCode, - city = gateDto.city, + city = gateDto.city + ?: throw buildNullMappingException(PhysicalPostalAddressGateDto::city), administrativeAreaLevel1 = gateDto.administrativeAreaLevel1, administrativeAreaLevel2 = gateDto.administrativeAreaLevel2, administrativeAreaLevel3 = gateDto.administrativeAreaLevel3, @@ -132,7 +159,7 @@ fun poolToGateLogisticAddress(address: LogisticAddressVerboseDto): LogisticAddre states = states, identifiers = identifiers, physicalPostalAddress = poolToGatePhysicalAddress(address.physicalPostalAddress), - alternativePostalAddress = address.alternativePostalAddress?.let { poolToGateAlternativeAddress(it) } + alternativePostalAddress = address.alternativePostalAddress?.let(::poolToGateAlternativeAddress) ) } @@ -163,8 +190,8 @@ private fun poolToGatePhysicalAddress(address: PhysicalPostalAddressVerboseDto): ) } -private fun poolToGateAlternativeAddress(address: AlternativePostalAddressVerboseDto): AlternativePostalAddressDto { - return AlternativePostalAddressDto( +private fun poolToGateAlternativeAddress(address: AlternativePostalAddressVerboseDto): AlternativePostalAddressGateDto { + return AlternativePostalAddressGateDto( geographicCoordinates = address.geographicCoordinates, country = address.country.technicalKey, postalCode = address.postalCode, 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 aca5820e5..5bdae2ed4 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 @@ -141,7 +141,7 @@ class PoolUpdateService( states = entry.address.states, identifiers = entry.address.identifiers, physicalPostalAddress = gateToPoolPhysicalAddress(entry.address.physicalPostalAddress), - alternativePostalAddress = entry.address.alternativePostalAddress + alternativePostalAddress = entry.address.alternativePostalAddress?.let(::gateToPoolAlternativeAddress) ), index = entry.externalId, bpnParent = siteParentBpn @@ -181,7 +181,7 @@ class PoolUpdateService( states = it.address.states, identifiers = it.address.identifiers, physicalPostalAddress = gateToPoolPhysicalAddress(it.address.physicalPostalAddress), - alternativePostalAddress = it.address.alternativePostalAddress + alternativePostalAddress = it.address.alternativePostalAddress?.let(::gateToPoolAlternativeAddress) ), bpna = it.bpn!! ) diff --git a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/AlternativePostalAddressGateDto.kt b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/AlternativePostalAddressGateDto.kt new file mode 100644 index 000000000..a29fa69fd --- /dev/null +++ b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/AlternativePostalAddressGateDto.kt @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ******************************************************************************/ + +package org.eclipse.tractusx.bpdm.gate.api.model + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.neovisionaries.i18n.CountryCode +import io.swagger.v3.oas.annotations.media.Schema +import org.eclipse.tractusx.bpdm.common.dto.GeoCoordinateDto +import org.eclipse.tractusx.bpdm.common.dto.IBaseAlternativePostalAddressDto +import org.eclipse.tractusx.bpdm.common.dto.openapidescription.PostalAddressDescription +import org.eclipse.tractusx.bpdm.common.model.DeliveryServiceType +import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializer + +@JsonDeserialize(using = DataClassUnwrappedJsonDeserializer::class) +@Schema(description = PostalAddressDescription.headerAlternative) +data class AlternativePostalAddressGateDto( + + override val geographicCoordinates: GeoCoordinateDto? = null, + + override val country: CountryCode? = null, + + override val administrativeAreaLevel1: String? = null, + + override val postalCode: String? = null, + + override val city: String? = null, + + override val deliveryServiceType: DeliveryServiceType? = null, + + override val deliveryServiceQualifier: String? = null, + + override val deliveryServiceNumber: String? = null + +) : IBaseAlternativePostalAddressDto diff --git a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/BusinessPartnerPostalAddressOutputDto.kt b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/BusinessPartnerPostalAddressDto.kt similarity index 81% rename from bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/BusinessPartnerPostalAddressOutputDto.kt rename to bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/BusinessPartnerPostalAddressDto.kt index 2060b69f7..78a46f5bd 100644 --- a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/BusinessPartnerPostalAddressOutputDto.kt +++ b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/BusinessPartnerPostalAddressDto.kt @@ -21,14 +21,13 @@ package org.eclipse.tractusx.bpdm.gate.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.AlternativePostalAddressDto import org.eclipse.tractusx.bpdm.common.dto.IBaseBusinessPartnerPostalAddressDto -@Schema(description = "Postal address of a output business partner", requiredProperties = ["physicalPostalAddress"]) -data class BusinessPartnerPostalAddressOutputDto( +@Schema(description = "Postal address of a business partner") +data class BusinessPartnerPostalAddressDto( - override val addressType: AddressType, - override val physicalPostalAddress: PhysicalPostalAddressGateDto, - override val alternativePostalAddress: AlternativePostalAddressDto? = null + override val addressType: AddressType? = null, + override val physicalPostalAddress: PhysicalPostalAddressGateDto? = null, + override val alternativePostalAddress: AlternativePostalAddressGateDto? = null ) : IBaseBusinessPartnerPostalAddressDto diff --git a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/LogisticAddressGateDto.kt b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/LogisticAddressGateDto.kt index 5b728763d..55c0ae6ac 100644 --- a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/LogisticAddressGateDto.kt +++ b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/LogisticAddressGateDto.kt @@ -23,7 +23,6 @@ import io.swagger.v3.oas.annotations.media.ArraySchema import io.swagger.v3.oas.annotations.media.Schema import org.eclipse.tractusx.bpdm.common.dto.AddressIdentifierDto import org.eclipse.tractusx.bpdm.common.dto.AddressStateDto -import org.eclipse.tractusx.bpdm.common.dto.AlternativePostalAddressDto import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerRole import org.eclipse.tractusx.bpdm.common.dto.openapidescription.LogisticAddressDescription @@ -45,7 +44,7 @@ data class LogisticAddressGateDto( // TODO OpenAPI description for complex field does not work!! @get:Schema(description = LogisticAddressDescription.alternativePostalAddress) - val alternativePostalAddress: AlternativePostalAddressDto? = null, + val alternativePostalAddress: AlternativePostalAddressGateDto? = null, @get:ArraySchema(arraySchema = Schema(description = LogisticAddressDescription.roles)) val roles: Collection = emptyList() diff --git a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/PhysicalPostalAddressGateDto.kt b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/PhysicalPostalAddressGateDto.kt index 98132567e..157e9265b 100644 --- a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/PhysicalPostalAddressGateDto.kt +++ b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/PhysicalPostalAddressGateDto.kt @@ -28,38 +28,35 @@ import org.eclipse.tractusx.bpdm.common.dto.openapidescription.PostalAddressDesc import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializer @JsonDeserialize(using = DataClassUnwrappedJsonDeserializer::class) -@Schema( - description = PostalAddressDescription.headerPhysical, - requiredProperties = ["country", "city"] -) +@Schema(description = PostalAddressDescription.headerPhysical) data class PhysicalPostalAddressGateDto( - override val geographicCoordinates: GeoCoordinateDto?, + override val geographicCoordinates: GeoCoordinateDto? = null, - override val country: CountryCode, + override val country: CountryCode? = null, - override val administrativeAreaLevel1: String?, + override val administrativeAreaLevel1: String? = null, - override val administrativeAreaLevel2: String?, + override val administrativeAreaLevel2: String? = null, - override val administrativeAreaLevel3: String?, + override val administrativeAreaLevel3: String? = null, - override val postalCode: String?, + override val postalCode: String? = null, - override val city: String, + override val city: String? = null, - override val district: String?, + override val district: String? = null, - override val street: StreetGateDto?, + override val street: StreetGateDto? = null, - override val companyPostalCode: String?, + override val companyPostalCode: String? = null, - override val industrialZone: String?, + override val industrialZone: String? = null, - override val building: String?, + override val building: String? = null, - override val floor: String?, + override val floor: String? = null, - override val door: String? + override val door: String? = null ) : IBasePhysicalPostalAddressDto 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 5210ca368..49cda910b 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 @@ -24,12 +24,12 @@ import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerIdentifierDto import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerRole import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerStateDto import org.eclipse.tractusx.bpdm.common.dto.ClassificationDto -import org.eclipse.tractusx.bpdm.gate.api.model.BusinessPartnerPostalAddressInputDto +import org.eclipse.tractusx.bpdm.gate.api.model.BusinessPartnerPostalAddressDto import org.eclipse.tractusx.bpdm.gate.api.model.IBaseBusinessPartnerGateDto @Schema( description = "Generic business partner with external id", - requiredProperties = ["externalId", "postalAddress"] + requiredProperties = ["externalId"] ) data class BusinessPartnerInputRequest( override val externalId: String, @@ -40,7 +40,7 @@ data class BusinessPartnerInputRequest( override val states: Collection = emptyList(), override val classifications: Collection = emptyList(), override val roles: Collection = emptyList(), - override val postalAddress: BusinessPartnerPostalAddressInputDto, + override val postalAddress: BusinessPartnerPostalAddressDto = BusinessPartnerPostalAddressDto(), override val isOwner: Boolean = false, override val bpnL: String? = null, override val bpnS: String? = null, 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 ebe7c82b1..7a3c7bbdc 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 @@ -25,11 +25,15 @@ import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerRole import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerStateDto import org.eclipse.tractusx.bpdm.common.dto.ClassificationDto import org.eclipse.tractusx.bpdm.common.dto.openapidescription.CommonDescription -import org.eclipse.tractusx.bpdm.gate.api.model.BusinessPartnerPostalAddressInputDto +import org.eclipse.tractusx.bpdm.gate.api.model.BusinessPartnerPostalAddressDto import org.eclipse.tractusx.bpdm.gate.api.model.IBaseBusinessPartnerGateDto import java.time.Instant -@Schema(description = "Generic business partner with external id", requiredProperties = ["externalId", "postalAddress"]) + +@Schema( + description = "Generic business partner with external id", + requiredProperties = ["externalId", "postalAddress"] +) data class BusinessPartnerInputDto( override val externalId: String, override val nameParts: List = emptyList(), @@ -39,7 +43,7 @@ data class BusinessPartnerInputDto( override val states: Collection = emptyList(), override val classifications: Collection = emptyList(), override val roles: Collection = emptyList(), - override val postalAddress: BusinessPartnerPostalAddressInputDto, + override val postalAddress: BusinessPartnerPostalAddressDto, override val isOwner: Boolean, override val bpnL: String?, override val bpnS: String?, 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 4716e47bf..be53e9cbb 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 @@ -25,11 +25,14 @@ import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerRole import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerStateDto import org.eclipse.tractusx.bpdm.common.dto.ClassificationDto import org.eclipse.tractusx.bpdm.common.dto.openapidescription.CommonDescription -import org.eclipse.tractusx.bpdm.gate.api.model.BusinessPartnerPostalAddressOutputDto +import org.eclipse.tractusx.bpdm.gate.api.model.BusinessPartnerPostalAddressDto import org.eclipse.tractusx.bpdm.gate.api.model.IBaseBusinessPartnerGateDto import java.time.Instant -@Schema(description = "Generic business partner output with external id", requiredProperties = ["externalId", "postalAddress", "bpnL", "bpnA"]) +@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(), @@ -39,7 +42,7 @@ data class BusinessPartnerOutputDto( override val states: Collection = emptyList(), override val classifications: Collection = emptyList(), override val roles: Collection = emptyList(), - override val postalAddress: BusinessPartnerPostalAddressOutputDto, + override val postalAddress: BusinessPartnerPostalAddressDto, override val isOwner: Boolean, override val bpnL: String, override val bpnS: String?, diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/AlternativePostalAddress.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/AlternativePostalAddress.kt index 538f63e2c..aaf8ff0e1 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/AlternativePostalAddress.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/AlternativePostalAddress.kt @@ -34,7 +34,7 @@ class AlternativePostalAddress( @Column(name = "alt_country") @Enumerated(EnumType.STRING) - val country: CountryCode, + val country: CountryCode?, /** * Region within the country @@ -51,16 +51,15 @@ class AlternativePostalAddress( /** * The city of the address (Synonym: Town, village, municipality) */ - // TODO Should it be optional? @Column(name = "alt_city") - val city: String, + val city: String?, /** * The type of this specified delivery */ @Column(name = "alt_delivery_service_type") @Enumerated(EnumType.STRING) - val deliveryServiceType: DeliveryServiceType, + val deliveryServiceType: DeliveryServiceType?, /** * The qualifier uniquely identifies the delivery service endpoint in conjunction with the delivery service number @@ -72,5 +71,5 @@ class AlternativePostalAddress( * Describes the PO Box or private Bag number the delivery should be placed at */ @Column(name = "alt_delivery_service_number") - val deliveryServiceNumber: String + val deliveryServiceNumber: String? ) diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/PhysicalPostalAddress.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/PhysicalPostalAddress.kt index 0efd37700..12ae6a9b5 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/PhysicalPostalAddress.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/PhysicalPostalAddress.kt @@ -33,7 +33,7 @@ class PhysicalPostalAddress( @Column(name = "phy_country") @Enumerated(EnumType.STRING) - val country: CountryCode, + val country: CountryCode?, /** * Region within the country @@ -62,9 +62,8 @@ class PhysicalPostalAddress( /** * The city of the address (Synonym: Town, village, municipality) */ - // TODO Should it be optional? @Column(name = "phy_city") - val city: String, + val city: String?, /** * Divides the city in several smaller areas diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/generic/PostalAddress.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/generic/PostalAddress.kt index ab1b9ab7d..891d1982d 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/generic/PostalAddress.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/generic/PostalAddress.kt @@ -34,7 +34,7 @@ class PostalAddress( var addressType: AddressType?, @Embedded - var physicalPostalAddress: PhysicalPostalAddress, + var physicalPostalAddress: PhysicalPostalAddress?, @Embedded var alternativePostalAddress: AlternativePostalAddress? 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 d03b9a610..cee706093 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 @@ -19,12 +19,15 @@ package org.eclipse.tractusx.bpdm.gate.service -import org.eclipse.tractusx.bpdm.common.dto.* +import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerIdentifierDto +import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerStateDto +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.BusinessPartnerPostalAddressInputDto -import org.eclipse.tractusx.bpdm.gate.api.model.BusinessPartnerPostalAddressOutputDto +import org.eclipse.tractusx.bpdm.gate.api.model.AlternativePostalAddressGateDto +import org.eclipse.tractusx.bpdm.gate.api.model.BusinessPartnerPostalAddressDto import org.eclipse.tractusx.bpdm.gate.api.model.PhysicalPostalAddressGateDto import org.eclipse.tractusx.bpdm.gate.api.model.StreetGateDto import org.eclipse.tractusx.bpdm.gate.api.model.request.BusinessPartnerInputRequest @@ -50,7 +53,7 @@ class BusinessPartnerMappings { states = entity.states.map(::toStateDto), classifications = entity.classifications.map(::toClassificationDto), roles = entity.roles, - postalAddress = toPostalAddressInputDto(entity.postalAddress), + postalAddress = toPostalAddressDto(entity.postalAddress), isOwner = entity.isOwner, bpnL = entity.bpnL, bpnS = entity.bpnS, @@ -70,7 +73,7 @@ class BusinessPartnerMappings { states = entity.states.map(::toStateDto), classifications = entity.classifications.map(::toClassificationDto), roles = entity.roles, - postalAddress = toPostalAddressOutputDto(entity.postalAddress), + postalAddress = toPostalAddressDto(entity.postalAddress), isOwner = entity.isOwner, bpnL = entity.bpnL ?: throw BpdmNullMappingException(BusinessPartner::class, BusinessPartnerOutputDto::class, BusinessPartner::bpnL, entity.externalId), @@ -116,31 +119,24 @@ class BusinessPartnerMappings { updatePostalAddress(entity.postalAddress, dto.postalAddress) } - private fun toPostalAddressInputDto(entity: PostalAddress) = - BusinessPartnerPostalAddressInputDto( + private fun toPostalAddressDto(entity: PostalAddress) = + BusinessPartnerPostalAddressDto( addressType = entity.addressType, - physicalPostalAddress = entity.physicalPostalAddress.let(::toPhysicalPostalAddressDto), + physicalPostalAddress = entity.physicalPostalAddress?.let(::toPhysicalPostalAddressDto), alternativePostalAddress = entity.alternativePostalAddress?.let(::toAlternativePostalAddressDto) ) - private fun toPostalAddressOutputDto(entity: PostalAddress) = - BusinessPartnerPostalAddressOutputDto( - addressType = entity.addressType!!, //An entity of stage output is expected to have a non-null addressType - physicalPostalAddress = entity.physicalPostalAddress.let(::toPhysicalPostalAddressDto), - alternativePostalAddress = entity.alternativePostalAddress?.let(::toAlternativePostalAddressDto) - ) - - private fun toPostalAddress(dto: BusinessPartnerPostalAddressInputDto) = + private fun toPostalAddress(dto: BusinessPartnerPostalAddressDto) = PostalAddress( addressType = dto.addressType, - physicalPostalAddress = dto.physicalPostalAddress.let(::toPhysicalPostalAddress), - alternativePostalAddress = dto.alternativePostalAddress?.let(::toAlternativePostalAddress) + physicalPostalAddress = normalize(dto.physicalPostalAddress)?.let(::toPhysicalPostalAddress), + alternativePostalAddress = normalize(dto.alternativePostalAddress)?.let(::toAlternativePostalAddress) ) - private fun updatePostalAddress(entity: PostalAddress, dto: BusinessPartnerPostalAddressInputDto) { - entity.addressType = dto.addressType ?: AddressType.AdditionalAddress - entity.physicalPostalAddress = dto.physicalPostalAddress.let(::toPhysicalPostalAddress) - entity.alternativePostalAddress = dto.alternativePostalAddress?.let(::toAlternativePostalAddress) + private fun updatePostalAddress(entity: PostalAddress, dto: BusinessPartnerPostalAddressDto) { + entity.addressType = dto.addressType + entity.physicalPostalAddress = normalize(dto.physicalPostalAddress)?.let(::toPhysicalPostalAddress) + entity.alternativePostalAddress = normalize(dto.alternativePostalAddress)?.let(::toAlternativePostalAddress) } private fun toPhysicalPostalAddressDto(entity: PhysicalPostalAddress) = @@ -161,6 +157,15 @@ class BusinessPartnerMappings { door = entity.door ) + // convert empty DTO to null + private fun normalize(dto: PhysicalPostalAddressGateDto?) = + if (dto != PhysicalPostalAddressGateDto()) dto + else null + + private fun normalize(dto: AlternativePostalAddressGateDto?) = + if (dto != AlternativePostalAddressGateDto()) dto + else null + private fun toPhysicalPostalAddress(dto: PhysicalPostalAddressGateDto) = PhysicalPostalAddress( geographicCoordinates = dto.geographicCoordinates?.let(::toGeographicCoordinate), @@ -180,7 +185,7 @@ class BusinessPartnerMappings { ) private fun toAlternativePostalAddressDto(entity: AlternativePostalAddress) = - AlternativePostalAddressDto( + AlternativePostalAddressGateDto( geographicCoordinates = entity.geographicCoordinates?.let(::toGeoCoordinateDto), country = entity.country, administrativeAreaLevel1 = entity.administrativeAreaLevel1, @@ -191,7 +196,7 @@ class BusinessPartnerMappings { deliveryServiceNumber = entity.deliveryServiceNumber ) - private fun toAlternativePostalAddress(dto: AlternativePostalAddressDto) = + private fun toAlternativePostalAddress(dto: AlternativePostalAddressGateDto) = AlternativePostalAddress( geographicCoordinates = dto.geographicCoordinates?.let(::toGeographicCoordinate), country = dto.country, diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/ResponseMappings.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/ResponseMappings.kt index b87ac0fed..9f1a4ad72 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/ResponseMappings.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/ResponseMappings.kt @@ -73,7 +73,7 @@ fun toNameParts(namePartsValue: String, address: LogisticAddress?, site: Site?, return NameParts(address, site, legalEntity, namePartsValue) } -fun AlternativePostalAddressDto.toAlternativePostalAddressEntity() = +fun AlternativePostalAddressGateDto.toAlternativePostalAddressEntity() = AlternativePostalAddress( geographicCoordinates = geographicCoordinates?.toGeographicCoordinateEntity(), country = country, @@ -308,8 +308,8 @@ fun mapToDtoStates(states: MutableSet): Collection