Skip to content

Commit

Permalink
Merge pull request #482 from catenax-ng/feat/gate_mandatory_fields
Browse files Browse the repository at this point in the history
Feat: Make fields in Business Partner Input optional
  • Loading branch information
nicoprow authored Sep 25, 2023
2 parents c1a1684 + ec261f7 commit e812c1e
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,51 @@ 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(
name = gateDto.nameParts.firstOrNull(),
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,
Expand Down Expand Up @@ -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)
)
}

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!!
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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<BusinessPartnerRole> = emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -40,7 +40,7 @@ data class BusinessPartnerInputRequest(
override val states: Collection<BusinessPartnerStateDto> = emptyList(),
override val classifications: Collection<ClassificationDto> = emptyList(),
override val roles: Collection<BusinessPartnerRole> = 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = emptyList(),
Expand All @@ -39,7 +43,7 @@ data class BusinessPartnerInputDto(
override val states: Collection<BusinessPartnerStateDto> = emptyList(),
override val classifications: Collection<ClassificationDto> = emptyList(),
override val roles: Collection<BusinessPartnerRole> = emptyList(),
override val postalAddress: BusinessPartnerPostalAddressInputDto,
override val postalAddress: BusinessPartnerPostalAddressDto,
override val isOwner: Boolean,
override val bpnL: String?,
override val bpnS: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = emptyList(),
Expand All @@ -39,7 +42,7 @@ data class BusinessPartnerOutputDto(
override val states: Collection<BusinessPartnerStateDto> = emptyList(),
override val classifications: Collection<ClassificationDto> = emptyList(),
override val roles: Collection<BusinessPartnerRole> = emptyList(),
override val postalAddress: BusinessPartnerPostalAddressOutputDto,
override val postalAddress: BusinessPartnerPostalAddressDto,
override val isOwner: Boolean,
override val bpnL: String,
override val bpnS: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AlternativePostalAddress(

@Column(name = "alt_country")
@Enumerated(EnumType.STRING)
val country: CountryCode,
val country: CountryCode?,

/**
* Region within the country
Expand All @@ -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
Expand All @@ -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?
)
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PhysicalPostalAddress(

@Column(name = "phy_country")
@Enumerated(EnumType.STRING)
val country: CountryCode,
val country: CountryCode?,

/**
* Region within the country
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class PostalAddress(
var addressType: AddressType?,

@Embedded
var physicalPostalAddress: PhysicalPostalAddress,
var physicalPostalAddress: PhysicalPostalAddress?,

@Embedded
var alternativePostalAddress: AlternativePostalAddress?
Expand Down
Loading

0 comments on commit e812c1e

Please sign in to comment.