Skip to content

Commit

Permalink
feat(dto): API adjustment - Rename/refactor field/enum LsaType/Change…
Browse files Browse the repository at this point in the history
…logSubject to BusinessPartnerType
  • Loading branch information
martinfkaeser committed Jul 26, 2023
1 parent 8d3da50 commit c33864e
Show file tree
Hide file tree
Showing 58 changed files with 368 additions and 375 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import com.catenax.bpdm.bridge.dummy.dto.GateAddressInfo
import com.catenax.bpdm.bridge.dummy.dto.GateLegalEntityInfo
import com.catenax.bpdm.bridge.dummy.dto.GateSiteInfo
import mu.KotlinLogging
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerType
import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest
import org.eclipse.tractusx.bpdm.gate.api.client.GateClient
import org.eclipse.tractusx.bpdm.gate.api.model.LsaType
import org.eclipse.tractusx.bpdm.gate.api.model.request.ChangeLogSearchRequest
import org.eclipse.tractusx.bpdm.gate.api.model.response.*
import org.springframework.stereotype.Service
Expand All @@ -40,7 +40,7 @@ class GateQueryService(

private val logger = KotlinLogging.logger { }

fun getChangedExternalIdsByLsaType(modifiedAfter: Instant?): Map<LsaType, Set<String>> {
fun getChangedExternalIdsByBusinessPartnerType(modifiedAfter: Instant?): Map<BusinessPartnerType, Set<String>> {
var page = 0
var totalPages: Int
val content = mutableListOf<ChangelogGateDto>()
Expand All @@ -61,16 +61,16 @@ class GateQueryService(
.also {
logger.info {
"Changed entries in Gate since last sync: " +
"${it[LsaType.LEGAL_ENTITY]?.size ?: 0} legal entities, " +
"${it[LsaType.SITE]?.size ?: 0} sites, " +
"${it[LsaType.ADDRESS]?.size ?: 0} addresses"
"${it[BusinessPartnerType.LEGAL_ENTITY]?.size ?: 0} legal entities, " +
"${it[BusinessPartnerType.SITE]?.size ?: 0} sites, " +
"${it[BusinessPartnerType.ADDRESS]?.size ?: 0} addresses"
}
}
}

fun getLegalEntityInfos(externalIds: Set<String>): Collection<GateLegalEntityInfo> {
val entries = getLegalEntitiesInput(externalIds)
val bpnByExternalId = getBpnByExternalId(LsaType.LEGAL_ENTITY, externalIds)
val bpnByExternalId = getBpnByExternalId(BusinessPartnerType.LEGAL_ENTITY, externalIds)

return entries.map {
GateLegalEntityInfo(
Expand All @@ -85,7 +85,7 @@ class GateQueryService(

fun getSiteInfos(externalIds: Set<String>): Collection<GateSiteInfo> {
val entries = getSitesInput(externalIds)
val bpnByExternalId = getBpnByExternalId(LsaType.SITE, externalIds)
val bpnByExternalId = getBpnByExternalId(BusinessPartnerType.SITE, externalIds)

return entries.map {
GateSiteInfo(
Expand All @@ -100,7 +100,7 @@ class GateQueryService(

fun getAddressInfos(externalIds: Set<String>): Collection<GateAddressInfo> {
val entries = getAddressesInput(externalIds)
val bpnByExternalId = getBpnByExternalId(LsaType.ADDRESS, externalIds)
val bpnByExternalId = getBpnByExternalId(BusinessPartnerType.ADDRESS, externalIds)

return entries.map {
GateAddressInfo(
Expand All @@ -113,7 +113,7 @@ class GateQueryService(
}
}

fun getBpnByExternalId(lsaType: LsaType, externalIds: Set<String>): Map<String, String> {
fun getBpnByExternalId(businessPartnerType: BusinessPartnerType, externalIds: Set<String>): Map<String, String> {
if (externalIds.isEmpty()) {
return emptyMap()
}
Expand All @@ -124,7 +124,7 @@ class GateQueryService(

do {
val pageResponse = gateClient.sharingState().getSharingStates(
lsaType = lsaType,
businessPartnerType = businessPartnerType,
externalIds = externalIds,
paginationRequest = PaginationRequest(page, bridgeConfigProperties.queryPageSize)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ package com.catenax.bpdm.bridge.dummy.service

import com.catenax.bpdm.bridge.dummy.dto.*
import mu.KotlinLogging
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerType
import org.eclipse.tractusx.bpdm.common.dto.response.LogisticAddressVerboseDto
import org.eclipse.tractusx.bpdm.gate.api.client.GateClient
import org.eclipse.tractusx.bpdm.gate.api.exception.BusinessPartnerSharingError
import org.eclipse.tractusx.bpdm.gate.api.model.LsaType
import org.eclipse.tractusx.bpdm.gate.api.model.SharingStateType
import org.eclipse.tractusx.bpdm.gate.api.model.request.AddressGateOutputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.request.LegalEntityGateOutputRequest
Expand Down Expand Up @@ -53,13 +53,13 @@ class GateUpdateService(
buildLegalEntityGateOutputRequest(requestEntry, entity)
)
upsertSharingState(
buildSuccessSharingStateDto(LsaType.LEGAL_ENTITY, externalId, entity.legalEntity.bpnl, true)
buildSuccessSharingStateDto(BusinessPartnerType.LEGAL_ENTITY, externalId, entity.legalEntity.bpnl, true)
)
}
for (errorInfo in responseWrapper.errors) {
val externalId = errorInfo.entityKey
upsertSharingState(
buildErrorSharingStateDto(LsaType.LEGAL_ENTITY, externalId, null, errorInfo, true)
buildErrorSharingStateDto(BusinessPartnerType.LEGAL_ENTITY, externalId, null, errorInfo, true)
)

}
Expand All @@ -79,14 +79,14 @@ class GateUpdateService(
buildLegalEntityGateOutputRequest(requestEntry, entity)
)
upsertSharingState(
buildSuccessSharingStateDto(LsaType.LEGAL_ENTITY, externalId, bpn, false)
buildSuccessSharingStateDto(BusinessPartnerType.LEGAL_ENTITY, externalId, bpn, false)
)
}
for (errorInfo in responseWrapper.errors) {
val bpn = errorInfo.entityKey
val externalId = externalIdByBpn[bpn]
upsertSharingState(
buildErrorSharingStateDto(LsaType.LEGAL_ENTITY, externalId, bpn, errorInfo, false)
buildErrorSharingStateDto(BusinessPartnerType.LEGAL_ENTITY, externalId, bpn, errorInfo, false)
)
}
logger.info { "Sharing states for ${responseWrapper.entityCount} valid and ${responseWrapper.errorCount} invalid modified legal entities were updated in the Gate" }
Expand All @@ -103,13 +103,13 @@ class GateUpdateService(
buildSiteGateOutputRequest(requestEntry, entity)
)
upsertSharingState(
buildSuccessSharingStateDto(LsaType.SITE, externalId, entity.site.bpns, true)
buildSuccessSharingStateDto(BusinessPartnerType.SITE, externalId, entity.site.bpns, true)
)
}
for (errorInfo in responseWrapper.errors) {
val externalId = errorInfo.entityKey
upsertSharingState(
buildErrorSharingStateDto(LsaType.SITE, externalId, null, errorInfo, true)
buildErrorSharingStateDto(BusinessPartnerType.SITE, externalId, null, errorInfo, true)
)
}
logger.info { "Sharing states for ${responseWrapper.entityCount} valid and ${responseWrapper.errorCount} invalid new sites were updated in the Gate" }
Expand All @@ -128,14 +128,14 @@ class GateUpdateService(
buildSiteGateOutputRequest(requestEntry, entity)
)
upsertSharingState(
buildSuccessSharingStateDto(LsaType.SITE, externalId, bpn, false)
buildSuccessSharingStateDto(BusinessPartnerType.SITE, externalId, bpn, false)
)
}
for (errorInfo in responseWrapper.errors) {
val bpn = errorInfo.entityKey
val externalId = externalIdByBpn[bpn]
upsertSharingState(
buildErrorSharingStateDto(LsaType.SITE, externalId, bpn, errorInfo, false)
buildErrorSharingStateDto(BusinessPartnerType.SITE, externalId, bpn, errorInfo, false)
)
}
logger.info { "Sharing states for ${responseWrapper.entityCount} valid and ${responseWrapper.errorCount} invalid modified sites were updated in the Gate" }
Expand All @@ -152,13 +152,13 @@ class GateUpdateService(
buildAddressGateOutputRequest(requestEntry, entity.address)
)
upsertSharingState(
buildSuccessSharingStateDto(LsaType.ADDRESS, externalId, entity.address.bpna, true)
buildSuccessSharingStateDto(BusinessPartnerType.ADDRESS, externalId, entity.address.bpna, true)
)
}
for (errorInfo in responseWrapper.errors) {
val externalId = errorInfo.entityKey
upsertSharingState(
buildErrorSharingStateDto(LsaType.ADDRESS, externalId, null, errorInfo, true)
buildErrorSharingStateDto(BusinessPartnerType.ADDRESS, externalId, null, errorInfo, true)
)
}
logger.info { "Sharing states for ${responseWrapper.entityCount} valid and ${responseWrapper.errorCount} invalid new addresses were updated in the Gate" }
Expand All @@ -177,14 +177,14 @@ class GateUpdateService(
buildAddressGateOutputRequest(requestEntry, entity)
)
upsertSharingState(
buildSuccessSharingStateDto(LsaType.ADDRESS, externalId, bpn, false)
buildSuccessSharingStateDto(BusinessPartnerType.ADDRESS, externalId, bpn, false)
)
}
for (errorInfo in responseWrapper.errors) {
val bpn = errorInfo.entityKey
val externalId = externalIdByBpn[bpn]
upsertSharingState(
buildErrorSharingStateDto(LsaType.ADDRESS, externalId, bpn, errorInfo, false)
buildErrorSharingStateDto(BusinessPartnerType.ADDRESS, externalId, bpn, errorInfo, false)
)
}
logger.info { "Sharing states for ${responseWrapper.entityCount} valid and ${responseWrapper.errorCount} invalid modified addresses were updated in the Gate" }
Expand Down Expand Up @@ -235,13 +235,18 @@ class GateUpdateService(
)
}

private fun buildSuccessSharingStateDto(lsaType: LsaType, externalId: String?, bpn: String, processStarted: Boolean): SharingStateDto? {
private fun buildSuccessSharingStateDto(
businessPartnerType: BusinessPartnerType,
externalId: String?,
bpn: String,
processStarted: Boolean
): SharingStateDto? {
if (externalId == null) {
logger.warn { "Encountered externalId=null in Pool response for $bpn, can't update the Gate sharing state" }
return null
}
return SharingStateDto(
lsaType = lsaType,
businessPartnerType = businessPartnerType,
externalId = externalId,
sharingStateType = SharingStateType.Success,
bpn = bpn,
Expand All @@ -250,7 +255,7 @@ class GateUpdateService(
}

private fun buildErrorSharingStateDto(
lsaType: LsaType,
businessPartnerType: BusinessPartnerType,
externalId: String?,
bpn: String?,
errorInfo: ErrorInfo<*>,
Expand All @@ -261,7 +266,7 @@ class GateUpdateService(
return null
}
return SharingStateDto(
lsaType = lsaType,
businessPartnerType = businessPartnerType,
externalId = externalId,
sharingStateType = SharingStateType.Error,
bpn = bpn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ package com.catenax.bpdm.bridge.dummy.service

import com.catenax.bpdm.bridge.dummy.dto.*
import mu.KotlinLogging
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerType
import org.eclipse.tractusx.bpdm.common.dto.LogisticAddressDto
import org.eclipse.tractusx.bpdm.common.dto.SiteDto
import org.eclipse.tractusx.bpdm.gate.api.model.LsaType
import org.eclipse.tractusx.bpdm.pool.api.client.PoolApiClient
import org.eclipse.tractusx.bpdm.pool.api.model.request.*
import org.eclipse.tractusx.bpdm.pool.api.model.response.*
Expand Down Expand Up @@ -68,7 +68,7 @@ class PoolUpdateService(
fun createSitesInPool(entriesToCreate: Collection<GateSiteInfo>): SitePartnerCreateResponseWrapper {
val leParentBpnByExternalId = entriesToCreate
.map { it.legalEntityExternalId }
.let { gateQueryService.getBpnByExternalId(LsaType.LEGAL_ENTITY, it.toSet()) }
.let { gateQueryService.getBpnByExternalId(BusinessPartnerType.LEGAL_ENTITY, it.toSet()) }
val createRequests = entriesToCreate.mapNotNull { entry ->
leParentBpnByExternalId[entry.legalEntityExternalId]
?.let { leParentBpn ->
Expand Down Expand Up @@ -113,7 +113,7 @@ class PoolUpdateService(
fun createAddressesInPool(entriesToCreate: Collection<GateAddressInfo>): AddressPartnerCreateResponseWrapper {
val leParentBpnByExternalId = entriesToCreate
.mapNotNull { it.legalEntityExternalId }
.let { gateQueryService.getBpnByExternalId(LsaType.LEGAL_ENTITY, it.toSet()) }
.let { gateQueryService.getBpnByExternalId(BusinessPartnerType.LEGAL_ENTITY, it.toSet()) }
val leParentsCreateRequests = entriesToCreate.mapNotNull { entry ->
leParentBpnByExternalId[entry.legalEntityExternalId]
?.let { leParentBpn ->
Expand All @@ -127,7 +127,7 @@ class PoolUpdateService(

val siteParentBpnByExternalId = entriesToCreate
.mapNotNull { it.siteExternalId }
.let { gateQueryService.getBpnByExternalId(LsaType.SITE, it.toSet()) }
.let { gateQueryService.getBpnByExternalId(BusinessPartnerType.SITE, it.toSet()) }
val siteParentsCreateRequests = entriesToCreate.mapNotNull { entry ->
siteParentBpnByExternalId[entry.siteExternalId]
?.let { siteParentBpn ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package com.catenax.bpdm.bridge.dummy.service

import com.catenax.bpdm.bridge.dummy.entity.SyncType
import mu.KotlinLogging
import org.eclipse.tractusx.bpdm.gate.api.model.LsaType
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerType
import org.springframework.stereotype.Service
import java.time.Instant

Expand All @@ -35,7 +35,7 @@ class SyncService(

private val logger = KotlinLogging.logger { }

// TODO For improved robustness we should maybe persistently track all sync entries (status) by LSAType/externalID.
// TODO For improved robustness we should maybe persistently track all sync entries (status) by businessPartnerType/externalID.

fun sync() {
logger.info("Bridge sync started...")
Expand All @@ -53,11 +53,11 @@ class SyncService(

private fun syncInternal(modifiedAfter: Instant) {
// Check changelog entries from Gate (after last sync time)
val externalIdsByType = gateQueryService.getChangedExternalIdsByLsaType(modifiedAfter)
val externalIdsByType = gateQueryService.getChangedExternalIdsByBusinessPartnerType(modifiedAfter)

externalIdsByType[LsaType.LEGAL_ENTITY]?.let { syncLegalEntities(it) }
externalIdsByType[LsaType.SITE]?.let { syncSites(it) }
externalIdsByType[LsaType.ADDRESS]?.let { syncAddresses(it) }
externalIdsByType[BusinessPartnerType.LEGAL_ENTITY]?.let { syncLegalEntities(it) }
externalIdsByType[BusinessPartnerType.SITE]?.let { syncSites(it) }
externalIdsByType[BusinessPartnerType.ADDRESS]?.let { syncAddresses(it) }
}

private fun syncLegalEntities(externalIdsRequested: Set<String>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

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

enum class LsaType {
enum class BusinessPartnerType {
LEGAL_ENTITY,
SITE,
ADDRESS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package org.eclipse.tractusx.bpdm.common.dto
import io.swagger.v3.oas.annotations.media.Schema

@Schema(description = "Specifies if an identifier type is valid for legal entities (L) or addresses (A). Sites (S) are not supported.")
enum class IdentifierLsaType {
enum class IdentifierBusinessPartnerType {
LEGAL_ENTITY,
ADDRESS
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import io.swagger.v3.oas.annotations.media.Schema

@Schema(name = "IdentifierTypeDto", description = "Identifier type definition for legal entity or address")
data class IdentifierTypeDto(
@get:Schema(description = "Unique key (in combination with lsaType) to be used as reference")

@get:Schema(description = "Unique key (in combination with businessPartnerType) to be used as reference")
val technicalKey: String,

@get:Schema(description = "Specifies if this identifier type is valid for legal entities (L) or addresses (A)")
val lsaType: IdentifierLsaType,
val businessPartnerType: IdentifierBusinessPartnerType,

@get:Schema(description = "Full name")
val name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import io.swagger.v3.oas.annotations.media.Content
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.responses.ApiResponses
import jakarta.validation.Valid
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerType
import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest
import org.eclipse.tractusx.bpdm.common.dto.response.PageDto
import org.eclipse.tractusx.bpdm.gate.api.model.LsaType
import org.eclipse.tractusx.bpdm.gate.api.model.response.SharingStateDto
import org.springdoc.core.annotations.ParameterObject
import org.springframework.http.MediaType
Expand All @@ -52,7 +52,7 @@ interface GateSharingStateApi {
@GetExchange
fun getSharingStates(
@ParameterObject @Valid paginationRequest: PaginationRequest,
@Parameter(description = "LSA Type") @RequestParam(required = false) lsaType: LsaType?,
@Parameter(description = "Business partner type") @RequestParam(required = false) businessPartnerType: BusinessPartnerType?,
@Parameter(description = "External identifiers") @RequestParam(required = false) externalIds: Collection<String>?
): PageDto<SharingStateDto>

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.eclipse.tractusx.bpdm.gate.api.model.request

import io.swagger.v3.oas.annotations.Parameter
import org.eclipse.tractusx.bpdm.gate.api.model.LsaType
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerType
import java.time.Instant

data class ChangeLogSearchRequest(
Expand All @@ -32,5 +32,5 @@ data class ChangeLogSearchRequest(
val externalIds: Set<String> = emptySet(),

@field:Parameter(description = "Lsa-Types of business partners for which to search changelog entries. Ignored if empty", required = false)
val lsaTypes: Set<LsaType> = emptySet()
val businessPartnerType: Set<BusinessPartnerType> = emptySet()
)
Loading

0 comments on commit c33864e

Please sign in to comment.