diff --git a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/GateSiteApi.kt b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/GateSiteApi.kt index c8ba106fd..8745782d4 100644 --- a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/GateSiteApi.kt +++ b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/GateSiteApi.kt @@ -75,6 +75,23 @@ interface GateSiteApi { @GetExchange("/input/sites/{externalId}") fun getSiteByExternalId(@Parameter(description = "External identifier") @PathVariable externalId: String): SiteGateInputResponse + @Operation( + summary = "Get page of sites filtered by a collection of externalIds", + description = "Get page of sites filtered by a collection of externalIds." + ) + @ApiResponses( + value = [ + ApiResponse(responseCode = "200", description = "The requested page of sites"), + ApiResponse(responseCode = "400", description = "On malformed pagination request", content = [Content()]), + ] + ) + @PostMapping("/input/sites/search") + @PostExchange("/input/sites/search") + fun getSitesByExternalIds( + @ParameterObject @Valid paginationRequest: PaginationStartAfterRequest, + @RequestBody externalIds: Collection + ): PageStartAfterResponse + @Operation( summary = "Get page of sites", description = "Get page of sites." diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/controller/SiteController.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/controller/SiteController.kt index a30d6cda7..ca6b151c3 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/controller/SiteController.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/controller/SiteController.kt @@ -54,6 +54,13 @@ class SiteController( return siteService.getSiteByExternalId(externalId) } + override fun getSitesByExternalIds( + paginationRequest: PaginationStartAfterRequest, + externalIds: Collection + ): PageStartAfterResponse { + return siteService.getSites(paginationRequest.limit, paginationRequest.startAfter, externalIds) + } + override fun getSites(paginationRequest: PaginationStartAfterRequest): PageStartAfterResponse { return siteService.getSites(paginationRequest.limit, paginationRequest.startAfter) } diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/SiteService.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/SiteService.kt index 083992322..11b5c9bbb 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/SiteService.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/SiteService.kt @@ -51,8 +51,8 @@ class SiteService( ) { private val logger = KotlinLogging.logger { } - fun getSites(limit: Int, startAfter: String?): PageStartAfterResponse { - val sitesPage = saasClient.getSites(limit, startAfter) + fun getSites(limit: Int, startAfter: String?, externalIds: Collection? = null): PageStartAfterResponse { + val sitesPage = saasClient.getSites(limit, startAfter, externalIds) val validEntries = sitesPage.values.filter { validateSiteBusinessPartner(it) } diff --git a/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/controller/SiteControllerInputIT.kt b/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/controller/SiteControllerInputIT.kt index d4d5a7104..0c9c759c7 100644 --- a/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/controller/SiteControllerInputIT.kt +++ b/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/controller/SiteControllerInputIT.kt @@ -242,6 +242,62 @@ internal class SiteControllerInputIT @Autowired constructor( ) } + /** + * Given sites exists in SaaS + * When getting sites page based on externalId + * Then sites page mapped to the catena data model should be returned + */ + @Test + fun `get sites by external id`() { + val sitesSaas = listOf( + SaasValues.siteBusinessPartnerWithRelations1, + SaasValues.siteBusinessPartnerWithRelations2 + ) + + val expectedSites = listOf( + ResponseValues.siteGateInputResponse1, + ResponseValues.siteGateInputResponse2 + ) + + 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 = sitesSaas + ) + ) + ) + ) + ) + + val externalIds = sitesSaas.mapNotNull { it.externalId } + val paginationValue = PaginationStartAfterRequest(startAfter, limit) + val pageResponse = gateClient.sites().getSitesByExternalIds(paginationValue, externalIds) + + assertThat(pageResponse).isEqualTo( + PageStartAfterResponse( + total = total, + nextStartAfter = nextStartAfter, + content = expectedSites, + invalidEntries = invalidEntries + ) + ) + } + /** * Given invalid sites in SaaS * When getting sites page