From 471eba0a09be74b24b94b9bb65fd97ab89e3327f Mon Sep 17 00:00:00 2001 From: Jorden_Reuter Date: Mon, 12 Feb 2024 11:36:04 +0100 Subject: [PATCH] feat: added workspaceName and getAllWorkspaceNames endpoint --- pom.xml | 31 ++++++++++++++----- .../AnnouncementRestController.java | 18 +++++++++-- .../openapi/openapi-announcement-bff.yaml | 31 +++++++++++++++++++ src/main/resources/application.properties | 12 +++++++ .../rs/AnnouncementRestControllerTest.java | 29 +++++++++++++++++ 5 files changed, 110 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index a2b06d6..5925a5f 100644 --- a/pom.xml +++ b/pom.xml @@ -178,16 +178,31 @@ wget + + + https://raw.githubusercontent.com/onecx/onecx-announcement-svc/main/src/main/openapi/announcement-openapi-internal.yaml + + target/tmp/openapi + onecx-announcement-svc.yaml + true + + + + workspace-v1 + generate-resources + + wget + + + + https://raw.githubusercontent.com/onecx/onecx-workspace-svc/main/src/main/openapi/onecx-workspace-v1-openapi.yaml + + target/tmp/openapi + onecx-workspace-svc-v1.yaml + true + - - - https://raw.githubusercontent.com/onecx/onecx-announcement-svc/main/src/main/openapi/announcement-openapi-internal.yaml - - target/tmp/openapi - onecx-announcement-svc.yaml - true - diff --git a/src/main/java/org/tkit/onecx/announcement/bff/rs/controller/AnnouncementRestController.java b/src/main/java/org/tkit/onecx/announcement/bff/rs/controller/AnnouncementRestController.java index 54b7cf6..6cedde3 100644 --- a/src/main/java/org/tkit/onecx/announcement/bff/rs/controller/AnnouncementRestController.java +++ b/src/main/java/org/tkit/onecx/announcement/bff/rs/controller/AnnouncementRestController.java @@ -1,5 +1,7 @@ package org.tkit.onecx.announcement.bff.rs.controller; +import java.util.HashSet; + import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import jakarta.transaction.Transactional; @@ -12,13 +14,13 @@ import org.jboss.resteasy.reactive.server.ServerExceptionMapper; import org.tkit.onecx.announcement.bff.rs.mappers.AnnouncementMapper; import org.tkit.onecx.announcement.bff.rs.mappers.ExceptionMapper; -import org.tkit.onecx.announcement.bff.rs.mappers.ProblemDetailMapper; import org.tkit.quarkus.log.cdi.LogService; import gen.org.tkit.onecx.announcement.bff.rs.internal.AnnouncementInternalApiService; import gen.org.tkit.onecx.announcement.bff.rs.internal.model.*; import gen.org.tkit.onecx.announcement.client.api.AnnouncementInternalApi; import gen.org.tkit.onecx.announcement.client.model.*; +import gen.org.tkit.onecx.workspace.client.api.WorkspaceExternalApi; @ApplicationScoped @Transactional(value = Transactional.TxType.NOT_SUPPORTED) @@ -30,10 +32,11 @@ public class AnnouncementRestController implements AnnouncementInternalApiServic AnnouncementInternalApi client; @Inject - AnnouncementMapper announcementMapper; + @RestClient + WorkspaceExternalApi workspaceClient; @Inject - ProblemDetailMapper problemDetailMapper; + AnnouncementMapper announcementMapper; @Inject ExceptionMapper exceptionMapper; @@ -66,6 +69,15 @@ public Response getAllAppsWithAnnouncements() { } } + @Override + public Response getAllWorkspaceNames() { + HashSet workspaceNames = new HashSet<>(); + try (Response response = workspaceClient.getAllWorkspaceNames()) { + workspaceNames = response.readEntity(HashSet.class); + } + return Response.status(Response.Status.OK).entity(workspaceNames).build(); + } + @Override public Response getAnnouncementById(String id) { diff --git a/src/main/openapi/openapi-announcement-bff.yaml b/src/main/openapi/openapi-announcement-bff.yaml index cda14ee..0a6220b 100644 --- a/src/main/openapi/openapi-announcement-bff.yaml +++ b/src/main/openapi/openapi-announcement-bff.yaml @@ -166,6 +166,25 @@ paths: application/json: schema: $ref: '#/components/schemas/ProblemDetailResponse' + /announcements/workspaces: + get: + x-onecx: + permissions: + announcements: + - read + tags: + - AnnouncementInternal + summary: retrieve list of all existing workspace names + operationId: getAllWorkspaceNames + responses: + "200": + description: OK + content: + application/json: + schema: + type: array + items: + type: string components: schemas: AnnouncementApps: @@ -175,6 +194,10 @@ components: type: array items: type: string + workspaceNames: + type: array + items: + type: string CreateAnnouncementRequest: type: object required: @@ -197,6 +220,8 @@ components: $ref: '#/components/schemas/OffsetDateTime' appId: type: string + workspaceName: + type: string AnnouncementSearchCriteria: type: object properties: @@ -220,6 +245,8 @@ components: $ref: '#/components/schemas/OffsetDateTime' appId: type: string + workspaceName: + type: string pageNumber: format: int32 description: The number of page. @@ -256,6 +283,8 @@ components: $ref: '#/components/schemas/OffsetDateTime' appId: type: string + workspaceName: + type: string Announcement: type: object properties: @@ -288,6 +317,8 @@ components: $ref: '#/components/schemas/OffsetDateTime' appId: type: string + workspaceName: + type: string AnnouncementPageResult: type: object properties: diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 4e0a5ff..a4e3a60 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -10,18 +10,27 @@ org.eclipse.microprofile.rest.client.propagateHeaders=apm-principal-token # PROD %prod.quarkus.rest-client.onecx_announcement_svc.url=http://onecx-announcement-svc:8080 +%prod.quarkus.rest-client.onecx_workspace_svc_v1.url=http://onecx-workspace-svc:8080 + %prod.quarkus.oidc-client.client-id=${quarkus.application.name} # BUILD quarkus.openapi-generator.codegen.input-base-dir=target/tmp/openapi +# announcement client quarkus.openapi-generator.codegen.spec.onecx_announcement_svc_yaml.config-key=onecx_announcement_svc quarkus.openapi-generator.codegen.spec.onecx_announcement_svc_yaml.base-package=gen.org.tkit.onecx.announcement.client quarkus.openapi-generator.codegen.spec.onecx_announcement_svc_yaml.return-response=true quarkus.openapi-generator.codegen.spec.onecx_announcement_svc.additional-api-type-annotations=@org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders; +# workspace external client +quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_v1_yaml.config-key=onecx_workspace_svc_v1 +quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_v1_yaml.base-package=gen.org.tkit.onecx.workspace.client +quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_v1_yaml.return-response=true +quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_v1_yaml.additional-api-type-annotations=@org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders; # DEV %dev.quarkus.rest-client.onecx_announcement_svc.url=${quarkus.mockserver.endpoint} +%dev.quarkus.rest-client.onecx_workspace_svc_v1.url=${quarkus.mockserver.endpoint} # INTEGRATION TEST quarkus.test.integration-test-profile=test @@ -35,9 +44,12 @@ 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_announcement_svc.url=${quarkus.mockserver.endpoint} +%test.quarkus.rest-client.onecx_workspace_svc_v1.url=${quarkus.mockserver.endpoint} + %test.tkit.rs.context.token.header-param=apm-principal-token %test.tkit.rs.context.token.enabled=false %test.quarkus.rest-client.onecx_announcement_svc.providers=io.quarkus.oidc.client.reactive.filter.OidcClientRequestReactiveFilter +%test.quarkus.rest-client.onecx_workspace_svc_v1.providers=io.quarkus.oidc.client.reactive.filter.OidcClientRequestReactiveFilter %test.tkit.rs.context.tenant-id.mock.claim-org-id=orgId %test.quarkus.rest-client.onecx_permission.url=${quarkus.mockserver.endpoint} %test.quarkus.keycloak.devservices.roles.alice=role-admin diff --git a/src/test/java/org/tkit/onecx/announcement/bff/rs/AnnouncementRestControllerTest.java b/src/test/java/org/tkit/onecx/announcement/bff/rs/AnnouncementRestControllerTest.java index 1676e48..5f5f614 100644 --- a/src/test/java/org/tkit/onecx/announcement/bff/rs/AnnouncementRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/announcement/bff/rs/AnnouncementRestControllerTest.java @@ -7,7 +7,9 @@ import java.time.OffsetDateTime; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import jakarta.ws.rs.HttpMethod; import jakarta.ws.rs.core.Response; @@ -387,4 +389,31 @@ void createAnnouncement_shouldReturnBadRequest_whenRunningIntoValidationConstrai Assertions.assertNotNull(response); } + + @Test + void getAllWorkspaceNames() { + Set workspaceNames = new HashSet<>(); + workspaceNames.add("testWorkspace"); + // create mock rest endpoint + mockServerClient + .when(request().withPath("/v1/workspaces") + .withMethod(HttpMethod.GET)) + .respond(httpRequest -> response().withStatusCode(Response.Status.OK.getStatusCode()) + .withContentType(MediaType.APPLICATION_JSON) + .withBody(JsonBody.json(workspaceNames))); + + var response = given() + .when() + .auth().oauth2(keycloakClient.getAccessToken(ADMIN)) + .header(APM_HEADER_PARAM, ADMIN) + .contentType(APPLICATION_JSON) + .get("/workspaces") + .then() + .statusCode(Response.Status.OK.getStatusCode()) + .contentType(APPLICATION_JSON) + .extract().as(HashSet.class); + + Assertions.assertNotNull(response); + Assertions.assertTrue(response.contains("testWorkspace")); + } }