Skip to content

Commit

Permalink
feat: update workspace external api
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras committed Feb 29, 2024
1 parent be601f3 commit ac01e2b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -90,8 +91,11 @@ public Response getProductByName(String name) {
try (Response response = client.getProductByName(name)) {
Product resultProduct = response.readEntity(Product.class);
Set<String> 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) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -118,15 +120,18 @@ void getProductByName_test() {
.withContentType(MediaType.APPLICATION_JSON)
.withBody(JsonBody.json(data)));

Set<String> 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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ac01e2b

Please sign in to comment.