Skip to content

Commit

Permalink
feat(api): eclipse-tractusx#181 Gate API: Nameparts
Browse files Browse the repository at this point in the history
add PoolLegalEntityResponse
  • Loading branch information
rainer-exxcellent committed May 31, 2023
1 parent ed28243 commit 03effc8
Show file tree
Hide file tree
Showing 26 changed files with 178 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ 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 = "LegalEntityResponse", 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 Expand Up @@ -101,7 +100,7 @@ object SaasMappings {
)
}

private fun BusinessPartnerSaas.toNameDto(): SassNameDto? {
fun BusinessPartnerSaas.toNameDto(): SassNameDto? {
if (names.size > 1) {
logger.warn { "Business Partner with ID $externalId has more than one name" }
}
Expand Down Expand Up @@ -293,7 +292,7 @@ object SaasMappings {
)
}

private data class SassNameDto(
data class SassNameDto(
val value: String,
val shortName: String?
) {
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
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 @@ -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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ object RequestValues {

val legalEntity1 = LegalEntityDto(
identifiers = listOf(identifier1, identifier2),
legalName = CommonValues.name1,
legalShortName = CommonValues.shortName1,
legalForm = CommonValues.legalFormTechnicalKey1,
states = listOf(leBusinessStatus1),
Expand All @@ -242,7 +241,6 @@ object RequestValues {

val legalEntity2 = LegalEntityDto(
identifiers = listOf(identifier3, identifier4),
legalName = CommonValues.name3,
legalShortName = CommonValues.shortName3,
legalForm = CommonValues.legalFormTechnicalKey2,
states = listOf(leBusinessStatus2),
Expand All @@ -262,12 +260,14 @@ object RequestValues {

val legalEntityGateInputRequest1 = LegalEntityGateInputRequest(
legalEntity = legalEntity1,
legalNameParts = arrayOf(CommonValues.name1),
externalId = CommonValues.externalId1,
bpn = CommonValues.bpn1
)

val legalEntityGateInputRequest2 = LegalEntityGateInputRequest(
legalEntity = legalEntity2,
legalNameParts = arrayOf(CommonValues.name3),
externalId = CommonValues.externalId2,
bpn = CommonValues.bpn2
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,11 @@ object ResponseValues {
updatedAt = Instant.now()
)


val legalEntityResponse1 = LegalEntityResponse(
val legalEntityResponsePool1 = PoolLegalEntityResponse(
bpnl = CommonValues.bpn1,
identifiers = listOf(identifier1, identifier2),
legalName = CommonValues.name1,
legalShortName = CommonValues.shortName1,
legalName = CommonValues.name1,
legalForm = legalForm1,
states = listOf(leBusinessStatus1),
classifications = listOf(classification1, classification2),
Expand All @@ -214,10 +213,34 @@ object ResponseValues {
updatedAt = CommonValues.now
)

val legalEntityResponse2 = LegalEntityResponse(
val legalEntityResponsePool2 = PoolLegalEntityResponse(
bpnl = CommonValues.bpn2,
identifiers = listOf(identifier3, identifier4),
legalShortName = CommonValues.shortName3,
legalName = CommonValues.name3,
legalForm = legalForm2,
states = listOf(leBusinessStatus2),
classifications = listOf(classification3, classification4),
currentness = CommonValues.now,
createdAt = CommonValues.now,
updatedAt = CommonValues.now
)

val legalEntityResponseGate1 = LegalEntityResponse(
bpnl = CommonValues.bpn1,
identifiers = listOf(identifier1, identifier2),
legalShortName = CommonValues.shortName1,
legalForm = legalForm1,
states = listOf(leBusinessStatus1),
classifications = listOf(classification1, classification2),
currentness = CommonValues.now,
createdAt = CommonValues.now,
updatedAt = CommonValues.now
)

val legalEntityResponseGate2 = LegalEntityResponse(
bpnl = CommonValues.bpn2,
identifiers = listOf(identifier3, identifier4),
legalShortName = CommonValues.shortName3,
legalForm = legalForm2,
states = listOf(leBusinessStatus2),
Expand Down Expand Up @@ -263,13 +286,15 @@ object ResponseValues {
)

val legalEntityGateOutput1 = LegalEntityGateOutput(
legalEntity = legalEntityResponse1,
legalEntity = legalEntityResponseGate1,
legalNameParts = arrayOf(CommonValues.name1),
legalAddress = logisticAddress1,
externalId = CommonValues.externalId1
)

val legalEntityGateOutput2 = LegalEntityGateOutput(
legalEntity = legalEntityResponse2,
legalEntity = legalEntityResponseGate2,
legalNameParts = arrayOf(CommonValues.name3),
legalAddress = logisticAddress2,
externalId = CommonValues.externalId2
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ interface PoolLegalEntityApi {
@Parameter(description = "Identifier value") @PathVariable idValue: String,
@Parameter(description = "Type of identifier to use, defaults to BPN when omitted", schema = Schema(defaultValue = "BPN"))
@RequestParam idType: String? = "BPN"
): LegalEntityResponse
): PoolLegalEntityResponse

@Operation(
summary = "Confirms that the data of a legal entity business partner is still up to date.",
Expand Down Expand Up @@ -130,7 +130,7 @@ interface PoolLegalEntityApi {
@PostExchange("/search")
fun searchSites(
@RequestBody bpnLs: Collection<String>
): ResponseEntity<Collection<LegalEntityResponse>>
): ResponseEntity<Collection<PoolLegalEntityResponse>>

@Operation(
summary = "Get site partners of a legal entity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializ
@JsonDeserialize(using = DataClassUnwrappedJsonDeserializer::class)
@Schema(name = "LegalEntityPartnerCreateRequest", description = "Request for creating new business partner record of type legal entity")
data class LegalEntityPartnerCreateRequest(

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

@field:JsonUnwrapped
val legalEntity: LegalEntityDto,

@Schema(description = "User defined index to conveniently match this entry to the corresponding entry in the response")
val index: String?
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ import io.swagger.v3.oas.annotations.media.Schema
import org.eclipse.tractusx.bpdm.common.dto.LegalEntityDto
import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializer


@JsonDeserialize(using = DataClassUnwrappedJsonDeserializer::class)
@Schema(name = "LegalEntityUpdateRequest", description = "Request for updating a business partner record of type legal entity")
data class LegalEntityPartnerUpdateRequest(
@Schema(description = "Business Partner Number")
val bpnl: String,

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

@field:JsonUnwrapped
val legalEntity: LegalEntityDto
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import com.fasterxml.jackson.annotation.JsonUnwrapped
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import io.swagger.v3.oas.annotations.media.Schema
import org.eclipse.tractusx.bpdm.common.dto.response.LogisticAddressResponse
import org.eclipse.tractusx.bpdm.common.dto.response.LegalEntityResponse
import org.eclipse.tractusx.bpdm.common.dto.response.PoolLegalEntityResponse
import org.eclipse.tractusx.bpdm.common.dto.response.SiteResponse
import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializer

Expand All @@ -33,7 +33,7 @@ data class BusinessPartnerResponse(
val uuid: String,

@field:JsonUnwrapped
val legalEntity: LegalEntityResponse,
val legalEntity: PoolLegalEntityResponse,

val addresses: Collection<LogisticAddressResponse>,

Expand Down
Loading

0 comments on commit 03effc8

Please sign in to comment.