From ac01e2b4d56e442970b1468d97c4fe8ef06b2225 Mon Sep 17 00:00:00 2001 From: Andrej Petras Date: Thu, 29 Feb 2024 11:01:22 +0100 Subject: [PATCH] feat: update workspace external api --- .../controllers/ProductsRestController.java | 10 ++++++--- .../store/bff/rs/mappers/ProductsMapper.java | 9 ++++++++ .../bff/rs/ProductsRestControllerTest.java | 22 ++++++++++++------- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/tkit/onecx/product/store/bff/rs/controllers/ProductsRestController.java b/src/main/java/org/tkit/onecx/product/store/bff/rs/controllers/ProductsRestController.java index 609e7be..b784d6d 100644 --- a/src/main/java/org/tkit/onecx/product/store/bff/rs/controllers/ProductsRestController.java +++ b/src/main/java/org/tkit/onecx/product/store/bff/rs/controllers/ProductsRestController.java @@ -1,6 +1,5 @@ package org.tkit.onecx.product.store.bff.rs.controllers; -import java.util.HashSet; import java.util.Set; import jakarta.enterprise.context.ApplicationScoped; @@ -25,6 +24,8 @@ import gen.org.tkit.onecx.product.store.client.model.Product; import gen.org.tkit.onecx.product.store.client.model.ProductPageResult; import gen.org.tkit.onecx.workspace.client.api.WorkspaceExternalApi; +import gen.org.tkit.onecx.workspace.client.model.WorkspacePageResult; +import gen.org.tkit.onecx.workspace.client.model.WorkspaceSearchCriteria; @LogService @ApplicationScoped @@ -90,8 +91,11 @@ public Response getProductByName(String name) { try (Response response = client.getProductByName(name)) { Product resultProduct = response.readEntity(Product.class); Set workspaceNames = null; - try (Response workspaceResponse = workspaceClient.getWorkspacesByProductName(name)) { - workspaceNames = workspaceResponse.readEntity(HashSet.class); + + try (Response workspaceResponse = workspaceClient + .searchWorkspaces(new WorkspaceSearchCriteria().productName(name))) { + var result = workspaceResponse.readEntity(WorkspacePageResult.class); + workspaceNames = mapper.workspaceNames(result); } catch (WebApplicationException ex) { } diff --git a/src/main/java/org/tkit/onecx/product/store/bff/rs/mappers/ProductsMapper.java b/src/main/java/org/tkit/onecx/product/store/bff/rs/mappers/ProductsMapper.java index cc8b74e..f44050b 100644 --- a/src/main/java/org/tkit/onecx/product/store/bff/rs/mappers/ProductsMapper.java +++ b/src/main/java/org/tkit/onecx/product/store/bff/rs/mappers/ProductsMapper.java @@ -9,10 +9,19 @@ import gen.org.tkit.onecx.product.store.bff.rs.internal.model.*; import gen.org.tkit.onecx.product.store.client.model.*; +import gen.org.tkit.onecx.workspace.client.model.WorkspaceAbstract; +import gen.org.tkit.onecx.workspace.client.model.WorkspacePageResult; @Mapper(uses = { OffsetDateTimeMapper.class }) public interface ProductsMapper { + default Set workspaceNames(WorkspacePageResult result) { + if (result == null || result.getStream() == null) { + return Set.of(); + } + return result.getStream().stream().map(WorkspaceAbstract::getName).collect(Collectors.toSet()); + } + CreateProductRequest mapCreateProduct(CreateProductRequestDTO createProduct); UpdateProductRequest mapUpdateProduct(UpdateProductRequestDTO updateProduct); diff --git a/src/test/java/org/tkit/onecx/product/store/bff/rs/ProductsRestControllerTest.java b/src/test/java/org/tkit/onecx/product/store/bff/rs/ProductsRestControllerTest.java index 691e29e..69315bd 100644 --- a/src/test/java/org/tkit/onecx/product/store/bff/rs/ProductsRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/product/store/bff/rs/ProductsRestControllerTest.java @@ -21,6 +21,8 @@ import gen.org.tkit.onecx.product.store.bff.rs.internal.model.*; import gen.org.tkit.onecx.product.store.client.model.*; +import gen.org.tkit.onecx.workspace.client.model.WorkspaceAbstract; +import gen.org.tkit.onecx.workspace.client.model.WorkspacePageResult; import io.quarkiverse.mockserver.test.InjectMockServerClient; import io.quarkus.test.common.http.TestHTTPEndpoint; import io.quarkus.test.junit.QuarkusTest; @@ -108,7 +110,7 @@ void getProductByName_test() { Product data = createProduct("7a0ee705-8fd0-47b0-8205-b2a5f6540b9e", "0", offsetDateTime, null, offsetDateTime, null, "test-appl2", "Here is some description 2", false, - "https://prod.ucwe.capgemini.com/wp-content/uploads/2023/11/world-cloud-report-banner1_2023.jpg", + "https://my-page.site.url", "/app3", 0, "Product ABC", "Sun", "Themes, Menu"); // create mock rest endpoint mockServerClient @@ -118,15 +120,18 @@ void getProductByName_test() { .withContentType(MediaType.APPLICATION_JSON) .withBody(JsonBody.json(data))); - Set workspaceNames = new HashSet<>(); - workspaceNames.add("testWorkspace"); + var result = new WorkspacePageResult().stream( + List.of( + new WorkspaceAbstract().name("testWorkspace").description("testWorkspace"))); + // create mock rest endpoint mockServerClient - .when(request().withPath("/v1/workspaces/productName/test-appl2") - .withMethod(HttpMethod.GET)) + .when(request().withPath("/v1/workspaces/search") + .withMethod(HttpMethod.POST)) + .withPriority(10) .respond(httpRequest -> response().withStatusCode(Response.Status.OK.getStatusCode()) .withContentType(MediaType.APPLICATION_JSON) - .withBody(JsonBody.json(workspaceNames))); + .withBody(JsonBody.json(result))); var response = given() .when() @@ -180,8 +185,9 @@ void getProductByName_test() { // create mock rest endpoint mockServerClient - .when(request().withPath("/v1/workspaces/productName/test-appl50") - .withMethod(HttpMethod.GET)) + .when(request().withPath("/v1/workspaces/search") + .withMethod(HttpMethod.POST)) + .withPriority(11) .respond(httpRequest -> response().withStatusCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())); // create mock rest endpoint