Skip to content

Commit

Permalink
Merge pull request #214 from catenax-ng/feat/gate_api_nameparts
Browse files Browse the repository at this point in the history
Feat/gate api nameparts
  • Loading branch information
nicoprow authored Jun 1, 2023
2 parents f7f421a + f10b623 commit 6202ae1
Show file tree
Hide file tree
Showing 34 changed files with 235 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package com.catenax.bpdm.bridge.dummy.dto
import org.eclipse.tractusx.bpdm.common.dto.LegalEntityDto

data class GateLegalEntityInfo(
val legalNameParts: Array<String> = emptyArray(),
val legalEntity: LegalEntityDto,
val externalId: String,
val bpn: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class PoolUpdateService(
val createRequests = entriesToCreate.map {
LegalEntityPartnerCreateRequest(
legalEntity = it.legalEntity,
index = it.externalId
index = it.externalId,
legalName = it.legalNameParts[0]
)
}

Expand All @@ -53,7 +54,8 @@ class PoolUpdateService(
val updateRequests = entriesToUpdate.map {
LegalEntityPartnerUpdateRequest(
legalEntity = it.legalEntity,
bpnl = it.bpn!!
bpnl = it.bpn!!,
legalName = it.legalNameParts[0]
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ import io.swagger.v3.oas.annotations.media.Schema
data class LegalEntityDto(
@ArraySchema(arraySchema = Schema(description = "Additional identifiers (except BPN)", required = false))
val identifiers: Collection<LegalEntityIdentifierDto> = emptyList(),

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


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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import io.swagger.v3.oas.annotations.media.ArraySchema
import io.swagger.v3.oas.annotations.media.Schema
import java.time.Instant

// TODO probably rename to LegalEntityDetailedDto

@Schema(name = "LegalEntityResponse", description = "Legal entity record")
data class LegalEntityResponse(
@get:Schema(description = "Business Partner Number of this legal entity")
Expand All @@ -32,9 +32,6 @@ data class LegalEntityResponse(
@ArraySchema(arraySchema = Schema(description = "All identifiers of the business partner, including BPN information"))
val identifiers: Collection<LegalEntityIdentifierResponse> = emptyList(),

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

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

import io.swagger.v3.oas.annotations.media.ArraySchema
import io.swagger.v3.oas.annotations.media.Schema
import java.time.Instant

@Schema(name = "PoolLegalEntityResponse", description = "Legal entity record")
data class PoolLegalEntityResponse(
@get:Schema(description = "Business Partner Number of this legal entity")
val bpnl: String,

@ArraySchema(arraySchema = Schema(description = "All identifiers of the business partner, including BPN information"))
val identifiers: Collection<LegalEntityIdentifierResponse> = emptyList(),

@get:Schema(description = "Legal name the partner goes by")
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,

@ArraySchema(arraySchema = Schema(description = "Business status"))
val states: Collection<LegalEntityStateResponse> = emptyList(),

@ArraySchema(arraySchema = Schema(description = "Classifications"))
val classifications: Collection<ClassificationResponse> = emptyList(),

@ArraySchema(arraySchema = Schema(description = "Relations to other business partners"))
val relations: Collection<RelationResponse> = emptyList(),

@get:Schema(description = "The timestamp the business partner data was last indicated to be still current")
val currentness: Instant,

@get:Schema(description = "The timestamp the business partner data was created")
val createdAt: Instant,

@get:Schema(description = "The timestamp the business partner data was last updated")
val updatedAt: Instant
)
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ 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.value,
legalShortName = legalName.shortName,
legalForm = toOptionalReference(legalForm),
states = toLegalEntityStatesDtos(status),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializ
@JsonDeserialize(using = DataClassUnwrappedJsonDeserializer::class)
@Schema(name = "LegalEntityGateInputRequest", description = "Legal entity with external id")
data class LegalEntityGateInputRequest(

val legalNameParts: Array<String> = emptyArray(),

@field:JsonUnwrapped
val legalEntity: LegalEntityDto,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import java.time.LocalDateTime
@JsonDeserialize(using = DataClassUnwrappedJsonDeserializer::class)
@Schema(name = "LegalEntityGateInputResponse", description = "Legal entity with external id")
data class LegalEntityGateInputResponse(

val legalNameParts: Array<String> = emptyArray(),

@field:JsonUnwrapped
val legalEntity: LegalEntityDto,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializ
@JsonDeserialize(using = DataClassUnwrappedJsonDeserializer::class)
@Schema(name = "LegalEntityGateOutput", description = "Legal entity with references")
data class LegalEntityGateOutput(

val legalNameParts: Array<String> = emptyArray(),

@field:JsonUnwrapped
val legalEntity: LegalEntityResponse,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class LegalEntityPersistenceService(
legalEntity.bpn = legalEntityRequest.bpn
legalEntity.externalId = legalEntityRequest.externalId
legalEntity.legalForm = legalEntityRequest.legalEntity.legalForm
legalEntity.legalName = Name(value = legalEntityRequest.legalEntity.legalName, shortName = legalEntityRequest.legalEntity.legalShortName)
legalEntity.legalName = Name(value = legalEntityRequest.legalNameParts[0], 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 @@ -22,6 +22,10 @@ package org.eclipse.tractusx.bpdm.gate.service
import mu.KotlinLogging
import org.eclipse.tractusx.bpdm.common.dto.response.LegalEntityResponse
import org.eclipse.tractusx.bpdm.common.dto.response.LogisticAddressResponse
import org.eclipse.tractusx.bpdm.common.dto.response.PoolLegalEntityResponse
import org.eclipse.tractusx.bpdm.common.dto.saas.BusinessPartnerSaas
import org.eclipse.tractusx.bpdm.common.dto.saas.FetchResponse
import org.eclipse.tractusx.bpdm.common.exception.BpdmMappingException
import org.eclipse.tractusx.bpdm.common.dto.response.PageResponse
import org.eclipse.tractusx.bpdm.common.exception.BpdmNotFoundException
import org.eclipse.tractusx.bpdm.gate.api.model.LegalEntityGateInputRequest
Expand Down Expand Up @@ -129,9 +133,21 @@ class LegalEntityService(
)
}

fun toLegalEntityOutput(externalId: String, legalEntity: LegalEntityResponse, legalAddress: LogisticAddressResponse): LegalEntityGateOutput =
fun toLegalEntityOutput(externalId: String, legalEntityPool: PoolLegalEntityResponse, legalAddress: LogisticAddressResponse): LegalEntityGateOutput =
LegalEntityGateOutput(
legalEntity = legalEntity,
legalEntity = LegalEntityResponse(
bpnl = legalEntityPool.bpnl,
identifiers = legalEntityPool.identifiers,
legalShortName = legalEntityPool.legalShortName,
legalForm = legalEntityPool.legalForm,
states = legalEntityPool.states,
classifications = legalEntityPool.classifications,
relations = legalEntityPool.relations,
currentness = legalEntityPool.currentness,
createdAt = legalEntityPool.createdAt,
updatedAt = legalEntityPool.updatedAt,
),
legalNameParts = arrayOf(legalEntityPool.legalName),
legalAddress = legalAddress,
externalId = externalId
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PoolClient(
private val webClient: WebClient,
private val objectMapper: ObjectMapper
) {
fun searchLegalEntities(bpnLs: Collection<String>): Collection<LegalEntityResponse> {
fun searchLegalEntities(bpnLs: Collection<String>): Collection<PoolLegalEntityResponse> {
if (bpnLs.isEmpty()) return emptyList()

val legalEntities = try {
Expand All @@ -44,7 +44,7 @@ class PoolClient(
.uri("/legal-entities/search")
.bodyValue(objectMapper.writeValueAsString(bpnLs))
.retrieve()
.bodyToMono<Collection<LegalEntityResponse>>()
.bodyToMono<Collection<PoolLegalEntityResponse>>()
.block()!!
} catch (e: Exception) {
throw PoolRequestException("Request to search legal entities failed.", e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ fun LegalEntityGateInputRequest.toLegalEntity(): LegalEntity {
externalId = externalId,
currentness = createCurrentnessTimestamp(),
legalForm = legalEntity.legalForm,
legalName = Name(legalEntity.legalName, legalEntity.legalShortName)
legalName = Name(legalNameParts[0], legalEntity.legalShortName)
)
legalEntity.identifiers.addAll(this.legalEntity.identifiers.map { toEntityIdentifier(it, legalEntity) })
legalEntity.states.addAll(this.legalEntity.states.map { toEntityState(it, legalEntity) })
Expand Down Expand Up @@ -293,7 +293,6 @@ private fun Street.toStreetDto(): StreetDto {

fun LegalEntity.toLegalEntityDto(): LegalEntityDto {
return LegalEntityDto(
legalName = legalName.value,
legalForm = legalForm,
legalShortName = legalName.shortName,
legalAddress = legalAddress.toLogisticAddressDto(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SaasRequestMappingService(
dataSource = saasConfigProperties.datasource,
types = listOf(TypeKeyNameUrlSaas(BusinessPartnerTypeSaas.LEGAL_ENTITY.name)),
identifiers = toLegalEntityIdentifiersSaas(legalEntity.identifiers, request.bpn),
names = toNamesSaas(legalEntity.legalName),
names = toNamesSaas(request.legalNameParts[0]),
// TODO Only the first state is passed to SaaS, any others are ignored
status = legalEntity.states.map { it.toSaasModel() }.firstOrNull(),
legalForm = toLegalFormSaas(legalEntity.legalForm),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,11 @@ internal class LegalEntityControllerInputIT @Autowired constructor(
content = expectedLegalEntities
)

// TODO check administrativeAreaLevel1
assertThat(pageResponse).usingRecursiveComparison().ignoringCollectionOrder().ignoringAllOverriddenEquals()
.ignoringFieldsMatchingRegexes(".*processStartedAt*", ".*administrativeAreaLevel1*").isEqualTo(
expectedPage
)
expectedPage
)
}


Expand Down Expand Up @@ -286,8 +287,8 @@ internal class LegalEntityControllerInputIT @Autowired constructor(

assertThat(pageResponse).usingRecursiveComparison().ignoringCollectionOrder().ignoringAllOverriddenEquals()
.ignoringFieldsMatchingRegexes(".*processStartedAt*", ".*administrativeAreaLevel1*").isEqualTo(
expectedPage
)
expectedPage
)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.github.tomakehurst.wiremock.client.WireMock.*
import com.github.tomakehurst.wiremock.core.WireMockConfiguration
import com.github.tomakehurst.wiremock.junit5.WireMockExtension
import org.assertj.core.api.Assertions.assertThat
import org.eclipse.tractusx.bpdm.common.dto.saas.AugmentedBusinessPartnerResponseSaas
import org.eclipse.tractusx.bpdm.common.dto.saas.PagedResponseSaas
import org.eclipse.tractusx.bpdm.gate.api.client.GateClient
Expand All @@ -50,7 +49,8 @@ import org.springframework.test.context.DynamicPropertySource
@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class])
internal class LegalEntityControllerOutputIT @Autowired constructor(
private val objectMapper: ObjectMapper,
val gateClient: GateClient
val gateClient: GateClient,
private val testHelpers: DbTestHelpers
) {
companion object {
@RegisterExtension
Expand Down Expand Up @@ -105,8 +105,8 @@ internal class LegalEntityControllerOutputIT @Autowired constructor(
)

val legalEntitiesPool = listOf(
ResponseValues.legalEntityResponse1,
ResponseValues.legalEntityResponse2
ResponseValues.legalEntityResponsePool1,
ResponseValues.legalEntityResponsePool2
)
val legalAddressesPool = listOf(
ResponseValues.logisticAddress1,
Expand Down Expand Up @@ -178,17 +178,17 @@ internal class LegalEntityControllerOutputIT @Autowired constructor(

val paginationValue = PaginationStartAfterRequest(startAfter, limit)
val pageResponse = gateClient.legalEntities().getLegalEntitiesOutput(paginationValue, emptyList())

assertThat(pageResponse).isEqualTo(
PageOutputResponse(
total = total,
nextStartAfter = nextStartAfter,
content = expectedLegalEntities,
invalidEntries = expectedPending.size + expectedErrors.size,
pending = expectedPending,
errors = expectedErrors,
)
val expectedResponse = PageOutputResponse(
total = total,
nextStartAfter = nextStartAfter,
content = expectedLegalEntities,
invalidEntries = expectedPending.size + expectedErrors.size,
pending = expectedPending,
errors = expectedErrors,
)


testHelpers.assertRecursively(pageResponse).isEqualTo(expectedResponse)
}

/**
Expand All @@ -209,8 +209,8 @@ internal class LegalEntityControllerOutputIT @Autowired constructor(
)

val legalEntitiesPool = listOf(
ResponseValues.legalEntityResponse1,
ResponseValues.legalEntityResponse2
ResponseValues.legalEntityResponsePool1,
ResponseValues.legalEntityResponsePool2
)
val legalAddressesPool = listOf(
ResponseValues.logisticAddress1,
Expand Down Expand Up @@ -283,16 +283,14 @@ internal class LegalEntityControllerOutputIT @Autowired constructor(

val paginationValue = PaginationStartAfterRequest(startAfter, limit)
val pageResponse = gateClient.legalEntities().getLegalEntitiesOutput(paginationValue, listOf(CommonValues.externalId1, CommonValues.externalId2))

assertThat(pageResponse).isEqualTo(
PageOutputResponse(
total = total,
nextStartAfter = nextStartAfter,
content = expectedLegalEntities,
invalidEntries = 0,
pending = listOf(),
errors = listOf(),
)
val expectedResponse = PageOutputResponse(
total = total,
nextStartAfter = nextStartAfter,
content = expectedLegalEntities,
invalidEntries = 0,
pending = listOf(),
errors = listOf(),
)
testHelpers.assertRecursively(pageResponse).isEqualTo(expectedResponse)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ package org.eclipse.tractusx.bpdm.gate.util

import jakarta.persistence.EntityManager
import jakarta.persistence.EntityManagerFactory
import org.assertj.core.api.Assertions
import org.assertj.core.api.RecursiveComparisonAssert
import org.springframework.stereotype.Component
import java.time.Instant

private const val BPDM_DB_SCHEMA_NAME: String = "bpdmgate"

Expand Down Expand Up @@ -50,5 +53,13 @@ class DbTestHelpers(entityManagerFactory: EntityManagerFactory) {

em.transaction.commit()
}


fun <T> assertRecursively(actual: T): RecursiveComparisonAssert<*> {
return Assertions.assertThat(actual)
.usingRecursiveComparison()
.ignoringCollectionOrder()
.ignoringAllOverriddenEquals()
.ignoringFieldsOfTypes(Instant::class.java)
}

}
Loading

0 comments on commit 6202ae1

Please sign in to comment.