Skip to content

Commit

Permalink
feat: update for new workspace external api
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras committed Apr 24, 2024
1 parent 4992119 commit a97f119
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 39 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
<goal>wget</goal>
</goals>
<configuration>
<url>https://raw.githubusercontent.com/onecx/onecx-workspace-svc/main/src/main/openapi/onecx-workspace-v1-openapi.yaml</url>
<url>https://raw.githubusercontent.com/onecx/onecx-workspace-svc/feat/add-slots/src/main/openapi/onecx-workspace-v1-openapi.yaml</url>
<outputDirectory>target/tmp/openapi</outputDirectory>
<outputFileName>onecx-workspace-svc-v1.yaml</outputFileName>
<skipCache>true</skipCache>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,29 +56,25 @@ public Response searchWorkspaces(WorkspaceSearchCriteriaDTO criteriaDTO) {
public Response getDetailsByWorkspaceName(String workspaceName) {
try (Response response = workspaceClient.getWorkspaceByName(workspaceName)) {
WorkspaceDetailsDTO workspaceDetails;
List<String> productNames;

List<String> 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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -122,24 +123,6 @@ void getDetailsByWorkspaceNameTest() {
.respond(httpRequest -> response().withStatusCode(Response.Status.OK.getStatusCode())
.withBody(JsonBody.json(workspace)));

List<Product> 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<String> productNames = List.of("product1", "product2");
ProductItemLoadSearchCriteria criteria = new ProductItemLoadSearchCriteria();
criteria.setProductNames(productNames);
Expand Down Expand Up @@ -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");
}

Expand Down

0 comments on commit a97f119

Please sign in to comment.