diff --git a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/GateLegalEntityApi.kt b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/GateLegalEntityApi.kt index 3811a9add..270481bde 100644 --- a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/GateLegalEntityApi.kt +++ b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/GateLegalEntityApi.kt @@ -75,6 +75,23 @@ interface GateLegalEntityApi { @GetExchange("/input/legal-entities/{externalId}") fun getLegalEntityByExternalId(@Parameter(description = "External identifier") @PathVariable externalId: String): LegalEntityGateInputResponse + @Operation( + summary = "Get page of legal-entities filtered by a collection of externalIds", + description = "Get page of legal-entities filtered by a collection of externalIds." + ) + @ApiResponses( + value = [ + ApiResponse(responseCode = "200", description = "The requested page of legal-entities"), + ApiResponse(responseCode = "400", description = "On malformed pagination request", content = [Content()]), + ] + ) + @PostMapping("/input/legal-entities/search") + @PostExchange("/input/legal-entities/search") + fun getLegalEntitiesByExternalIds( + @ParameterObject @Valid paginationRequest: PaginationStartAfterRequest, + @RequestBody externalIds: Collection + ): PageStartAfterResponse + @Operation( summary = "Get page of legal entities", description = "Get page of legal entities." diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/controller/LegalEntityController.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/controller/LegalEntityController.kt index 3b95bd599..680dc0c7c 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/controller/LegalEntityController.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/controller/LegalEntityController.kt @@ -54,6 +54,13 @@ class LegalEntityController( return legalEntityService.getLegalEntityByExternalId(externalId) } + override fun getLegalEntitiesByExternalIds( + paginationRequest: PaginationStartAfterRequest, + externalIds: Collection + ): PageStartAfterResponse { + return legalEntityService.getLegalEntities(limit = paginationRequest.limit, startAfter = paginationRequest.startAfter, externalIds = externalIds) + } + override fun getLegalEntities(paginationRequest: PaginationStartAfterRequest): PageStartAfterResponse { return legalEntityService.getLegalEntities(paginationRequest.limit, paginationRequest.startAfter) } diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/LegalEntityService.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/LegalEntityService.kt index c8f5b0c9c..ff14649ea 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/LegalEntityService.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/LegalEntityService.kt @@ -69,8 +69,8 @@ class LegalEntityService( } } - fun getLegalEntities(limit: Int, startAfter: String?): PageStartAfterResponse { - val partnerCollection = saasClient.getLegalEntities(limit, startAfter) + fun getLegalEntities(limit: Int, startAfter: String?, externalIds: Collection? = null): PageStartAfterResponse { + val partnerCollection = saasClient.getLegalEntities(limit, startAfter, externalIds) val validEntries = toValidLegalEntities(partnerCollection.values) diff --git a/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/controller/LegalEntityControllerInputIT.kt b/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/controller/LegalEntityControllerInputIT.kt index aa265473d..ba311045f 100644 --- a/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/controller/LegalEntityControllerInputIT.kt +++ b/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/controller/LegalEntityControllerInputIT.kt @@ -374,6 +374,63 @@ internal class LegalEntityControllerInputIT @Autowired constructor( ) } + + /** + * Given legal entity exists in SaaS + * When getting legal entities page based on external id list + * Then legal entities page mapped to the catena data model should be returned + */ + @Test + fun `get legal entity filter by external ids`() { + val legalEntitiesSaas = listOf( + SaasValues.legalEntityResponse1, + SaasValues.legalEntityResponse2, + ) + + val expectedLegalEntities = listOf( + ResponseValues.legalEntityGateInputResponse1, + ResponseValues.legalEntityGateInputResponse2, + ) + + val limit = 2 + val startAfter = "Aaa111" + val nextStartAfter = "Aaa222" + val total = 10 + val invalidEntries = 0 + + wireMockServer.stubFor( + get(urlPathMatching(SAAS_MOCK_BUSINESS_PARTNER_PATH)) + .willReturn( + aResponse() + .withHeader("Content-Type", "application/json") + .withBody( + objectMapper.writeValueAsString( + PagedResponseSaas( + limit = limit, + startAfter = startAfter, + nextStartAfter = nextStartAfter, + total = total, + values = legalEntitiesSaas + ) + ) + ) + ) + ) + + val paginationValue = PaginationStartAfterRequest(startAfter, limit) + val listExternalIds = legalEntitiesSaas.mapNotNull { it.externalId } + val pageResponse = gateClient.legalEntities().getLegalEntitiesByExternalIds(paginationValue, listExternalIds) + + assertThat(pageResponse).isEqualTo( + PageStartAfterResponse( + total = total, + nextStartAfter = nextStartAfter, + content = expectedLegalEntities, + invalidEntries = invalidEntries + ) + ) + } + /** * Given legal entity without legal address in SaaS * When getting legal entities page