Skip to content

Commit

Permalink
feat: clean-up removed workspace api (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
JordenReuter authored Nov 5, 2024
1 parent 62b19df commit db4a535
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ quarkus.http.filter.images.header."Cache-Control"=max-age=432000
quarkus.http.filter.images.matches=/images/*
%prod.quarkus.rest-client.onecx_product_store_internal.url=http://onecx-product-store-svc:8080
%prod.quarkus.rest-client.onecx_image_internal.url=http://onecx-product-store-svc:8080
%prod.quarkus.rest-client.onecx_workspace_svc_external_v1.url=http://onecx-workspace-svc:8080
quarkus.openapi-generator.codegen.spec.onecx_product_store_internal_yaml.config-key=onecx_product_store_internal
quarkus.openapi-generator.codegen.spec.onecx_product_store_internal_yaml.base-package=gen.org.tkit.onecx.product.store.client
quarkus.openapi-generator.codegen.spec.onecx_product_store_internal_yaml.return-response=true
Expand All @@ -32,16 +31,9 @@ quarkus.openapi-generator.codegen.spec.onecx_image_internal_yaml.additional-api-
quarkus.openapi-generator.codegen.spec.onecx_image_internal_yaml.type-mappings.File=byte[]
quarkus.openapi-generator.codegen.spec.onecx_image_internal_yaml.additional-model-type-annotations=@io.quarkus.runtime.annotations.RegisterForReflection;
quarkus.openapi-generator.codegen.spec.onecx_image_internal_yaml.enable-security-generation=false
quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_external_v1_yaml.config-key=onecx_workspace_svc_external_v1
quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_external_v1_yaml.base-package=gen.org.tkit.onecx.workspace.client
quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_external_v1_yaml.return-response=true
quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_external_v1_yaml.additional-api-type-annotations=@org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders;
quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_external_v1_yaml.additional-model-type-annotations=@io.quarkus.runtime.annotations.RegisterForReflection;
quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_external_v1_yaml.enable-security-generation=false
quarkus.openapi-generator.codegen.input-base-dir=target/tmp/openapi
%prod.quarkus.rest-client.onecx_product_store_internal.providers=io.quarkus.oidc.client.reactive.filter.OidcClientRequestReactiveFilter
%prod.quarkus.rest-client.onecx_image_internal.providers=io.quarkus.oidc.client.reactive.filter.OidcClientRequestReactiveFilter
%prod.quarkus.rest-client.onecx_workspace_svc_external_v1.providers=io.quarkus.oidc.client.reactive.filter.OidcClientRequestReactiveFilter
%prod.quarkus.oidc-client.client-id=${quarkus.application.name}
----
====
Expand Down Expand Up @@ -101,3 +93,26 @@ app:
defaultClientScopes: [ ocx-ps:all, ocx-ws:read, ocx-pm:read ]
----

uct:
read: permission on all GET requests and POST search
write: permission on PUT, POST, PATCH requests, where objects are saved or updated
delete: permission on all DELETE requests
microservice:
read: permission on all GET requests and POST search
write: permission on PUT, POST, PATCH requests, where objects are saved or updated
delete: permission on all DELETE requests
slot:
read: permission on all GET requests and POST search
write: permission on PUT, POST, PATCH requests, where objects are saved or updated
delete: permission on all DELETE requests
image:
read: permission on all GET requests and POST search
write: permission on PUT, POST, PATCH requests, where objects are saved or updated
keycloak:
client:
enabled: true
spec:
kcConfig:
defaultClientScopes: [ ocx-ps:all, ocx-ws:read, ocx-pm:read ]
----
Original file line number Diff line number Diff line change
Expand Up @@ -59,38 +59,38 @@ h| Version
| tkit-quarkus-log-cdi
| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-log-cdi.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.33.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-cdi.adoc[Link]
| 2.33.0
| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-cdi.adoc[Link]
| 2.36.0
| tkit-quarkus-log-rs
| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-log-rs.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.33.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-rs.adoc[Link]
| 2.33.0
| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-rs.adoc[Link]
| 2.36.0
| tkit-quarkus-log-json
| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-log-json.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.33.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-json.adoc[Link]
| 2.33.0
| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-json.adoc[Link]
| 2.36.0
| tkit-quarkus-rest
| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-rest.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.33.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest.adoc[Link]
| 2.33.0
| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest.adoc[Link]
| 2.36.0
| tkit-quarkus-rest-context
| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-rest-context.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.33.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest-context.adoc[Link]
| 2.33.0
| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest-context.adoc[Link]
| 2.36.0
| tkit-quarkus-jpa
| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-jpa.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.33.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-jpa.adoc[Link]
| 2.33.0
| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-jpa.adoc[Link]
| 2.36.0
| quarkus-hibernate-validator
Expand All @@ -101,8 +101,8 @@ h| Version
| onecx-permissions
| https://onecx.github.io/docs/onecx-quarkus/current/onecx-quarkus/onecx-permissions.html[Link]
| https://github.com/onecx/onecx-quarkus/blob/0.31.0/docs/modules/onecx-quarkus/pages/includes/onecx-permissions.adoc[Link]
| 0.31.0
| https://github.com/onecx/onecx-quarkus/blob/0.34.0/docs/modules/onecx-quarkus/pages/includes/onecx-permissions.adoc[Link]
| 0.34.0
| quarkus-oidc
Expand All @@ -113,14 +113,14 @@ h| Version
| tkit-quarkus-security
| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-security.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.33.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-security.adoc[Link]
| 2.33.0
| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-security.adoc[Link]
| 2.36.0
| onecx-core
| https://onecx.github.io/docs/onecx-quarkus/current/onecx-quarkus/onecx-core.html[Link]
|
| 0.31.0
| 0.34.0
| quarkus-arc
Expand Down
15 changes: 0 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,6 @@
<skipCache>true</skipCache>
</configuration>
</execution>
<execution>
<id>workspace-svc-v1</id>
<phase>generate-resources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>
https://raw.githubusercontent.com/onecx/onecx-workspace-svc/main/src/main/openapi/onecx-workspace-v1-openapi.yaml
</url>
<outputDirectory>target/tmp/openapi</outputDirectory>
<outputFileName>onecx-workspace-svc-external-v1.yaml</outputFileName>
<skipCache>true</skipCache>
</configuration>
</execution>
<execution>
<id>onecx-image-internal</id>
<phase>generate-resources</phase>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.tkit.onecx.product.store.bff.rs.controllers;

import java.util.Set;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
Expand All @@ -23,9 +21,6 @@
import gen.org.tkit.onecx.product.store.client.api.ProductsInternalApi;
import gen.org.tkit.onecx.product.store.client.api.SlotsInternalApi;
import gen.org.tkit.onecx.product.store.client.model.*;
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 All @@ -36,10 +31,6 @@ public class ProductsRestController implements ProductsApiService {
@Inject
ProductsInternalApi client;

@RestClient
@Inject
WorkspaceExternalApi workspaceClient;

@RestClient
@Inject
MicroservicesInternalApi msClient;
Expand Down Expand Up @@ -111,20 +102,9 @@ public Response getProduct(String id) {
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
.searchWorkspaces(new WorkspaceSearchCriteria().productName(name))) {
var result = workspaceResponse.readEntity(WorkspacePageResult.class);
workspaceNames = mapper.workspaceNames(result);
} catch (WebApplicationException ex) {
// ignore exception
}

ProductAndWorkspacesDTO resultProductDTO = mapper.mapProductWithWorkspaceNames(resultProduct, workspaceNames);
ProductDTO resultProductDTO = mapper.mapProduct(resultProduct);
return Response.status(response.getStatus()).entity(resultProductDTO).build();
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,10 @@

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::getDisplayName).collect(Collectors.toSet());
}

CreateProductRequest mapCreateProduct(CreateProductRequestDTO createProduct);

UpdateProductRequest mapUpdateProduct(UpdateProductRequestDTO updateProduct);
Expand Down Expand Up @@ -52,11 +43,6 @@ default String map(Set<String> classifications) {
return "";
}

@Mapping(target = "removeClassificationsItem", ignore = true)
@Mapping(target = "removeWorkspacesItem", ignore = true)
@Mapping(target = "workspaces", source = "workspaceNames")
ProductAndWorkspacesDTO mapProductWithWorkspaceNames(Product resultProduct, Set<String> workspaceNames);

@Mapping(target = "productName", source = "name")
@Mapping(target = "appName", ignore = true)
@Mapping(target = "appId", ignore = true)
Expand Down
11 changes: 1 addition & 10 deletions src/main/openapi/openapi-bff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/ProductAndWorkspaces'
$ref: '#/components/schemas/Product'
"400":
description: Bad Request
content:
Expand Down Expand Up @@ -967,15 +967,6 @@ components:
type: boolean
provider:
type: string
ProductAndWorkspaces:
type: object
allOf:
- $ref: '#/components/schemas/Product'
properties:
workspaces:
type: array
items:
type: string
ProductAbstract:
type: object
required:
Expand Down
13 changes: 0 additions & 13 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ quarkus.http.filter.images.matches=/images/*
# PROD
%prod.quarkus.rest-client.onecx_product_store_internal.url=http://onecx-product-store-svc:8080
%prod.quarkus.rest-client.onecx_image_internal.url=http://onecx-product-store-svc:8080
%prod.quarkus.rest-client.onecx_workspace_svc_external_v1.url=http://onecx-workspace-svc:8080

# BUILD
# product-store client
Expand All @@ -35,26 +34,15 @@ quarkus.openapi-generator.codegen.spec.onecx_image_internal_yaml.additional-api-
quarkus.openapi-generator.codegen.spec.onecx_image_internal_yaml.type-mappings.File=byte[]
quarkus.openapi-generator.codegen.spec.onecx_image_internal_yaml.additional-model-type-annotations=@io.quarkus.runtime.annotations.RegisterForReflection;
quarkus.openapi-generator.codegen.spec.onecx_image_internal_yaml.enable-security-generation=false

# workspace external client
quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_external_v1_yaml.config-key=onecx_workspace_svc_external_v1
quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_external_v1_yaml.base-package=gen.org.tkit.onecx.workspace.client
quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_external_v1_yaml.return-response=true
quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_external_v1_yaml.additional-api-type-annotations=@org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders;
quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_external_v1_yaml.additional-model-type-annotations=@io.quarkus.runtime.annotations.RegisterForReflection;
quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_external_v1_yaml.enable-security-generation=false

quarkus.openapi-generator.codegen.input-base-dir=target/tmp/openapi

# OIDC
%prod.quarkus.rest-client.onecx_product_store_internal.providers=io.quarkus.oidc.client.reactive.filter.OidcClientRequestReactiveFilter
%prod.quarkus.rest-client.onecx_image_internal.providers=io.quarkus.oidc.client.reactive.filter.OidcClientRequestReactiveFilter
%prod.quarkus.rest-client.onecx_workspace_svc_external_v1.providers=io.quarkus.oidc.client.reactive.filter.OidcClientRequestReactiveFilter
%prod.quarkus.oidc-client.client-id=${quarkus.application.name}

# DEV
%dev.quarkus.rest-client.onecx_product_store_internal.url=http://onecx-product-store-svc
%dev.quarkus.rest-client.onecx_workspace_svc_external_v1.url=http://onecx-workspace-svc
%dev.quarkus.oidc-client.auth-server-url=${quarkus.oidc.auth-server-url}
%dev.quarkus.oidc-client.client-id=${quarkus.oidc.client-id}
%dev.quarkus.oidc-client.credentials.secret=${quarkus.oidc.credentials.secret}
Expand All @@ -76,7 +64,6 @@ quarkus.test.integration-test-profile=test
%test.quarkus.mockserver.devservices.config-file=/mockserver.properties
%test.quarkus.mockserver.devservices.config-dir=/mockserver
%test.quarkus.rest-client.onecx_product_store_internal.url=${quarkus.mockserver.endpoint}
%test.quarkus.rest-client.onecx_workspace_svc_external_v1.url=${quarkus.mockserver.endpoint
%test.quarkus.rest-client.onecx_image_internal.url=${quarkus.mockserver.endpoint}

%test.tkit.rs.context.token.header-param=apm-principal-token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockserver.client.MockServerClient;
import org.mockserver.matchers.Times;
import org.mockserver.model.JsonBody;
import org.mockserver.model.MediaType;
import org.tkit.onecx.product.store.bff.rs.controllers.ProductsRestController;
import org.tkit.quarkus.rs.mappers.OffsetDateTimeMapper;

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 @@ -121,19 +118,6 @@ void getProductByName_test() {
.withContentType(MediaType.APPLICATION_JSON)
.withBody(JsonBody.json(data)));

var result = new WorkspacePageResult().stream(
List.of(
new WorkspaceAbstract().name("testWorkspace").displayName("testWorkspace")
.description("testWorkspace")));

// create mock rest endpoint
mockServerClient
.when(request().withPath("/v1/workspaces/search")
.withMethod(HttpMethod.POST), Times.exactly(1))
.respond(httpRequest -> response().withStatusCode(Response.Status.OK.getStatusCode())
.withContentType(MediaType.APPLICATION_JSON)
.withBody(JsonBody.json(result)));

var response = given()
.when()
.auth().oauth2(keycloakClient.getAccessToken(ADMIN))
Expand All @@ -143,7 +127,7 @@ void getProductByName_test() {
.then()
.statusCode(Response.Status.OK.getStatusCode())
.contentType(APPLICATION_JSON)
.extract().as(ProductAndWorkspacesDTO.class);
.extract().as(ProductDTO.class);

Assertions.assertNotNull(response);
Assertions.assertEquals(data.getId(), response.getId());
Expand All @@ -161,7 +145,6 @@ void getProductByName_test() {
Assertions.assertEquals(data.getIconName(), response.getIconName());
Assertions.assertEquals(Arrays.stream(data.getClassifications().split(",")).toArray().length,
response.getClassifications().size());
Assertions.assertEquals("testWorkspace", response.getWorkspaces().get(0));

// getByName for not existing name -> should return not found
// create mock rest endpoint
Expand All @@ -184,12 +167,6 @@ void getProductByName_test() {
"https://prod.ucwe.capgemini.com/wp-content/uploads/2023/11/world-cloud-report-banner1_2023.jpg",
"/app3", 0, "Product ABC", "Sun", "Themes, Menu");

// create mock rest endpoint
mockServerClient
.when(request().withPath("/v1/workspaces/search")
.withMethod(HttpMethod.POST), Times.exactly(1))
.respond(httpRequest -> response().withStatusCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));

// create mock rest endpoint
mockServerClient
.when(request().withPath(PRODUCT_STORE_SVC_INTERNAL_API_BASE_PATH + "/name/" + data2.getName())
Expand All @@ -198,7 +175,7 @@ void getProductByName_test() {
.withContentType(MediaType.APPLICATION_JSON)
.withBody(JsonBody.json(data2)));

var responseWithoutWorkspaces = given()
var response2 = given()
.when()
.auth().oauth2(keycloakClient.getAccessToken(ADMIN))
.header(APM_HEADER_PARAM, ADMIN)
Expand All @@ -207,10 +184,9 @@ void getProductByName_test() {
.then()
.statusCode(Response.Status.OK.getStatusCode())
.contentType(APPLICATION_JSON)
.extract().as(ProductAndWorkspacesDTO.class);
Assertions.assertNotNull(responseWithoutWorkspaces);
Assertions.assertEquals(data2.getId(), responseWithoutWorkspaces.getId());
Assertions.assertTrue(responseWithoutWorkspaces.getWorkspaces().isEmpty());
.extract().as(ProductDTO.class);
Assertions.assertNotNull(response2);
Assertions.assertEquals(data2.getId(), response2.getId());
}

/**
Expand Down

0 comments on commit db4a535

Please sign in to comment.