Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring: Reorganize Legal Entity DTOs between modules #662

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,58 @@
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.dto.response.AlternativePostalAddressVerboseDto
import org.eclipse.tractusx.bpdm.common.dto.response.LogisticAddressVerboseDto
import org.eclipse.tractusx.bpdm.common.dto.response.PhysicalPostalAddressVerboseDto
import org.eclipse.tractusx.bpdm.common.dto.response.SiteVerboseDto
import org.eclipse.tractusx.bpdm.common.exception.BpdmNullMappingException
import org.eclipse.tractusx.bpdm.gate.api.model.*
import org.eclipse.tractusx.bpdm.pool.api.model.LegalEntityVerboseDto
import kotlin.reflect.KProperty
import org.eclipse.tractusx.bpdm.gate.api.model.LegalEntityClassificationDto as Gate_LegalEntityClassificationDto
import org.eclipse.tractusx.bpdm.gate.api.model.LegalEntityDto as Gate_LegalEntityDto
import org.eclipse.tractusx.bpdm.gate.api.model.LegalEntityIdentifierDto as Gate_LegalEntityIdentifierDto
import org.eclipse.tractusx.bpdm.gate.api.model.LegalEntityStateDto as Gate_LegalEntityStateDto
import org.eclipse.tractusx.bpdm.pool.api.model.LegalEntityClassificationDto as Pool_LegalEntityClassificationDto
import org.eclipse.tractusx.bpdm.pool.api.model.LegalEntityDto as Pool_LegalEntityDto
import org.eclipse.tractusx.bpdm.pool.api.model.LegalEntityIdentifierDto as Pool_LegalEntityIdentifierDto
import org.eclipse.tractusx.bpdm.pool.api.model.LegalEntityStateDto as Pool_LegalEntityStateDto

fun gateToPoolLegalEntity(gateDto: Gate_LegalEntityDto): Pool_LegalEntityDto {
return Pool_LegalEntityDto(
identifiers = gateDto.identifiers.map(::gateToPoolLegalEntityIdentifier),
legalName = gateDto.legalNameParts.firstOrNull() ?: "",
legalShortName = gateDto.legalShortName,
legalForm = gateDto.legalForm,
states = gateDto.states.map(::gateToPoolLegalEntityState),
classifications = gateDto.classifications.map(::gateToPoolLegalEntityClassification)
)
}

fun gateToPoolLegalEntityIdentifier(gateDto: Gate_LegalEntityIdentifierDto): Pool_LegalEntityIdentifierDto {
return Pool_LegalEntityIdentifierDto(
type = gateDto.type,
value = gateDto.value,
issuingBody = gateDto.issuingBody
)
}

fun gateToPoolLegalEntityState(gateDto: Gate_LegalEntityStateDto): Pool_LegalEntityStateDto {
return Pool_LegalEntityStateDto(
validFrom = gateDto.validFrom,
validTo = gateDto.validTo,
type = gateDto.type,
description = gateDto.description
)
}

fun gateToPoolLegalEntityClassification(gateDto: Gate_LegalEntityClassificationDto): Pool_LegalEntityClassificationDto {
return Pool_LegalEntityClassificationDto(
type = gateDto.type,
code = gateDto.code,
value = gateDto.value
)
}

fun gateToPoolLogisticAddress(gateDto: LogisticAddressGateDto): LogisticAddressDto {
return LogisticAddressDto(
Expand Down Expand Up @@ -85,33 +133,34 @@ fun gateToPoolPhysicalAddress(gateDto: PhysicalPostalAddressGateDto): PhysicalPo
}


fun poolToGateLegalEntity(legalEntity: LegalEntityVerboseDto): LegalEntityDto {
fun poolToGateLegalEntity(legalEntity: LegalEntityVerboseDto): Gate_LegalEntityDto {
val identifiers = legalEntity.identifiers.map {
LegalEntityIdentifierDto(
Gate_LegalEntityIdentifierDto(
value = it.value,
type = it.type.technicalKey,
issuingBody = it.issuingBody
)
}
val states = legalEntity.states.map {
LegalEntityStateDto(
Gate_LegalEntityStateDto(
description = it.description,
validFrom = it.validFrom,
validTo = it.validTo,
type = it.type.technicalKey
)
}
val classifications = legalEntity.classifications.map {
ClassificationDto(
Gate_LegalEntityClassificationDto(
type = it.type.technicalKey,
code = it.code,
value = it.value
)
}
return LegalEntityDto(
identifiers = identifiers,
return Gate_LegalEntityDto(
legalNameParts = listOfNotNull(legalEntity.legalName),
legalShortName = legalEntity.legalShortName,
legalForm = legalEntity.legalForm?.technicalKey,
identifiers = identifiers,
states = states,
classifications = classifications
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@

package com.catenax.bpdm.bridge.dummy.dto

import org.eclipse.tractusx.bpdm.common.dto.LegalEntityDto
import org.eclipse.tractusx.bpdm.gate.api.model.LegalEntityDto
import org.eclipse.tractusx.bpdm.gate.api.model.response.AddressGateInputDto

data class GateLegalEntityInfo(
val legalNameParts: Collection<String>,
val legalEntity: LegalEntityDto,
val legalAddress: AddressGateInputDto,
val externalId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class GateQueryService(

return entries.map {
GateLegalEntityInfo(
legalNameParts = it.legalNameParts,
legalEntity = it.legalEntity,
legalAddress = it.legalAddress,
externalId = it.externalId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ class GateUpdateService(
return null
}
return LegalEntityGateOutputRequest(
legalNameParts = listOfNotNull(poolResponse.legalName),
legalEntity = poolToGateLegalEntity(poolResponse.legalEntity),
legalAddress = poolToGateAddressChild(poolResponse.legalAddress),
externalId = requestEntry.externalId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ class PoolUpdateService(
fun createLegalEntitiesInPool(entriesToCreate: Collection<GateLegalEntityInfo>): LegalEntityPartnerCreateResponseWrapper {
val createRequests = entriesToCreate.map {
LegalEntityPartnerCreateRequest(
legalEntity = it.legalEntity,
legalEntity = gateToPoolLegalEntity(it.legalEntity),
legalAddress = gateToPoolLogisticAddress(it.legalAddress.address),
index = it.externalId,
legalName = it.legalNameParts.firstOrNull() ?: ""
index = it.externalId
)
}

Expand All @@ -54,10 +53,9 @@ class PoolUpdateService(
fun updateLegalEntitiesInPool(entriesToUpdate: Collection<GateLegalEntityInfo>): LegalEntityPartnerUpdateResponseWrapper {
val updateRequests = entriesToUpdate.map {
LegalEntityPartnerUpdateRequest(
legalEntity = it.legalEntity,
legalEntity = gateToPoolLegalEntity(it.legalEntity),
legalAddress = gateToPoolLogisticAddress(it.legalAddress.address),
bpnl = it.bpn!!,
legalName = it.legalNameParts.firstOrNull() ?: ""
bpnl = it.bpn!!
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@

package com.catenax.bpdm.bridge.dummy.testdata

import org.eclipse.tractusx.bpdm.common.dto.*
import org.eclipse.tractusx.bpdm.gate.api.model.LogisticAddressGateDto
import org.eclipse.tractusx.bpdm.gate.api.model.PhysicalPostalAddressGateDto
import org.eclipse.tractusx.bpdm.gate.api.model.SiteGateDto
import org.eclipse.tractusx.bpdm.gate.api.model.StreetGateDto
import org.eclipse.tractusx.bpdm.common.dto.GeoCoordinateDto
import org.eclipse.tractusx.bpdm.common.dto.SiteStateDto
import org.eclipse.tractusx.bpdm.gate.api.model.*
import org.eclipse.tractusx.bpdm.gate.api.model.request.AddressGateInputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.request.LegalEntityGateInputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.request.SiteGateInputRequest
Expand Down Expand Up @@ -90,25 +88,25 @@ object GateRequestValues {
type = CommonValues.businessStateType2
)

val classification1 = ClassificationDto(
val classification1 = LegalEntityClassificationDto(
type = CommonValues.classificationType,
code = CommonValues.classificationCode1,
value = CommonValues.classificationValue1
)

val classification2 = ClassificationDto(
val classification2 = LegalEntityClassificationDto(
type = CommonValues.classificationType,
code = CommonValues.classificationCode2,
value = CommonValues.classificationValue2
)

val classification3 = ClassificationDto(
val classification3 = LegalEntityClassificationDto(
type = CommonValues.classificationType,
code = CommonValues.classificationCode3,
value = CommonValues.classificationValue3
)

val classification4 = ClassificationDto(
val classification4 = LegalEntityClassificationDto(
type = CommonValues.classificationType,
code = CommonValues.classificationCode4,
value = CommonValues.classificationValue4
Expand Down Expand Up @@ -226,6 +224,7 @@ object GateRequestValues {

val legalEntity1 = LegalEntityDto(
identifiers = listOf(identifier1, identifier2),
legalNameParts = listOf(CommonValues.name1),
legalShortName = CommonValues.shortName1,
legalForm = CommonValues.legalFormTechnicalKey1,
states = listOf(leBusinessStatus1),
Expand All @@ -234,6 +233,7 @@ object GateRequestValues {

val legalEntity2 = LegalEntityDto(
identifiers = listOf(identifier3, identifier4),
legalNameParts = listOf(CommonValues.name3),
legalShortName = CommonValues.shortName3,
legalForm = CommonValues.legalFormTechnicalKey2,
states = listOf(leBusinessStatus2),
Expand All @@ -242,6 +242,7 @@ object GateRequestValues {

val legalEntity3 = LegalEntityDto(
identifiers = listOf(identifier5),
legalNameParts = listOf(CommonValues.name1),
legalShortName = CommonValues.shortName1,
legalForm = CommonValues.legalFormTechnicalKey1,
states = listOf(leBusinessStatus1),
Expand All @@ -251,21 +252,18 @@ object GateRequestValues {
val legalEntityGateInputRequest1 = LegalEntityGateInputRequest(
legalEntity = legalEntity1,
legalAddress = address1,
legalNameParts = listOf(CommonValues.name1),
externalId = CommonValues.externalId1,
)

val legalEntityGateInputRequest2 = LegalEntityGateInputRequest(
legalEntity = legalEntity2,
legalAddress = address2,
legalNameParts = listOf(CommonValues.name3),
externalId = CommonValues.externalId2,
)

val legalEntityGateInputRequest3 = LegalEntityGateInputRequest(
legalEntity = legalEntity3,
legalAddress = address3,
legalNameParts = listOf(CommonValues.name1),
externalId = CommonValues.externalId3,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.eclipse.tractusx.bpdm.cleaning.service


import org.eclipse.tractusx.bpdm.common.dto.ClassificationDto
import org.eclipse.tractusx.orchestrator.api.model.*


Expand All @@ -40,9 +39,9 @@ fun BusinessPartnerGenericDto.toLegalEntityDto(bpnReferenceDto: BpnReferenceDto,
)
}

fun BusinessPartnerClassificationDto.toLegalEntityClassificationDto(): ClassificationDto {
fun BusinessPartnerClassificationDto.toLegalEntityClassificationDto(): LegalEntityClassificationDto {

return ClassificationDto(code = code, type = type, value = value)
return LegalEntityClassificationDto(code = code, type = type, value = value)
}

fun BusinessPartnerIdentifierDto.toLegalEntityIdentifierDto(): LegalEntityIdentifierDto? {
Expand All @@ -55,9 +54,9 @@ fun BusinessPartnerIdentifierDto.toLegalEntityIdentifierDto(): LegalEntityIdenti

}

fun BusinessPartnerStateDto.toLegalEntityState(): LegalEntityState? {
fun BusinessPartnerStateDto.toLegalEntityState(): LegalEntityStateDto? {

return type?.let { LegalEntityState(description, validFrom, validTo, it) }
return type?.let { LegalEntityStateDto(description, validFrom, validTo, it) }
}

fun BusinessPartnerStateDto.toSiteState(): SiteStateDto? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ interface IBaseBusinessPartnerDto {
val legalForm: String?

@get:ArraySchema(arraySchema = Schema(description = "The list of (temporary) states of the business partner. Sorted and duplicates removed by the service."))
val states: Collection<IBaseStateDto>
val states: Collection<IBusinessPartnerStateDto>

@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<IBaseClassificationDto>
val classifications: Collection<IBusinessPartnerClassificationDto>

@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<BusinessPartnerRole>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import org.eclipse.tractusx.bpdm.common.dto.openapidescription.LegalEntityDescri

@Schema(description = LegalEntityDescription.header)
interface IBaseLegalEntityDto {

@get:ArraySchema(arraySchema = Schema(description = LegalEntityDescription.identifiers, required = false))
val identifiers: Collection<IBaseLegalEntityIdentifierDto>
val identifiers: Collection<ILegalEntityIdentifierDto>

@get:Schema(description = LegalEntityDescription.legalShortName)
val legalShortName: String?
Expand All @@ -35,9 +36,8 @@ interface IBaseLegalEntityDto {
val legalForm: String?

@get:ArraySchema(arraySchema = Schema(description = LegalEntityDescription.states))
val states: Collection<IBaseLegalEntityStateDto>
val states: Collection<ILegalEntityStateDto>

@get:ArraySchema(arraySchema = Schema(description = LegalEntityDescription.classifications, required = false))
val classifications: Collection<IBaseClassificationDto>

}
val classifications: Collection<ILegalEntityClassificationDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,4 @@

package org.eclipse.tractusx.bpdm.common.dto


data class LegalEntityIdentifierDto(

override val value: String,
override val type: String,
override val issuingBody: String?
) : IBaseLegalEntityIdentifierDto
interface IBusinessPartnerClassificationDto : IBaseClassificationDto
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,4 @@

package org.eclipse.tractusx.bpdm.common.dto

import io.swagger.v3.oas.annotations.media.Schema

@Schema(name = "Name", description = "Name record for a business partner")
data class NameDto(
@get:Schema(description = "Full name")
val value: String,

@get:Schema(description = "Abbreviated name or shorthand")
val shortName: String?
)
interface IBusinessPartnerStateDto : IBaseStateDto
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
package org.eclipse.tractusx.bpdm.common.dto

import io.swagger.v3.oas.annotations.media.Schema
import org.eclipse.tractusx.bpdm.common.dto.openapidescription.ClassificationDescription
import org.eclipse.tractusx.bpdm.common.model.ClassificationType

@Schema(name = "NameRegioncodeDto", description = "Region within a country")
data class NameRegioncodeVerboseDto(
interface ILegalEntityClassificationDto : IBaseClassificationDto {

@get:Schema(description = "Describes the full name of the region within a country according to ISO 3166-214")
val name: String,

@get:Schema(description = "Abbreviation or shorthand of the area")
val regionCode: String,
)
@get:Schema(description = ClassificationDescription.type, required = true)
override val type: ClassificationType
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import io.swagger.v3.oas.annotations.media.Schema
import org.eclipse.tractusx.bpdm.common.dto.openapidescription.LegalEntityIdentifierDescription

@Schema(description = LegalEntityIdentifierDescription.header)
interface IBaseLegalEntityIdentifierDto : IBaseIdentifierDto {
interface ILegalEntityIdentifierDto : IBaseIdentifierDto {

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

Expand All @@ -32,4 +33,4 @@ interface IBaseLegalEntityIdentifierDto : IBaseIdentifierDto {

@get:Schema(description = LegalEntityIdentifierDescription.issuingBody)
val issuingBody: String?
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.eclipse.tractusx.bpdm.common.model.BusinessStateType
import java.time.LocalDateTime

@Schema(description = LegalEntityStateDescription.header)
interface IBaseLegalEntityStateDto : IBaseStateDto {
interface ILegalEntityStateDto : IBaseStateDto {

@get:Schema(description = LegalEntityStateDescription.description)
override val description: String?
Expand Down
Loading