Skip to content

Commit

Permalink
feat(api): eclipse-tractusx#172 Unwrap name schema eclipse-tractusx#180
Browse files Browse the repository at this point in the history
  • Loading branch information
rainer-exxcellent committed May 25, 2023
1 parent b83b2bd commit d938618
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ data class LegalEntityDto(
val identifiers: Collection<LegalEntityIdentifierDto> = emptyList(),

@get:Schema(description = "Legal name the partner goes by")
val legalName: NameDto,
val legalName: String,

@get:Schema(description = "Abbreviated name or shorthand")
val legalShortName: String?,

@get:Schema(description = "Technical key of the legal form")
val legalForm: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ data class LegalEntityResponse(
val identifiers: Collection<LegalEntityIdentifierResponse> = emptyList(),

@get:Schema(description = "Legal name the partner goes by")
val legalName: NameResponse,
val legalName: String,

@get:Schema(description = "Abbreviated name or shorthand")
val legalShortName: String? = null,

@get:Schema(description = "Legal form of the business partner")
val legalForm: LegalFormResponse? = null,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ object SaasMappings {
?: throw BpdmMappingException(this::class, LegalEntityDto::class, "No legal name", externalId ?: "Unknown")
return LegalEntityDto(
identifiers = identifiers.filter { it.type?.technicalKey != BPN_TECHNICAL_KEY }.map { toLegalEntityIdentifierDto(it) },
legalName = legalName,
legalName = legalName.value,
legalShortName = legalName.shortName,
legalForm = toOptionalReference(legalForm),
states = toLegalEntityStatesDtos(status),
classifications = toDto(profile),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ package org.eclipse.tractusx.bpdm.gate.service
import org.eclipse.tractusx.bpdm.common.exception.BpdmNotFoundException
import org.eclipse.tractusx.bpdm.common.util.replace
import org.eclipse.tractusx.bpdm.gate.api.model.LegalEntityGateInputRequest
import org.eclipse.tractusx.bpdm.gate.entity.AddressIdentifier
import org.eclipse.tractusx.bpdm.gate.entity.AddressState
import org.eclipse.tractusx.bpdm.gate.entity.LegalEntity
import org.eclipse.tractusx.bpdm.gate.entity.LogisticAddress
import org.eclipse.tractusx.bpdm.gate.entity.*
import org.eclipse.tractusx.bpdm.gate.repository.GateAddressRepository
import org.eclipse.tractusx.bpdm.gate.repository.LegalEntityRepository
import org.springframework.stereotype.Service
Expand Down Expand Up @@ -73,7 +70,7 @@ class LegalEntityPersistenceService(
legalEntity.bpn = legalEntityRequest.bpn
legalEntity.externalId = legalEntityRequest.externalId
legalEntity.legalForm = legalEntityRequest.legalEntity.legalForm
legalEntity.legalName = legalEntityRequest.legalEntity.legalName.toName()
legalEntity.legalName = Name(value = legalEntityRequest.legalEntity.legalName, shortName = legalEntityRequest.legalEntity.legalShortName)
legalEntity.identifiers.replace(legalEntityRequest.legalEntity.identifiers.map { toEntityIdentifier(it, legalEntity) })
legalEntity.states.replace(legalEntityRequest.legalEntity.states.map { toEntityState(it, legalEntity) })
legalEntity.classifications.replace(legalEntityRequest.legalEntity.classifications.map { toEntityClassification(it, legalEntity) })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fun LegalEntityGateInputRequest.toLegalEntity(): LegalEntity {
externalId = externalId,
currentness = createCurrentnessTimestamp(),
legalForm = legalEntity.legalForm,
legalName = legalEntity.legalName.toName()
legalName = Name(legalEntity.legalName, legalEntity.legalShortName)
)

legalEntity.identifiers.addAll(this.legalEntity.identifiers.map { toEntityIdentifier(it, legalEntity) })
Expand All @@ -181,10 +181,6 @@ fun toEntityClassification(dto: ClassificationDto, legalEntity: LegalEntity): Cl
return Classification(dto.value, dto.code, dto.type, legalEntity)
}

fun NameDto.toName(): Name {
return Name(value, shortName)
}

private fun createCurrentnessTimestamp(): Instant {
return Instant.now().truncatedTo(ChronoUnit.MICROS)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ object RequestValues {
)

val name1 = NameDto(value = CommonValues.name1, shortName = CommonValues.shortName1)
val name2 = NameDto(value = CommonValues.name2, shortName = CommonValues.shortName2)
val name3 = NameDto(value = CommonValues.name3, shortName = CommonValues.shortName3)
val name4 = NameDto(value = CommonValues.name4, shortName = CommonValues.shortName4)

val leBusinessStatus1 = LegalEntityStateDto(
officialDenotation = CommonValues.businessStatusOfficialDenotation1,
Expand Down Expand Up @@ -166,7 +163,8 @@ object RequestValues {

val legalEntity1 = LegalEntityDto(
identifiers = listOf(identifier1, identifier2),
legalName = name1,
legalName = CommonValues.name1,
legalShortName = CommonValues.shortName1,
legalForm = CommonValues.legalFormTechnicalKey1,
states = listOf(leBusinessStatus1),
classifications = listOf(classification1, classification2),
Expand All @@ -175,7 +173,8 @@ object RequestValues {

val legalEntity2 = LegalEntityDto(
identifiers = listOf(identifier3, identifier4),
legalName = name3,
legalName = CommonValues.name3,
legalShortName = CommonValues.shortName3,
legalForm = CommonValues.legalFormTechnicalKey2,
states = listOf(leBusinessStatus2),
classifications = listOf(classification3, classification4),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,6 @@ object ResponseValues {

)

val name1 = NameResponse(
value = CommonValues.name1,
shortName = CommonValues.shortName1,
)

val name2 = NameResponse(
value = CommonValues.name2,
shortName = CommonValues.shortName2,
)

val name3 = NameResponse(
value = CommonValues.name3,
shortName = CommonValues.shortName3,
)

val name4 = NameResponse(
value = CommonValues.name4,
shortName = CommonValues.shortName4,
)

val legalForm1 = LegalFormResponse(
technicalKey = CommonValues.legalFormTechnicalKey1,
name = CommonValues.legalFormName1,
Expand Down Expand Up @@ -224,7 +204,8 @@ object ResponseValues {
val legalEntityResponse1 = LegalEntityResponse(
bpnl = CommonValues.bpn1,
identifiers = listOf(identifier1, identifier2),
legalName = name1,
legalName = CommonValues.name1,
legalShortName = CommonValues.shortName1,
legalForm = legalForm1,
states = listOf(leBusinessStatus1),
classifications = listOf(classification1, classification2),
Expand All @@ -236,7 +217,8 @@ object ResponseValues {
val legalEntityResponse2 = LegalEntityResponse(
bpnl = CommonValues.bpn2,
identifiers = listOf(identifier3, identifier4),
legalName = name3,
legalName = CommonValues.name3,
legalShortName = CommonValues.shortName3,
legalForm = legalForm2,
states = listOf(leBusinessStatus2),
classifications = listOf(classification3, classification4),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,10 @@ class BusinessPartnerBuildService(
bpnL: String,
metadataMap: LegalEntityMetadataMappingDto
): LegalEntity {
val legalName = toEntity(request.legalName)
val legalName = Name(
value = request.legalName,
shortName = request.legalShortName
)
val legalForm = request.legalForm?.let { metadataMap.legalForms[it]!! }

val partner = LegalEntity(
Expand Down Expand Up @@ -347,7 +350,11 @@ class BusinessPartnerBuildService(

partner.currentness = createCurrentnessTimestamp()

partner.legalName = toEntity(request.legalName)
partner.legalName = Name(
value = request.legalName,
shortName = request.legalShortName
)

partner.legalForm = request.legalForm?.let { metadataMap.legalForms[it]!! }

partner.identifiers.clear()
Expand Down Expand Up @@ -501,13 +508,6 @@ class BusinessPartnerBuildService(
)
}

private fun toEntity(dto: NameDto): Name {
return Name(
value = dto.value,
shortName = dto.shortName
)
}

private fun toEntity(dto: ClassificationDto, partner: LegalEntity): Classification {
return Classification(
value = dto.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ fun LegalEntity.toDto(): LegalEntityResponse {
return LegalEntityResponse(
bpnl = bpn,
identifiers = identifiers.map { it.toDto() },
legalName = legalName.toDto(),
legalName = legalName.value,
legalShortName = legalName.shortName,
legalForm = legalForm?.toDto(),
states = states.map { it.toDto() },
classifications = classifications.map { it.toDto() },
Expand Down Expand Up @@ -89,10 +90,6 @@ fun IdentifierType.toDto(): IdentifierTypeDto {
details.map { IdentifierTypeDetailDto(it.countryCode, it.mandatory) })
}

fun Name.toDto(): NameResponse {
return NameResponse(value, shortName)
}

fun LegalForm.toDto(): LegalFormResponse {
return LegalFormResponse(technicalKey, name, abbreviation)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,11 @@ class OpenSearchControllerIT @Autowired constructor(

private fun searchBusinessPartnerByName(name: String): PageResponse<LegalEntityMatchResponse> {

return poolClient.legalEntities().getLegalEntities(LegalEntityPropertiesSearchRequest(name,null,null,null)
, AddressPropertiesSearchRequest.EmptySearchRequest
, SitePropertiesSearchRequest.EmptySearchRequest
, PaginationRequest()
return poolClient.legalEntities().getLegalEntities(
LegalEntityPropertiesSearchRequest(name, null, null, null),
AddressPropertiesSearchRequest.EmptySearchRequest,
SitePropertiesSearchRequest.EmptySearchRequest,
PaginationRequest()
)
}

Expand All @@ -206,7 +207,7 @@ class OpenSearchControllerIT @Autowired constructor(
val pageResult = searchBusinessPartnerByName(name)

assertThat(pageResult.content).isNotEmpty
assertThat(pageResult.content.first()).matches { it.legalEntity.legalName.value == name }
assertThat(pageResult.content.first()).matches { it.legalEntity.legalName == name }
}
}

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

package org.eclipse.tractusx.bpdm.pool.controller

import org.eclipse.tractusx.bpdm.common.dto.NameDto
import org.eclipse.tractusx.bpdm.common.dto.response.PageResponse

import org.eclipse.tractusx.bpdm.pool.Application
import org.eclipse.tractusx.bpdm.pool.api.model.response.BusinessPartnerMatchResponse
import org.eclipse.tractusx.bpdm.pool.api.model.response.BusinessPartnerResponse
Expand Down Expand Up @@ -55,10 +53,7 @@ class BusinessPartnerLegacyControllerIT @Autowired constructor(
LegalEntityStructureRequest(legalEntity = with(RequestValues.legalEntityCreate1) {
copy(
legalEntity = legalEntity.copy(
legalName = NameDto(
uniqueName,
null
)
legalName = uniqueName
)
)
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class SuggestionControllerIT @Autowired constructor(
.build()

private val expectedLegalEntity = ResponseValues.legalEntityUpsert1.legalEntity
private val expectedLegalEntityName = expectedLegalEntity.legalName.value
private val expectedLegalEntityName = expectedLegalEntity.legalName
private val expectedLegalAddress = ResponseValues.legalEntityUpsert1.legalAddress
private val expectedSite = ResponseValues.siteUpsert2

Expand All @@ -94,7 +94,7 @@ class SuggestionControllerIT @Autowired constructor(
Arguments.of(
expectedLegalEntity.legalForm!!.name,
EndpointValues.CATENA_SUGGESTION_LE_LEGAL_FORM_PATH,
expectedLegalEntity.legalName.value
expectedLegalEntity.legalName
),
Arguments.of(
expectedLegalEntity.states.first().officialDenotation,
Expand Down Expand Up @@ -147,7 +147,7 @@ class SuggestionControllerIT @Autowired constructor(
@JvmStatic
fun argumentsSuggestPropertyValuesNonLatin(): Stream<Arguments> =
Stream.of(
Arguments.of(nonlatinLegalEntity.legalName.value, EndpointValues.CATENA_SUGGESTION_LE_NAME_PATH),
Arguments.of(nonlatinLegalEntity.legalName, EndpointValues.CATENA_SUGGESTION_LE_NAME_PATH),
Arguments.of(nonlatinLegalEntity.legalForm!!.name, EndpointValues.CATENA_SUGGESTION_LE_LEGAL_FORM_PATH),
Arguments.of(nonlatinSite.site.name, EndpointValues.CATENA_SUGGESTION_SITE_NAME_PATH),
Arguments.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ import org.eclipse.tractusx.bpdm.pool.api.model.request.*

object RequestValues {

val name1 = NameDto(value = CommonValues.name1, shortName = null)
val name2 = NameDto(value = CommonValues.name2, shortName = null)
val name3 = NameDto(value = CommonValues.name3, shortName = null)
val name4 = NameDto(value = CommonValues.name4, shortName = null)
val name5 = NameDto(value = CommonValues.name5, shortName = null)

val identifierType1 = TypeKeyNameDto(CommonValues.identifierTypeTechnicalKey1, CommonValues.identifierTypeName1)
val identifierType2 = TypeKeyNameDto(CommonValues.identifierTypeTechnicalKey2, CommonValues.identifierTypeName2)
val identifierType3 = TypeKeyNameDto(CommonValues.identifierTypeTechnicalKey3, CommonValues.identifierTypeName3)
Expand Down Expand Up @@ -163,7 +157,8 @@ object RequestValues {

val legalEntityCreate1 = LegalEntityPartnerCreateRequest(
legalEntity = LegalEntityDto(
legalName = name1,
legalName = CommonValues.name1,
legalShortName = null,
identifiers = listOf(identifier1),
legalForm = CommonValues.legalFormTechnicalKey1,
states = listOf(leStatus1),
Expand All @@ -175,7 +170,8 @@ object RequestValues {

val legalEntityCreate2 = LegalEntityPartnerCreateRequest(
legalEntity = LegalEntityDto(
legalName = name3,
legalName = CommonValues.name3,
legalShortName = null,
identifiers = listOf(identifier2),
legalForm = CommonValues.legalFormTechnicalKey2,
states = listOf(leStatus2),
Expand All @@ -187,7 +183,8 @@ object RequestValues {

val legalEntityCreate3 = LegalEntityPartnerCreateRequest(
legalEntity = LegalEntityDto(
legalName = name5,
legalName = CommonValues.name5,
legalShortName = null,
identifiers = listOf(identifier3),
legalForm = CommonValues.legalFormTechnicalKey3,
states = listOf(leStatus3),
Expand Down
Loading

0 comments on commit d938618

Please sign in to comment.