Skip to content

Commit

Permalink
feat(api): eclipse-tractusx#179 Pool API: Legal Entity Response shoul…
Browse files Browse the repository at this point in the history
…d include Legal Address
  • Loading branch information
rainer-exxcellent committed Jun 1, 2023
1 parent afec8ab commit cfe67be
Show file tree
Hide file tree
Showing 19 changed files with 278 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class GateUpdateService(
) {
for (entity in responseWrapper.entities) {
val externalId = entity.index
buildSuccessSharingStateDto(LsaType.LegalEntity, externalId, entity.legalEntity.bpnl, true)
buildSuccessSharingStateDto(LsaType.LegalEntity, externalId, entity.poolLegalEntity.bpnl, true)
?.let { gateClient.sharingState().upsertSharingState(it) }
}
for (errorInfo in responseWrapper.errors) {
Expand All @@ -57,7 +57,7 @@ class GateUpdateService(
externalIdByBpn: Map<String, String>
) {
for (entity in responseWrapper.entities) {
val bpn = entity.legalEntity.bpnl
val bpn = entity.poolLegalEntity.bpnl
val externalId = externalIdByBpn[bpn]
buildSuccessSharingStateDto(LsaType.LegalEntity, externalId, bpn, false)
?.let { gateClient.sharingState().upsertSharingState(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ data class LegalEntityResponse(
@ArraySchema(arraySchema = Schema(description = "Relations to other business partners"))
val relations: Collection<RelationResponse> = emptyList(),

@get:Schema(description = "Address of the official seat of this legal entity")
val legalAddress: LogisticAddressResponse,

@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
)
val updatedAt: Instant,

)
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,14 @@

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
@Schema(description = "Legal Entity")
val legalEntity: LegalEntityResponse,
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.eclipse.tractusx.bpdm.gate.api.model

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.LegalEntityDto
Expand All @@ -31,7 +30,7 @@ data class LegalEntityGateInputRequest(

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

@field:JsonUnwrapped
@Schema(description = "legal Enity")
val legalEntity: LegalEntityDto,

@Schema(description = "ID the record has in the external system where the record originates from", required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
package org.eclipse.tractusx.bpdm.gate.api.model


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.LegalEntityResponse
import org.eclipse.tractusx.bpdm.common.dto.response.LogisticAddressResponse
import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializer

@JsonDeserialize(using = DataClassUnwrappedJsonDeserializer::class)
Expand All @@ -33,12 +31,9 @@ data class LegalEntityGateOutput(

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

@field:JsonUnwrapped
@Schema(description = "Legal Entity")
val legalEntity: LegalEntityResponse,

@Schema(description = "Address of the official seat of this legal entity")
val legalAddress: LogisticAddressResponse,

@Schema(description = "ID the record has in the external system where the record originates from")
val externalId: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class LegalEntityService(

//Search entries in the pool with BPNs found in the local mirror
val bpnSet = partnersWithLocalBpn.map { it.bpn }.toSet()
val legalEntitiesByBpnMap = poolClient.searchLegalEntities(bpnSet).associateBy { it.bpnl }
val legalEntitiesByBpnMap = poolClient.searchLegalEntities(bpnSet).associateBy { it.legalEntity.bpnl }
val legalAddressesByBpnMap = poolClient.searchLegalAddresses(bpnSet).associateBy { it.bpnLegalEntity }

if (bpnSet.size > legalEntitiesByBpnMap.size) {
Expand Down Expand Up @@ -136,19 +136,19 @@ class LegalEntityService(
fun toLegalEntityOutput(externalId: String, legalEntityPool: PoolLegalEntityResponse, legalAddress: LogisticAddressResponse): LegalEntityGateOutput =
LegalEntityGateOutput(
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,
bpnl = legalEntityPool.legalEntity.bpnl,
identifiers = legalEntityPool.legalEntity.identifiers,
legalShortName = legalEntityPool.legalEntity.legalShortName,
legalForm = legalEntityPool.legalEntity.legalForm,
states = legalEntityPool.legalEntity.states,
classifications = legalEntityPool.legalEntity.classifications,
relations = legalEntityPool.legalEntity.relations,
currentness = legalEntityPool.legalEntity.currentness,
createdAt = legalEntityPool.legalEntity.createdAt,
updatedAt = legalEntityPool.legalEntity.updatedAt,
legalAddress = legalEntityPool.legalEntity.legalAddress,
),
legalNameParts = arrayOf(legalEntityPool.legalName),
legalAddress = legalAddress,
externalId = externalId
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,29 +201,36 @@ object ResponseValues {
)

val legalEntityResponsePool1 = PoolLegalEntityResponse(
bpnl = CommonValues.bpn1,
identifiers = listOf(identifier1, identifier2),
legalShortName = CommonValues.shortName1,
legalName = CommonValues.name1,
legalForm = legalForm1,
states = listOf(leBusinessStatus1),
classifications = listOf(classification1, classification2),
currentness = CommonValues.now,
createdAt = CommonValues.now,
updatedAt = CommonValues.now
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,
legalAddress = logisticAddress1
)

)

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
LegalEntityResponse(
bpnl = CommonValues.bpn2,
identifiers = listOf(identifier3, identifier4),
legalShortName = CommonValues.shortName3,
legalForm = legalForm2,
states = listOf(leBusinessStatus2),
classifications = listOf(classification3, classification4),
currentness = CommonValues.now,
createdAt = CommonValues.now,
updatedAt = CommonValues.now,
legalAddress = logisticAddress2
)
)

val legalEntityResponseGate1 = LegalEntityResponse(
Expand All @@ -235,7 +242,8 @@ object ResponseValues {
classifications = listOf(classification1, classification2),
currentness = CommonValues.now,
createdAt = CommonValues.now,
updatedAt = CommonValues.now
updatedAt = CommonValues.now,
legalAddress = logisticAddress1,
)

val legalEntityResponseGate2 = LegalEntityResponse(
Expand All @@ -247,7 +255,8 @@ object ResponseValues {
classifications = listOf(classification3, classification4),
currentness = CommonValues.now,
createdAt = CommonValues.now,
updatedAt = CommonValues.now
updatedAt = CommonValues.now,
legalAddress = logisticAddress2,
)

val legalEntityGateInputResponse1 = LegalEntityGateInputResponse(
Expand Down Expand Up @@ -288,14 +297,12 @@ object ResponseValues {
val legalEntityGateOutput1 = LegalEntityGateOutput(
legalEntity = legalEntityResponseGate1,
legalNameParts = arrayOf(CommonValues.name1),
legalAddress = logisticAddress1,
externalId = CommonValues.externalId1
)

val legalEntityGateOutput2 = LegalEntityGateOutput(
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 @@ -27,7 +27,7 @@ import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializ


@JsonDeserialize(using = DataClassUnwrappedJsonDeserializer::class)
@Schema(name = "LegalEntityUpdateRequest", description = "Request for updating a business partner record of type legal entity")
@Schema(name = "LegalEntityPartnerUpdateRequest", description = "Request for updating a business partner record of type legal entity")
data class LegalEntityPartnerUpdateRequest(
@Schema(description = "Business Partner Number")
val bpnl: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@

package org.eclipse.tractusx.bpdm.pool.api.model.response

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.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.response.SiteResponse
import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializer

Expand All @@ -32,8 +31,11 @@ import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializ
data class BusinessPartnerResponse(
val uuid: String,

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

@Schema(description = "Legal Entity")
val legalEntity: LegalEntityResponse,

val addresses: Collection<LogisticAddressResponse>,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
package org.eclipse.tractusx.bpdm.pool.api.model.response

import io.swagger.v3.oas.annotations.media.Schema
import org.eclipse.tractusx.bpdm.common.dto.response.PoolLegalEntityResponse
import org.eclipse.tractusx.bpdm.common.dto.response.LegalEntityResponse

@Schema(name = "LegalEntityMatchResponse", description = "Match with score for a business partner record of type legal entity")
data class LegalEntityMatchResponse(
@Schema(description = "Relative quality score of the match. The higher the better")
val score: Float,

@Schema(description = "Matched legal entity business partner record")
val legalEntity: PoolLegalEntityResponse
@get:Schema(description = "Legal name the partner goes by")
val legalName: String,

@Schema(description = "Legal Entity")
val legalEntity: LegalEntityResponse
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,20 @@

package org.eclipse.tractusx.bpdm.pool.api.model.response

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.PoolLegalEntityResponse
import org.eclipse.tractusx.bpdm.common.dto.response.LegalEntityResponse
import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializer

@JsonDeserialize(using = DataClassUnwrappedJsonDeserializer::class)
@Schema(name = "LegalEntityPartnerCreateResponse", description = "Created business partner of type legal entity")
data class LegalEntityPartnerCreateResponse(
@field:JsonUnwrapped
val legalEntity: PoolLegalEntityResponse,

@Schema(description = "Address of the official seat of this of the legal entity")
val legalAddress: LogisticAddressResponse,
@get:Schema(description = "Legal name the partner goes by")
val legalName: String,

@Schema(description = "Legal Entity")
val legalEntity: LegalEntityResponse,

@Schema(description = "User defined index to conveniently match this entry to the corresponding entry from the request")
val index: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class BusinessPartnerFetchService(
* Fetch a business partner by [bpn] and return as [PoolLegalEntityResponse]
*/
fun findLegalEntityIgnoreCase(bpn: String): PoolLegalEntityResponse {
return findLegalEntityOrThrow(bpn).toDto()
return findLegalEntityOrThrow(bpn).toPoolLegalEntity()
}

fun findBusinessPartnerIgnoreCase(bpn: String): BusinessPartnerResponse {
Expand All @@ -65,7 +65,7 @@ class BusinessPartnerFetchService(
*/
@Transactional
fun findLegalEntityIgnoreCase(identifierType: String, identifierValue: String): PoolLegalEntityResponse {
return findLegalEntityOrThrow(identifierType, identifierValue).toDto()
return findLegalEntityOrThrow(identifierType, identifierValue).toPoolLegalEntity()
}


Expand All @@ -87,7 +87,7 @@ class BusinessPartnerFetchService(
*/
@Transactional
fun fetchDtosByBpns(bpns: Collection<String>): Collection<PoolLegalEntityResponse> {
return fetchByBpns(bpns).map { it.toDto() }
return fetchByBpns(bpns).map { it.toPoolLegalEntity() }
}

/**
Expand Down
Loading

0 comments on commit cfe67be

Please sign in to comment.