Skip to content

Commit

Permalink
feat(api): #172 Rename BPN fields - rename controlles paths
Browse files Browse the repository at this point in the history
  • Loading branch information
rainer-exxcellent committed May 25, 2023
1 parent a11a942 commit b83b2bd
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class PoolUpdateService(
SitePartnerCreateRequest(
site = entry.site,
index = entry.externalId,
bpnParent = leParentBpn
bpnlParent = leParentBpn
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ interface PoolAddressApi {
): PageResponse<AddressMatchResponse>

@Operation(
summary = "Get address partners by bpn",
summary = "Get address partners by bpna",
description = "Get business partners of type address by bpn-a ignoring case."
)
@ApiResponses(
value = [
ApiResponse(responseCode = "200", description = "Found address with specified bpn"),
ApiResponse(responseCode = "200", description = "Found address with specified bpna"),
ApiResponse(responseCode = "400", description = "On malformed request parameters", content = [Content()]),
ApiResponse(responseCode = "404", description = "No address found under specified bpn", content = [Content()])
ApiResponse(responseCode = "404", description = "No address found under specified bpna", content = [Content()])
]
)
@GetMapping("/{bpn}")
@GetExchange("/{bpn}")
@GetMapping("/{bpna}")
@GetExchange("/{bpna}")
fun getAddress(
@Parameter(description = "Bpn value") @PathVariable bpn: String
@Parameter(description = "Bpn value") @PathVariable bpna: String
): LogisticAddressResponse

@Operation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,19 @@ interface PoolLegalEntityApi {
@Operation(
summary = "Confirms that the data of a legal entity business partner is still up to date.",
description = "Confirms that the data of a business partner is still up to date " +
"by saving the current timestamp at the time this POST-request is made as this business partner's \"currentness\". Ignores case of bpn."
"by saving the current timestamp at the time this POST-request is made as this business partner's \"currentness\". Ignores case of bpnl."
)
@ApiResponses(
value = [
ApiResponse(responseCode = "200", description = "Business partner's \"currentness\" successfully updated"),
ApiResponse(responseCode = "400", description = "On malformed request parameters", content = [Content()]),
ApiResponse(responseCode = "404", description = "No business partner found for specified bpn", content = [Content()])
ApiResponse(responseCode = "404", description = "No business partner found for specified bpnl", content = [Content()])
]
)
@PostMapping("/{bpn}/confirm-up-to-date")
@PostExchange("/{bpn}/confirm-up-to-date")
@PostMapping("/{bpnl}/confirm-up-to-date")
@PostExchange("/{bpnl}/confirm-up-to-date")
fun setLegalEntityCurrentness(
@Parameter(description = "Bpn value") @PathVariable bpn: String
@Parameter(description = "Bpnl value") @PathVariable bpnl: String
)

@Operation(
Expand All @@ -134,19 +134,19 @@ interface PoolLegalEntityApi {

@Operation(
summary = "Get site partners of a legal entity",
description = "Get business partners of type site belonging to a business partner of type legal entity, identified by the business partner's bpn ignoring case."
description = "Get business partners of type site belonging to a business partner of type legal entity, identified by the business partner's bpnl ignoring case."
)
@ApiResponses(
value = [
ApiResponse(responseCode = "200", description = "The sites for the specified bpn"),
ApiResponse(responseCode = "200", description = "The sites for the specified bpnl"),
ApiResponse(responseCode = "400", description = "On malformed pagination request", content = [Content()]),
ApiResponse(responseCode = "404", description = "No business partner found for specified bpn", content = [Content()])
ApiResponse(responseCode = "404", description = "No business partner found for specified bpnl", content = [Content()])
]
)
@GetMapping("/{bpn}/sites")
@GetExchange("/{bpn}/sites")
@GetMapping("/{bpnl}/sites")
@GetExchange("/{bpnl}/sites")
fun getSites(
@Parameter(description = "Bpn value") @PathVariable bpn: String,
@Parameter(description = "Bpnl value") @PathVariable bpnl: String,
@ParameterObject paginationRequest: PaginationRequest
): PageResponse<SiteResponse>

Expand All @@ -161,10 +161,10 @@ interface PoolLegalEntityApi {
ApiResponse(responseCode = "404", description = "No business partner found for specified bpn", content = [Content()])
]
)
@GetMapping("/{bpn}/addresses")
@GetExchange("/{bpn}/addresses")
@GetMapping("/{bpnl}/addresses")
@GetExchange("/{bpnl}/addresses")
fun getAddresses(
@Parameter(description = "Bpn value") @PathVariable bpn: String,
@Parameter(description = "Bpn value") @PathVariable bpnl: String,
@ParameterObject paginationRequest: PaginationRequest
): PageResponse<LogisticAddressResponse>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ data class SitePartnerCreateRequest(
val site: SiteDto,

@Schema(description = "Business Partner Number of the legal entity this site belongs to")
val bpnParent: String,
val bpnlParent: String,

@Schema(description = "User defined index to conveniently match this entry to the corresponding entry in the response")
val index: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package org.eclipse.tractusx.bpdm.pool.component.saas.service
import mu.KotlinLogging
import org.eclipse.tractusx.bpdm.common.dto.IdentifierLsaType
import org.eclipse.tractusx.bpdm.common.dto.IdentifierTypeDto
import org.eclipse.tractusx.bpdm.common.dto.response.type.TypeKeyNameDto
import org.eclipse.tractusx.bpdm.common.dto.saas.BusinessPartnerSaas
import org.eclipse.tractusx.bpdm.common.dto.saas.LegalFormSaas
import org.eclipse.tractusx.bpdm.common.dto.saas.TypeKeyNameUrlSaas
Expand Down Expand Up @@ -74,7 +73,7 @@ class SaasToRequestMapper {
fun toSiteCreateRequest(partnerWithParent: BusinessPartnerWithParentBpn): SitePartnerCreateRequest {
return SitePartnerCreateRequest(
site = partnerWithParent.partner.toSiteDto(),
bpnParent = partnerWithParent.parentBpn,
bpnlParent = partnerWithParent.parentBpn,
index = partnerWithParent.partner.externalId
)
}
Expand Down Expand Up @@ -138,11 +137,6 @@ class SaasToRequestMapper {
}
}


fun toRequest(idType: TypeKeyNameUrlSaas): TypeKeyNameDto<String> {
return TypeKeyNameDto(idType.technicalKey!!, idType.name ?: "")
}

fun toRequest(legalForm: LegalFormSaas, partner: BusinessPartnerSaas): LegalFormRequest {
return LegalFormRequest(
technicalKey = legalForm.technicalKey!!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ class AddressController(
}

override fun getAddress(
bpn: String
bpna: String
): LogisticAddressResponse {
return addressService.findByBpn(bpn.uppercase())
return addressService.findByBpn(bpna.uppercase())
}

override fun searchAddresses(
Expand All @@ -68,7 +68,7 @@ class AddressController(

override fun createAddresses(
requests: Collection<AddressPartnerCreateRequest>
): AddressPartnerCreateResponseWrapper {
): AddressPartnerCreateResponseWrapper {
return businessPartnerBuildService.createAddresses(requests)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class LegalEntityController(
}


override fun setLegalEntityCurrentness(bpn: String) {
businessPartnerBuildService.setBusinessPartnerCurrentness(bpn.uppercase())
override fun setLegalEntityCurrentness(bpnl: String) {
businessPartnerBuildService.setBusinessPartnerCurrentness(bpnl.uppercase())
}

override fun searchSites(
Expand All @@ -86,18 +86,18 @@ class LegalEntityController(
}

override fun getSites(
bpn: String,
bpnl: String,
paginationRequest: PaginationRequest
): PageResponse<SiteResponse> {
return siteService.findByPartnerBpn(bpn.uppercase(), paginationRequest.page, paginationRequest.size)
return siteService.findByPartnerBpn(bpnl.uppercase(), paginationRequest.page, paginationRequest.size)
}


override fun getAddresses(
bpn: String,
bpnl: String,
paginationRequest: PaginationRequest
): PageResponse<LogisticAddressResponse> {
return addressService.findByPartnerBpn(bpn.uppercase(), paginationRequest.page, paginationRequest.size)
return addressService.findByPartnerBpn(bpnl.uppercase(), paginationRequest.page, paginationRequest.size)
}


Expand All @@ -114,7 +114,8 @@ class LegalEntityController(
return businessPartnerBuildService.createLegalEntities(businessPartners)
}

override fun updateBusinessPartners(businessPartners: Collection<LegalEntityPartnerUpdateRequest>
override fun updateBusinessPartners(
businessPartners: Collection<LegalEntityPartnerUpdateRequest>
): LegalEntityPartnerUpdateResponseWrapper {
return businessPartnerBuildService.updateLegalEntities(businessPartners)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ class BusinessPartnerBuildService(
fun createSites(requests: Collection<SitePartnerCreateRequest>): SitePartnerCreateResponseWrapper {
logger.info { "Create ${requests.size} new sites" }

val legalEntities = legalEntityRepository.findDistinctByBpnIn(requests.map { it.bpnParent })
val legalEntities = legalEntityRepository.findDistinctByBpnIn(requests.map { it.bpnlParent })
val legalEntityMap = legalEntities.associateBy { it.bpn }

val (validRequests, invalidRequests) = requests.partition { legalEntityMap[it.bpnParent] != null }
val (validRequests, invalidRequests) = requests.partition { legalEntityMap[it.bpnlParent] != null }
val errors = invalidRequests.map {
ErrorInfo(SiteCreateError.LegalEntityNotFound, "Site not created: parent legal entity ${it.bpnParent} not found", it.index)
ErrorInfo(SiteCreateError.LegalEntityNotFound, "Site not created: parent legal entity ${it.bpnlParent} not found", it.index)
}

val addressMetadataMap = metadataMappingService.mapRequests(validRequests.map { it.site.mainAddress })
Expand All @@ -110,7 +110,7 @@ class BusinessPartnerBuildService(

val siteWithIndexByBpnMap = validRequests
.mapIndexed { i, request ->
val legalEntity = legalEntityMap[request.bpnParent]!!
val legalEntity = legalEntityMap[request.bpnlParent]!!
val site = createSite(request.site, bpnSs[i], legalEntity)
site.mainAddress = createLogisticAddress(request.site.mainAddress, bpnAs[i], site, addressMetadataMap)
Pair(site, request.index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ class SiteControllerIT @Autowired constructor(
val expected = listOf(ResponseValues.siteUpsert1, ResponseValues.siteUpsert2, ResponseValues.siteUpsert3)

val toCreate = listOf(
RequestValues.siteCreate1.copy(bpnParent = bpnL1),
RequestValues.siteCreate2.copy(bpnParent = bpnL2),
RequestValues.siteCreate3.copy(bpnParent = bpnL2)
RequestValues.siteCreate1.copy(bpnlParent = bpnL1),
RequestValues.siteCreate2.copy(bpnlParent = bpnL2),
RequestValues.siteCreate3.copy(bpnlParent = bpnL2)
)

val response = poolClient.sites().createSite(toCreate)
Expand Down Expand Up @@ -200,9 +200,9 @@ class SiteControllerIT @Autowired constructor(
val expected = listOf(ResponseValues.siteUpsert1, ResponseValues.siteUpsert2)

val toCreate = listOf(
RequestValues.siteCreate1.copy(bpnParent = bpnL1),
RequestValues.siteCreate2.copy(bpnParent = bpnL2),
RequestValues.siteCreate3.copy(bpnParent = "NONEXISTENT")
RequestValues.siteCreate1.copy(bpnlParent = bpnL1),
RequestValues.siteCreate2.copy(bpnlParent = bpnL2),
RequestValues.siteCreate3.copy(bpnlParent = "NONEXISTENT")
)
val response = poolClient.sites().createSite(toCreate)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ object RequestValues {
mainAddress = logisticAddress1
),
index = CommonValues.index1,
bpnParent = legalEntityUpdate1.bpnl
bpnlParent = legalEntityUpdate1.bpnl
)

val siteCreate2 = SitePartnerCreateRequest(
Expand All @@ -229,7 +229,7 @@ object RequestValues {
mainAddress = logisticAddress2
),
index = CommonValues.index2,
bpnParent = legalEntityUpdate2.bpnl
bpnlParent = legalEntityUpdate2.bpnl
)

val siteCreate3 = SitePartnerCreateRequest(
Expand All @@ -239,7 +239,7 @@ object RequestValues {
mainAddress = logisticAddress3
),
index = CommonValues.index3,
bpnParent = legalEntityUpdate3.bpnl
bpnlParent = legalEntityUpdate3.bpnl
)

val siteUpdate1 = SitePartnerUpdateRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class TestHelpers(
val assignedSiteRequests =
partnerStructures.flatMap {
it.siteStructures.map { site ->
site.site.copy(bpnParent = indexedLegalEntities[it.legalEntity.index]!!.legalEntity.bpnl)
site.site.copy(bpnlParent = indexedLegalEntities[it.legalEntity.index]!!.legalEntity.bpnl)
}
}
val sitesWithErrorsResponse = poolClient.sites().createSite(assignedSiteRequests)
Expand Down

0 comments on commit b83b2bd

Please sign in to comment.