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
… - refactor SaasMappings
  • Loading branch information
rainer-exxcellent committed May 30, 2023
1 parent d53fc50 commit 03e11a2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ object SaasMappings {
)
}

private fun BusinessPartnerSaas.toNameDto(): NameDto? {
private fun BusinessPartnerSaas.toNameDto(): SassNameDto? {
if (names.size > 1) {
logger.warn { "Business Partner with ID $externalId has more than one name" }
}
return names.map { toDto(it) }
return names.map { SassNameDto(it) }
.firstOrNull()
}

Expand All @@ -124,13 +124,6 @@ object SaasMappings {
)
}

fun toDto(name: NameSaas): NameDto {
return NameDto(
name.value,
name.shortName
)
}

fun toLegalEntityStatesDtos(status: BusinessPartnerStatusSaas?): Collection<LegalEntityStateDto> =
listOfNotNull(
status?.type?.let {
Expand Down Expand Up @@ -300,4 +293,12 @@ object SaasMappings {
)
}

private data class SassNameDto(
val value: String,
val shortName: String?
) {
constructor(nameSass: NameSaas) :
this(value = nameSass.value, shortName = nameSass.shortName)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,6 @@ class SaasRequestMappingService(

private fun toLegalFormSaas(technicalKey: String?) = if (technicalKey != null) LegalFormSaas(technicalKey = technicalKey) else null

private fun NameDto.toSaasModel(): NameSaas {
return NameSaas(
value = value,
shortName = shortName
)
}

private fun LegalEntityIdentifierDto.toSaasModel(): IdentifierSaas {
return IdentifierSaas(
type = TypeKeyNameUrlSaas(type),
Expand Down Expand Up @@ -184,9 +177,6 @@ class SaasRequestMappingService(
)
}

private fun toNamesSaas(nameDto: NameDto): List<NameSaas> =
listOf(nameDto.toSaasModel())

private fun toNamesSaas(name: String?): List<NameSaas> =
name?.let { listOf(NameSaas(value = it)) } ?: emptyList()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import com.github.tomakehurst.wiremock.junit5.WireMockExtension
import org.assertj.core.api.Assertions.assertThat
import org.eclipse.tractusx.bpdm.common.dto.saas.*
import org.eclipse.tractusx.bpdm.gate.api.client.GateClient
import org.eclipse.tractusx.bpdm.gate.api.model.BusinessPartnerCandidateDto
import org.eclipse.tractusx.bpdm.gate.api.model.response.OptionalLsaType
import org.eclipse.tractusx.bpdm.gate.api.model.response.TypeMatchResponse
import org.eclipse.tractusx.bpdm.gate.config.TypeMatchConfigProperties
Expand Down Expand Up @@ -88,6 +89,12 @@ class BusinessPartnerControllerIT @Autowired constructor(
}
}

val candidate1 = BusinessPartnerCandidateDto(
identifiers = listOf(RequestValues.genericIdentifier),
names = listOf(RequestValues.name1),
address = RequestValues.address1
)

/**
* Given business partner candidate whose properties are matching existing legal entity
* When invoking type match for candidate
Expand All @@ -96,7 +103,7 @@ class BusinessPartnerControllerIT @Autowired constructor(
@Test
fun `match legal entity type`() {
//make sure candidate is valid by providing identifier and name
val givenCandidate = with(RequestValues.candidate1) {
val givenCandidate = with(candidate1) {
copy(
identifiers = listOf(RequestValues.genericIdentifier),
names = listOf(RequestValues.name1)
Expand All @@ -121,7 +128,7 @@ class BusinessPartnerControllerIT @Autowired constructor(
@Test
fun `match no type`() {
//make sure candidate is valid by providing identifier and name
val givenCandidate = with(RequestValues.candidate1) {
val givenCandidate = with(candidate1) {
copy(
identifiers = listOf(RequestValues.genericIdentifier),
names = listOf(RequestValues.name1)
Expand All @@ -146,7 +153,7 @@ class BusinessPartnerControllerIT @Autowired constructor(
@Test
fun `accept candidate without name`() {
//create candidate without name
val givenCandidate = with(RequestValues.candidate1) {
val givenCandidate = with(candidate1) {
copy(
identifiers = listOf(RequestValues.genericIdentifier),
names = emptyList()
Expand All @@ -171,7 +178,7 @@ class BusinessPartnerControllerIT @Autowired constructor(
@Test
fun `accept candidate without identifier`() {
//create candidate without identifier
val givenCandidate = with(RequestValues.candidate1) {
val givenCandidate = with(candidate1) {
copy(
identifiers = emptyList(),
names = listOf(RequestValues.name1)
Expand All @@ -196,7 +203,7 @@ class BusinessPartnerControllerIT @Autowired constructor(
@Test
fun `refuse candidate without name and identifier`() {
//create candidate without identifier
val givenCandidate = with(RequestValues.candidate1) {
val givenCandidate = with(candidate1) {
copy(
identifiers = emptyList(),
names = emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package org.eclipse.tractusx.bpdm.gate.util

import org.eclipse.tractusx.bpdm.common.dto.*
import org.eclipse.tractusx.bpdm.gate.api.model.AddressGateInputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.BusinessPartnerCandidateDto
import org.eclipse.tractusx.bpdm.gate.api.model.LegalEntityGateInputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.SiteGateInputRequest

Expand Down Expand Up @@ -328,9 +327,4 @@ object RequestValues {
bpn = CommonValues.bpnAddress2
)

val candidate1 = BusinessPartnerCandidateDto(
identifiers = listOf(genericIdentifier),
names = listOf(name1),
address = address1
)
}

0 comments on commit 03e11a2

Please sign in to comment.