Skip to content

Commit

Permalink
refactor(DTO): Unify legal entity for normal/verbose model
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfkaeser committed Dec 7, 2023
1 parent 30df324 commit 7f7ef3d
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 63 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,27 @@

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.ILegalEntityClassificationDto
import org.eclipse.tractusx.bpdm.common.dto.TypeKeyNameVerboseDto
import org.eclipse.tractusx.bpdm.common.dto.openapidescription.ClassificationDescription
import org.eclipse.tractusx.bpdm.common.model.ClassificationType

@Schema(description = ClassificationDescription.header)
data class LegalEntityClassificationVerboseDto(

@get:Schema(description = ClassificationDescription.value)
val value: String? = null,
override val value: String? = null,
override val code: String? = null,

@get:Schema(description = ClassificationDescription.code)
val code: String? = null,

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

) : ILegalEntityClassificationDto {

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

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.ILegalEntityIdentifierDto
import org.eclipse.tractusx.bpdm.common.dto.TypeKeyNameVerboseDto
import org.eclipse.tractusx.bpdm.common.dto.openapidescription.LegalEntityIdentifierDescription

@Schema(description = LegalEntityIdentifierDescription.header)
data class LegalEntityIdentifierVerboseDto(

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

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

@get:Schema(description = LegalEntityIdentifierDescription.issuingBody)
val issuingBody: String? = null
)
override val issuingBody: String? = null

) : ILegalEntityIdentifierDto {

@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.ILegalEntityStateDto
import org.eclipse.tractusx.bpdm.common.dto.TypeKeyNameVerboseDto
import org.eclipse.tractusx.bpdm.common.dto.openapidescription.LegalEntityStateDescription
import org.eclipse.tractusx.bpdm.common.model.BusinessStateType
Expand All @@ -28,16 +31,17 @@ import java.time.LocalDateTime
@Schema(description = LegalEntityStateDescription.header)
data class LegalEntityStateVerboseDto(

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

@get:Schema(description = LegalEntityStateDescription.validFrom)
val validFrom: LocalDateTime?,
@field:JsonProperty("type")
@get:Schema(description = LegalEntityStateDescription.type)
val typeVerbose: TypeKeyNameVerboseDto<BusinessStateType>

@get:Schema(description = LegalEntityStateDescription.validTo)
val validTo: LocalDateTime?,
) : ILegalEntityStateDto {

// TODO OpenAPI description for complex field does not work!!
@get:Schema(description = LegalEntityStateDescription.type)
val type: TypeKeyNameVerboseDto<BusinessStateType>
)
@get:JsonIgnore
override val type: BusinessStateType
get() = typeVerbose.technicalKey
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@

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.ArraySchema
import io.swagger.v3.oas.annotations.media.Schema
import org.eclipse.tractusx.bpdm.common.dto.IBaseLegalEntityDto
import org.eclipse.tractusx.bpdm.common.dto.openapidescription.CommonDescription
import org.eclipse.tractusx.bpdm.common.dto.openapidescription.LegalEntityDescription
import java.time.Instant
Expand All @@ -34,21 +37,15 @@ data class LegalEntityVerboseDto(
@get:Schema(description = LegalEntityDescription.legalName)
val legalName: String,

@get:Schema(description = LegalEntityDescription.legalShortName)
val legalShortName: String? = null,
override val legalShortName: String? = null,

@field:JsonProperty("legalForm")
@get:Schema(description = LegalEntityDescription.legalForm)
val legalForm: LegalFormDto? = null,
val legalFormVerbose: LegalFormDto? = null,

// TODO OpenAPI description for complex field does not work!!
@get:ArraySchema(arraySchema = Schema(description = LegalEntityDescription.identifiers))
val identifiers: Collection<LegalEntityIdentifierVerboseDto> = emptyList(),

@get:ArraySchema(arraySchema = Schema(description = LegalEntityDescription.states))
val states: Collection<LegalEntityStateVerboseDto> = emptyList(),

@get:ArraySchema(arraySchema = Schema(description = LegalEntityDescription.classifications))
val classifications: Collection<LegalEntityClassificationVerboseDto> = emptyList(),
override val identifiers: Collection<LegalEntityIdentifierVerboseDto> = emptyList(),
override val states: Collection<LegalEntityStateVerboseDto> = emptyList(),
override val classifications: Collection<LegalEntityClassificationVerboseDto> = emptyList(),

@get:ArraySchema(arraySchema = Schema(description = LegalEntityDescription.relations))
val relations: Collection<RelationVerboseDto> = emptyList(),
Expand All @@ -60,5 +57,11 @@ data class LegalEntityVerboseDto(
val createdAt: Instant,

@get:Schema(description = CommonDescription.updatedAt)
val updatedAt: Instant,
)
val updatedAt: Instant

) : IBaseLegalEntityDto {

@get:JsonIgnore
override val legalForm: String?
get() = legalFormVerbose?.technicalKey
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fun LegalEntity.toDto(): LegalEntityVerboseDto {
bpnl = bpn,
legalName = legalName.value,
legalShortName = legalName.shortName,
legalForm = legalForm?.toDto(),
legalFormVerbose = legalForm?.toDto(),
identifiers = identifiers.map { it.toDto() },
states = states.map { it.toDto() },
classifications = classifications.map { it.toDto() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ class LegalEntityControllerIT @Autowired constructor(
.first() // search for first

val identifierToFind = expected.identifiers.first()
val response = poolClient.legalEntities.getLegalEntity(identifierToFind.value, identifierToFind.type.technicalKey).legalEntity
val response = poolClient.legalEntities.getLegalEntity(identifierToFind.value, identifierToFind.typeVerbose.technicalKey).legalEntity

assertThat(response)
.usingRecursiveComparison()
Expand Down Expand Up @@ -645,7 +645,7 @@ class LegalEntityControllerIT @Autowired constructor(
var identifierToFind = expected.identifiers.first()
identifierToFind = identifierToFind.copy(value = changeCase(identifierToFind.value))

val response = poolClient.legalEntities.getLegalEntity(identifierToFind.value, identifierToFind.type.technicalKey).legalEntity
val response = poolClient.legalEntities.getLegalEntity(identifierToFind.value, identifierToFind.typeVerbose.technicalKey).legalEntity

assertThat(response)
.usingRecursiveComparison()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ class TaskStepFetchAndReserveServiceTest @Autowired constructor(
val verboseLegalEntity = verboseRequest.legalEntity

assertThat(verboseLegalEntity.legalShortName).isEqualTo(legalEntity?.legalShortName)
assertThat(verboseLegalEntity.legalForm?.technicalKey).isEqualTo(legalEntity?.legalForm)
assertThat(verboseLegalEntity.legalFormVerbose?.technicalKey).isEqualTo(legalEntity?.legalForm)
compareStates(verboseLegalEntity.states, legalEntity?.states)
compareClassifications(verboseLegalEntity.classifications, legalEntity?.classifications)
compareIdentifiers(verboseLegalEntity.identifiers, legalEntity?.identifiers)
Expand Down Expand Up @@ -636,11 +636,11 @@ class TaskStepFetchAndReserveServiceTest @Autowired constructor(
val sortedVerboseStates = statesVerbose.sortedBy { it.description }
val sortedStates = states!!.sortedBy { it.description }
sortedVerboseStates.indices.forEach {
assertThat(sortedVerboseStates[it].type.technicalKey.name).isEqualTo(sortedStates[it].type.name)
assertThat(sortedVerboseStates[it].typeVerbose.technicalKey.name).isEqualTo(sortedStates[it].type.name)
assertThat(sortedVerboseStates[it]).usingRecursiveComparison()
.withEqualsForFields(isEqualToIgnoringMilliseconds(), "validTo")
.withEqualsForFields(isEqualToIgnoringMilliseconds(), "validFrom")
.ignoringFields("type")
.ignoringFields("typeVerbose")
.isEqualTo(sortedStates[it])
}
}
Expand Down Expand Up @@ -673,27 +673,26 @@ class TaskStepFetchAndReserveServiceTest @Autowired constructor(
) {

assertThat(classificationsVerbose.size).isEqualTo(classifications?.size ?: 0)
val sortedVerboseClassifications = classificationsVerbose.sortedBy { it.type.name }
val sortedVerboseClassifications = classificationsVerbose.sortedBy { it.typeVerbose.name }
val sortedClassifications = classifications!!.sortedBy { it.type.name }
sortedVerboseClassifications.indices.forEach {
assertThat(sortedVerboseClassifications[it].type.technicalKey.name).isEqualTo(sortedClassifications[it].type.name)
assertThat(sortedVerboseClassifications[it].typeVerbose.technicalKey.name).isEqualTo(sortedClassifications[it].type.name)
assertThat(sortedVerboseClassifications[it]).usingRecursiveComparison()
.ignoringFields("type")
.ignoringFields("typeVerbose")
.isEqualTo(sortedClassifications[it])
}
}

fun compareIdentifiers(identifiersVerbose: Collection<LegalEntityIdentifierVerboseDto>, identifiers: Collection<LegalEntityIdentifierDto>?) {

assertThat(identifiersVerbose.size).isEqualTo(identifiers?.size ?: 0)
val sortedVerboseIdentifiers = identifiersVerbose.sortedBy { it.type.name }
val sortedVerboseIdentifiers = identifiersVerbose.sortedBy { it.typeVerbose.name }
val sortedIdentifiers = identifiers!!.sortedBy { it.type }
sortedVerboseIdentifiers.indices.forEach {
assertThat(sortedVerboseIdentifiers[it].type.technicalKey).isEqualTo(sortedIdentifiers[it].type)
assertThat(sortedVerboseIdentifiers[it].typeVerbose.technicalKey).isEqualTo(sortedIdentifiers[it].type)
assertThat(sortedVerboseIdentifiers[it]).usingRecursiveComparison()
.ignoringFields("type").isEqualTo(sortedIdentifiers[it])
.ignoringFields("typeVerbose").isEqualTo(sortedIdentifiers[it])
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ object BusinessPartnerVerboseValues {
LegalEntityVerboseDto(
bpnl = "BPNL000000000001",
legalName = "Business Partner Name",
legalForm = legalForm1,
legalFormVerbose = legalForm1,
identifiers = listOf(identifier1),
states = listOf(leStatus1),
classifications = listOf(classification1, classification2),
Expand Down Expand Up @@ -286,7 +286,7 @@ object BusinessPartnerVerboseValues {
LegalEntityVerboseDto(
bpnl = "BPNL0000000001YN",
legalName = "Another Organisation Corp",
legalForm = legalForm2,
legalFormVerbose = legalForm2,
identifiers = listOf(identifier2),
states = listOf(leStatus2),
classifications = listOf(classification3, classification4),
Expand Down Expand Up @@ -323,7 +323,7 @@ object BusinessPartnerVerboseValues {
LegalEntityVerboseDto(
bpnl = "BPNL0000000002XY",
legalName = "好公司 合伙制企业",
legalForm = legalForm3,
legalFormVerbose = legalForm3,
identifiers = listOf(identifier3),
states = listOf(leStatus3),
classifications = listOf(classification5),
Expand Down Expand Up @@ -360,7 +360,7 @@ object BusinessPartnerVerboseValues {
legalEntity = LegalEntityVerboseDto(
bpnl = "BPNL000000000001",
legalName = "Business Partner Name",
legalForm = legalForm1,
legalFormVerbose = legalForm1,
identifiers = listOf(LegalEntityIdentifierVerboseDto("ID-XYZ", identifierType1, "Agency X")),
states = listOf(leStatus1),
classifications = listOf(classification1, classification2),
Expand All @@ -379,7 +379,7 @@ object BusinessPartnerVerboseValues {
legalEntity = LegalEntityVerboseDto(
bpnl = "BPNL0000000001YN",
legalName = "Another Organisation Corp",
legalForm = legalForm2,
legalFormVerbose = legalForm2,
identifiers = listOf(LegalEntityIdentifierVerboseDto("Another ID Value", identifierType2, "Body Y")),
states = listOf(leStatus2),
classifications = listOf(classification3, classification4),
Expand All @@ -398,7 +398,7 @@ object BusinessPartnerVerboseValues {
legalEntity = LegalEntityVerboseDto(
bpnl = "BPNL0000000002XY",
legalName = "好公司 合伙制企业",
legalForm = legalForm3,
legalFormVerbose = legalForm3,
identifiers = listOf(LegalEntityIdentifierVerboseDto("An ID Value", identifierType3, "Official Z")),
states = listOf(leStatus3),
classifications = listOf(classification5),
Expand All @@ -417,7 +417,7 @@ object BusinessPartnerVerboseValues {
legalEntity = LegalEntityVerboseDto(
bpnl = "BPNL000000000001",
legalName = "Business Partner Name",
legalForm = legalForm1,
legalFormVerbose = legalForm1,
identifiers = listOf(
LegalEntityIdentifierVerboseDto("ID-XYZ", identifierType1, "Agency X"),
LegalEntityIdentifierVerboseDto("Another ID Value", identifierType2, "Body Y")
Expand Down

0 comments on commit 7f7ef3d

Please sign in to comment.