Skip to content

Commit

Permalink
Merge pull request #676 from catenax-ng/refactor/UnifyNormalVerboseDTOs
Browse files Browse the repository at this point in the history
Refactor: Unify DTOs for normal/verbose model
  • Loading branch information
nicoprow authored Dec 12, 2023
2 parents f2313c0 + 5a5d655 commit 4f6bc2a
Show file tree
Hide file tree
Showing 31 changed files with 249 additions and 257 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ fun poolToGateLegalEntity(legalEntity: LegalEntityVerboseDto): Gate_LegalEntityD
val identifiers = legalEntity.identifiers.map {
Gate_LegalEntityIdentifierDto(
value = it.value,
type = it.type.technicalKey,
type = it.typeVerbose.technicalKey,
issuingBody = it.issuingBody
)
}
Expand All @@ -178,20 +178,20 @@ fun poolToGateLegalEntity(legalEntity: LegalEntityVerboseDto): Gate_LegalEntityD
description = it.description,
validFrom = it.validFrom,
validTo = it.validTo,
type = it.type.technicalKey
type = it.typeVerbose.technicalKey
)
}
val classifications = legalEntity.classifications.map {
Gate_LegalEntityClassificationDto(
type = it.type.technicalKey,
type = it.typeVerbose.technicalKey,
code = it.code,
value = it.value
)
}
return Gate_LegalEntityDto(
legalNameParts = listOfNotNull(legalEntity.legalName),
legalShortName = legalEntity.legalShortName,
legalForm = legalEntity.legalForm?.technicalKey,
legalForm = legalEntity.legalFormVerbose?.technicalKey,
identifiers = identifiers,
states = states,
classifications = classifications
Expand All @@ -204,7 +204,7 @@ fun poolToGateSite(site: SiteVerboseDto): SiteGateDto {
description = it.description,
validFrom = it.validFrom,
validTo = it.validTo,
type = it.type.technicalKey
type = it.typeVerbose.technicalKey
)
}
return SiteGateDto(
Expand All @@ -226,13 +226,13 @@ fun poolToGateLogisticAddress(address: Pool_LogisticAddressVerboseDto): Gate_Log
description = it.description,
validFrom = it.validFrom,
validTo = it.validTo,
type = it.type.technicalKey
type = it.typeVerbose.technicalKey
)
}
val identifiers = address.identifiers.map {
Gate_AddressIdentifierDto(
value = it.value,
type = it.type.technicalKey
type = it.typeVerbose.technicalKey
)
}
return Gate_LogisticAddressDto(
Expand All @@ -255,10 +255,10 @@ private fun poolToGatePhysicalAddress(address: PhysicalPostalAddressVerboseDto):
}
return Gate_PhysicalPostalAddressDto(
geographicCoordinates = address.geographicCoordinates,
country = address.country.technicalKey,
country = address.country,
postalCode = address.postalCode,
city = address.city,
administrativeAreaLevel1 = address.administrativeAreaLevel1?.regionCode,
administrativeAreaLevel1 = address.administrativeAreaLevel1,
administrativeAreaLevel2 = address.administrativeAreaLevel2,
administrativeAreaLevel3 = address.administrativeAreaLevel3,
district = address.district,
Expand All @@ -274,10 +274,10 @@ private fun poolToGatePhysicalAddress(address: PhysicalPostalAddressVerboseDto):
private fun poolToGateAlternativeAddress(address: AlternativePostalAddressVerboseDto): org.eclipse.tractusx.bpdm.gate.api.model.AlternativePostalAddressDto {
return org.eclipse.tractusx.bpdm.gate.api.model.AlternativePostalAddressDto(
geographicCoordinates = address.geographicCoordinates,
country = address.country.technicalKey,
country = address.country,
postalCode = address.postalCode,
city = address.city,
administrativeAreaLevel1 = address.administrativeAreaLevel1?.regionCode,
administrativeAreaLevel1 = address.administrativeAreaLevel1,
deliveryServiceNumber = address.deliveryServiceNumber,
deliveryServiceType = address.deliveryServiceType,
deliveryServiceQualifier = address.deliveryServiceQualifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ interface IBaseAlternativePostalAddressDto {
val geographicCoordinates: GeoCoordinateDto?

@get:Schema(description = PostalAddressDescription.country)
val country: Any?
val country: CountryCode?

@get:Schema(description = PostalAddressDescription.administrativeAreaLevel1)
val administrativeAreaLevel1: Any?
val administrativeAreaLevel1: String?

@get:Schema(description = PostalAddressDescription.postalCode)
val postalCode: String?
Expand All @@ -52,8 +52,4 @@ interface IBaseAlternativePostalAddressDto {

@get:Schema(description = PostalAddressDescription.deliveryServiceNumber)
val deliveryServiceNumber: String?

fun adminLevel1Key(): String?

fun countryCode(): CountryCode?
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ interface IBasePhysicalPostalAddressDto {
val geographicCoordinates: GeoCoordinateDto?

@get:Schema(description = PostalAddressDescription.country)
val country: Any?
val country: CountryCode?

@get:Schema(description = PostalAddressDescription.administrativeAreaLevel1)
val administrativeAreaLevel1: Any?
val administrativeAreaLevel1: String?

@get:Schema(description = PostalAddressDescription.administrativeAreaLevel2)
val administrativeAreaLevel2: String?
Expand Down Expand Up @@ -69,8 +69,4 @@ interface IBasePhysicalPostalAddressDto {

@get:Schema(description = PostalAddressDescription.door)
val door: String?

fun adminLevel1Key(): String?

fun countryCode(): CountryCode?
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,4 @@ interface IBaseSiteDto {

@get:ArraySchema(arraySchema = Schema(description = SiteDescription.states))
val states: Collection<ISiteStateDto>

// TODO OpenAPI description for complex field does not work!!
@get:Schema(description = SiteDescription.mainAddress)
val mainAddress: IBaseLogisticAddressDto?
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.eclipse.tractusx.bpdm.common.service

import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonUnwrapped
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.*
Expand Down Expand Up @@ -58,15 +59,17 @@ private class DataClassUnwrappedJsonDeserializerForType(destinationJavaType: Jav
this.primaryConstructor = destinationClass.primaryConstructor
?: throw IllegalStateException("Primary constructor required for '$destinationClass'")

// Annotation @field:JsonUnwrapped is stored on the Java field, not the constructor parameter.
// Annotations @field:JsonUnwrapped and @field:JsonProperty are stored on the Java field, not the constructor parameter.
val propertiesByName = destinationClass.memberProperties.associateBy { it.name }

this.constructorParameters = primaryConstructor.parameters.map { param ->
val name = param.name
?: throw IllegalStateException("Some primary constructor parameter of '$destinationClass' doesn't have a name")
val type = param.type
val jsonUnwrapped = propertiesByName[name]?.javaField?.getAnnotation(JsonUnwrapped::class.java) != null
ConstructorParameter(name, type, jsonUnwrapped)
val altName = propertiesByName[name]?.javaField?.getAnnotation(JsonProperty::class.java)?.value
val finalName = if (altName.isNullOrEmpty()) name else altName
ConstructorParameter(finalName, type, jsonUnwrapped)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,4 @@ data class AlternativePostalAddressDto(
override val deliveryServiceQualifier: String? = null,
override val deliveryServiceNumber: String? = null

) : IBaseAlternativePostalAddressDto {
override fun adminLevel1Key(): String? {
return administrativeAreaLevel1
}

override fun countryCode(): CountryCode? {
return country
}
}
) : IBaseAlternativePostalAddressDto
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,4 @@ data class PhysicalPostalAddressDto(
override val floor: String? = null,
override val door: String? = null

) : IBasePhysicalPostalAddressDto {
override fun adminLevel1Key(): String? {
return administrativeAreaLevel1
}

override fun countryCode(): CountryCode? {
return country
}
}
) : IBasePhysicalPostalAddressDto
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.eclipse.tractusx.bpdm.common.dto.IBaseAlternativePostalAddressDto
import org.eclipse.tractusx.bpdm.common.model.DeliveryServiceType

data class AlternativePostalAddressDto(

override val geographicCoordinates: GeoCoordinateDto? = null,
override val country: CountryCode? = null,
override val administrativeAreaLevel1: String? = null,
Expand All @@ -34,11 +35,4 @@ data class AlternativePostalAddressDto(
override val deliveryServiceQualifier: String? = null,
override val deliveryServiceNumber: String? = null

) : IBaseAlternativePostalAddressDto {
override fun adminLevel1Key(): String? {
return administrativeAreaLevel1
}
override fun countryCode(): CountryCode? {
return country
}
}
) : IBaseAlternativePostalAddressDto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.eclipse.tractusx.bpdm.common.dto.GeoCoordinateDto
import org.eclipse.tractusx.bpdm.common.dto.IBasePhysicalPostalAddressDto

data class PhysicalPostalAddressDto(

override val geographicCoordinates: GeoCoordinateDto? = null,
override val country: CountryCode? = null,
override val administrativeAreaLevel1: String? = null,
Expand All @@ -39,12 +40,4 @@ data class PhysicalPostalAddressDto(
override val floor: String? = null,
override val door: String? = null

) : IBasePhysicalPostalAddressDto {
override fun adminLevel1Key(): String? {
return administrativeAreaLevel1
}

override fun countryCode(): CountryCode? {
return country
}
}
) : IBasePhysicalPostalAddressDto
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package org.eclipse.tractusx.orchestrator.api.model

import io.swagger.v3.oas.annotations.media.Schema
import org.eclipse.tractusx.bpdm.common.dto.IBaseSiteDto
import org.eclipse.tractusx.bpdm.common.dto.openapidescription.SiteDescription

data class SiteDto(

Expand All @@ -32,9 +31,8 @@ data class SiteDto(
val hasChanged: Boolean? = null,

override val name: String? = null,

override val states: Collection<SiteStateDto> = emptyList(),

override val mainAddress: LogisticAddressDto? = null
val mainAddress: LogisticAddressDto? = null

) : IBaseSiteDto
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,26 @@

package org.eclipse.tractusx.bpdm.pool.api.model

import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonProperty
import io.swagger.v3.oas.annotations.media.Schema
import org.eclipse.tractusx.bpdm.common.dto.IAddressIdentifierDto
import org.eclipse.tractusx.bpdm.common.dto.TypeKeyNameVerboseDto
import org.eclipse.tractusx.bpdm.common.dto.openapidescription.AddressIdentifierDescription

@Schema(description = AddressIdentifierDescription.header)
data class AddressIdentifierVerboseDto(

@get:Schema(description = AddressIdentifierDescription.value)
val value: String,
override val value: String,

@field:JsonProperty("type")
@get:Schema(description = AddressIdentifierDescription.type)
val type: TypeKeyNameVerboseDto<String>,
)
val typeVerbose: TypeKeyNameVerboseDto<String>,

) : IAddressIdentifierDto {

@get:JsonIgnore
override val type: String
get() = typeVerbose.technicalKey
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

package org.eclipse.tractusx.bpdm.pool.api.model

import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonProperty
import io.swagger.v3.oas.annotations.media.Schema
import org.eclipse.tractusx.bpdm.common.dto.IAddressStateDto
import org.eclipse.tractusx.bpdm.common.dto.TypeKeyNameVerboseDto
import org.eclipse.tractusx.bpdm.common.dto.openapidescription.AddressStateDescription
import org.eclipse.tractusx.bpdm.common.model.BusinessStateType
Expand All @@ -28,16 +31,18 @@ import java.time.LocalDateTime
@Schema(description = AddressStateDescription.header)
data class AddressStateVerboseDto(

@get:Schema(description = AddressStateDescription.description)
val description: String?,

@get:Schema(description = AddressStateDescription.validFrom)
val validFrom: LocalDateTime?,

@get:Schema(description = AddressStateDescription.validTo)
val validTo: LocalDateTime?,
override val description: String?,
override val validFrom: LocalDateTime?,
override val validTo: LocalDateTime?,

@field:JsonProperty("type")
// TODO OpenAPI description for complex field does not work!!
@get:Schema(description = AddressStateDescription.type)
val type: TypeKeyNameVerboseDto<BusinessStateType>
)
val typeVerbose: TypeKeyNameVerboseDto<BusinessStateType>

) : IAddressStateDto {

@get:JsonIgnore
override val type: BusinessStateType
get() = typeVerbose.technicalKey
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,4 @@ data class AlternativePostalAddressDto(
override val deliveryServiceQualifier: String?,
override val deliveryServiceNumber: String

) : IBaseAlternativePostalAddressDto {
override fun adminLevel1Key(): String? {
return administrativeAreaLevel1
}

override fun countryCode(): CountryCode {
return country
}
}
) : IBaseAlternativePostalAddressDto
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package org.eclipse.tractusx.bpdm.pool.api.model

import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.neovisionaries.i18n.CountryCode
import io.swagger.v3.oas.annotations.media.Schema
Expand All @@ -34,20 +36,28 @@ import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializ
data class AlternativePostalAddressVerboseDto(

override val geographicCoordinates: GeoCoordinateDto?,
override val country: TypeKeyNameVerboseDto<CountryCode>,
override val administrativeAreaLevel1: RegionDto?,

@field:JsonProperty("country")
@get:Schema(description = PostalAddressDescription.country)
val countryVerbose: TypeKeyNameVerboseDto<CountryCode>,

@field:JsonProperty("administrativeAreaLevel1")
@get:Schema(description = PostalAddressDescription.administrativeAreaLevel1)
val administrativeAreaLevel1Verbose: RegionDto?,

override val postalCode: String?,
override val city: String,
override val deliveryServiceType: DeliveryServiceType,
override val deliveryServiceQualifier: String?,
override val deliveryServiceNumber: String

) : IBaseAlternativePostalAddressDto {
override fun adminLevel1Key(): String? {
return administrativeAreaLevel1?.regionCode
}
override fun countryCode(): CountryCode {
return country.technicalKey
}
}

@get:JsonIgnore
override val country: CountryCode
get() = countryVerbose.technicalKey

@get:JsonIgnore
override val administrativeAreaLevel1: String?
get() = administrativeAreaLevel1Verbose?.regionCode
}
Loading

0 comments on commit 4f6bc2a

Please sign in to comment.