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 8, 2023
1 parent dbdf73a commit 5a5d655
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 60 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 @@ -1325,9 +1325,9 @@ class TaskStepFetchAndReserveServiceTest @Autowired constructor(
sortedVerboseStates.indices.forEach {
assertThat(sortedVerboseStates[it].typeVerbose.technicalKey.name).isEqualTo(sortedStates[it].type.name)
assertThat(sortedVerboseStates[it]).usingRecursiveComparison()
.withEqualsForFields(isEqualToIgnoringMilliseconds(), ILegalEntityStateDto::validTo.name )
.withEqualsForFields(isEqualToIgnoringMilliseconds(), ILegalEntityStateDto::validFrom.name)
.ignoringFields(ILegalEntityStateDto::type.name)
.withEqualsForFields(isEqualToIgnoringMilliseconds(), LegalEntityStateVerboseDto::validTo.name )
.withEqualsForFields(isEqualToIgnoringMilliseconds(), LegalEntityStateVerboseDto::validFrom.name)
.ignoringFields(LegalEntityStateVerboseDto::typeVerbose.name)
.isEqualTo(sortedStates[it])
}
}
Expand Down Expand Up @@ -1360,12 +1360,12 @@ 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].typeVerbose.technicalKey.name).isEqualTo(sortedClassifications[it].type.name)
assertThat(sortedVerboseClassifications[it]).usingRecursiveComparison()
.ignoringFields(LegalEntityClassificationVerboseDto::type.name)
.ignoringFields(LegalEntityClassificationVerboseDto::typeVerbose.name)
.isEqualTo(sortedClassifications[it])
}
}
Expand All @@ -1378,9 +1378,8 @@ class TaskStepFetchAndReserveServiceTest @Autowired constructor(
sortedVerboseIdentifiers.indices.forEach {
assertThat(sortedVerboseIdentifiers[it].typeVerbose.technicalKey).isEqualTo(sortedIdentifiers[it].type)
assertThat(sortedVerboseIdentifiers[it]).usingRecursiveComparison()
.ignoringFields(LegalEntityIdentifierVerboseDto::type.name).isEqualTo(sortedIdentifiers[it])
.ignoringFields(LegalEntityIdentifierVerboseDto::typeVerbose.name).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 5a5d655

Please sign in to comment.