From a97f119e3643145dd9446de65565a87f167bbb58 Mon Sep 17 00:00:00 2001 From: Andrej Petras Date: Wed, 24 Apr 2024 21:30:20 +0200 Subject: [PATCH] feat: update for new workspace external api --- pom.xml | 2 +- .../controllers/WorkspaceRestController.java | 30 ++++++++----------- .../rs/WorkspaceRestControllerTest.java | 22 ++------------ 3 files changed, 15 insertions(+), 39 deletions(-) diff --git a/pom.xml b/pom.xml index 151f1cf..0afe562 100644 --- a/pom.xml +++ b/pom.xml @@ -183,7 +183,7 @@ wget - https://raw.githubusercontent.com/onecx/onecx-workspace-svc/main/src/main/openapi/onecx-workspace-v1-openapi.yaml + https://raw.githubusercontent.com/onecx/onecx-workspace-svc/feat/add-slots/src/main/openapi/onecx-workspace-v1-openapi.yaml target/tmp/openapi onecx-workspace-svc-v1.yaml true diff --git a/src/main/java/org/tkit/onecx/permission/bff/rs/controllers/WorkspaceRestController.java b/src/main/java/org/tkit/onecx/permission/bff/rs/controllers/WorkspaceRestController.java index 96801a7..52d60ec 100644 --- a/src/main/java/org/tkit/onecx/permission/bff/rs/controllers/WorkspaceRestController.java +++ b/src/main/java/org/tkit/onecx/permission/bff/rs/controllers/WorkspaceRestController.java @@ -19,9 +19,7 @@ import gen.org.tkit.onecx.permission.bff.rs.internal.model.WorkspaceDetailsDTO; import gen.org.tkit.onecx.permission.bff.rs.internal.model.WorkspaceSearchCriteriaDTO; import gen.org.tkit.onecx.permission.client.api.WorkspaceExternalApi; -import gen.org.tkit.onecx.permission.client.model.Product; import gen.org.tkit.onecx.permission.client.model.Workspace; -import gen.org.tkit.onecx.permission.client.model.WorkspaceLoad; import gen.org.tkit.onecx.permission.client.model.WorkspacePageResult; import gen.org.tkit.onecx.product.store.client.api.ProductsApi; import gen.org.tkit.onecx.product.store.client.model.ProductItemLoadSearchCriteria; @@ -58,29 +56,25 @@ public Response searchWorkspaces(WorkspaceSearchCriteriaDTO criteriaDTO) { public Response getDetailsByWorkspaceName(String workspaceName) { try (Response response = workspaceClient.getWorkspaceByName(workspaceName)) { WorkspaceDetailsDTO workspaceDetails; - List productNames; + List workspaceRoles = new ArrayList<>(); - ProductsLoadResult productsLoadResult = new ProductsLoadResult(); var workspaceResponse = response.readEntity(Workspace.class); if (workspaceResponse.getWorkspaceRoles() != null) { - workspaceRoles = workspaceResponse.getWorkspaceRoles().stream().toList(); + workspaceRoles = new ArrayList<>(workspaceResponse.getWorkspaceRoles()); } - //get products of workspace - try (Response wsProductsResponse = workspaceClient.loadWorkspaceByName(workspaceName)) { - //list of product names registered in workspace - productNames = wsProductsResponse.readEntity(WorkspaceLoad.class).getProducts().stream() - .map(Product::getProductName).toList(); - if (!productNames.isEmpty()) { - //get mfe and ms for each product by name from product-store - ProductItemLoadSearchCriteria mfeAndMsCriteria = new ProductItemLoadSearchCriteria(); - mfeAndMsCriteria.setProductNames(productNames); - try (Response productStoreResponse = productStoreClient.loadProductsByCriteria(mfeAndMsCriteria)) { - productsLoadResult = productStoreResponse.readEntity(ProductsLoadResult.class); - } + ProductsLoadResult productsLoadResult = new ProductsLoadResult(); + if (workspaceResponse.getProducts() != null) { + //get mfe and ms for each product by name from product-store + ProductItemLoadSearchCriteria mfeAndMsCriteria = new ProductItemLoadSearchCriteria(); + mfeAndMsCriteria.setProductNames(new ArrayList<>(workspaceResponse.getProducts())); + try (Response productStoreResponse = productStoreClient.loadProductsByCriteria(mfeAndMsCriteria)) { + productsLoadResult = productStoreResponse.readEntity(ProductsLoadResult.class); } - workspaceDetails = mapper.map(workspaceRoles, productsLoadResult); } + + workspaceDetails = mapper.map(workspaceRoles, productsLoadResult); + return Response.status(Response.Status.OK).entity(workspaceDetails).build(); } } diff --git a/src/test/java/org/tkit/onecx/permission/rs/WorkspaceRestControllerTest.java b/src/test/java/org/tkit/onecx/permission/rs/WorkspaceRestControllerTest.java index 0164c1b..f17c043 100644 --- a/src/test/java/org/tkit/onecx/permission/rs/WorkspaceRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/permission/rs/WorkspaceRestControllerTest.java @@ -113,7 +113,8 @@ void getDetailsByWorkspaceNameTest() { String workspaceName = "test-workspace"; Workspace workspace = new Workspace(); - workspace.name("test-workspace").workspaceRoles(Set.of("role1", "role2")); + workspace.name("test-workspace").workspaceRoles(Set.of("role1", "role2")) + .products(Set.of("product1", "product2")); // create mock rest endpoint mockServerClient @@ -122,24 +123,6 @@ void getDetailsByWorkspaceNameTest() { .respond(httpRequest -> response().withStatusCode(Response.Status.OK.getStatusCode()) .withBody(JsonBody.json(workspace))); - List productsOfWorkspace = new ArrayList<>(); - Product product1 = new Product(); - product1.productName("product1"); - Product product2 = new Product(); - product2.productName("product2"); - productsOfWorkspace.add(product1); - productsOfWorkspace.add(product2); - - WorkspaceLoad loadResponse = new WorkspaceLoad(); - loadResponse.setName(workspaceName); - loadResponse.setProducts(productsOfWorkspace); - // create mock rest endpoint - mockServerClient - .when(request().withPath("/v1/workspaces/" + workspaceName + "/load").withMethod(HttpMethod.GET)) - .withId("MOCKID2") - .respond(httpRequest -> response().withStatusCode(Response.Status.OK.getStatusCode()) - .withBody(JsonBody.json(loadResponse))); - List productNames = List.of("product1", "product2"); ProductItemLoadSearchCriteria criteria = new ProductItemLoadSearchCriteria(); criteria.setProductNames(productNames); @@ -201,7 +184,6 @@ void getDetailsByWorkspaceNameTest() { Assertions.assertNotNull(output.getProducts().get(1).getMs().get(0).getAppId()); mockServerClient.clear(MOCKID); - mockServerClient.clear("MOCKID2"); mockServerClient.clear("MOCKID3"); }