From 8af22c38d07e2899b3a981302226e55a1fe8b515 Mon Sep 17 00:00:00 2001 From: Andrej Petras Date: Thu, 29 Feb 2024 11:17:24 +0100 Subject: [PATCH] feat: update workspace external api (#17) * feat: update workspace external api * feat: update workspace external api --- .../rs/controller/AnnouncementRestController.java | 11 +++++++---- .../bff/rs/mappers/AnnouncementMapper.java | 12 ++++++++++++ .../bff/rs/AnnouncementRestControllerTest.java | 15 +++++++++------ 3 files changed, 28 insertions(+), 10 deletions(-) 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 8119d2c..b1a2e81 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,6 +1,6 @@ package org.tkit.onecx.announcement.bff.rs.controller; -import java.util.HashSet; +import java.util.Set; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; @@ -21,6 +21,8 @@ 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; +import gen.org.tkit.onecx.workspace.client.model.WorkspacePageResult; +import gen.org.tkit.onecx.workspace.client.model.WorkspaceSearchCriteria; @ApplicationScoped @Transactional(value = Transactional.TxType.NOT_SUPPORTED) @@ -71,9 +73,10 @@ public Response getAllAppsWithAnnouncements() { @Override public Response getAllWorkspaceNames() { - HashSet workspaceNames = new HashSet<>(); - try (Response response = workspaceClient.getAllWorkspaceNames()) { - workspaceNames = response.readEntity(HashSet.class); + Set workspaceNames; + try (Response response = workspaceClient.searchWorkspaces(new WorkspaceSearchCriteria())) { + var result = response.readEntity(WorkspacePageResult.class); + workspaceNames = announcementMapper.workspaceNames(result); } return Response.status(Response.Status.OK).entity(workspaceNames).build(); } diff --git a/src/main/java/org/tkit/onecx/announcement/bff/rs/mappers/AnnouncementMapper.java b/src/main/java/org/tkit/onecx/announcement/bff/rs/mappers/AnnouncementMapper.java index e3c94fc..60ade18 100644 --- a/src/main/java/org/tkit/onecx/announcement/bff/rs/mappers/AnnouncementMapper.java +++ b/src/main/java/org/tkit/onecx/announcement/bff/rs/mappers/AnnouncementMapper.java @@ -1,15 +1,27 @@ package org.tkit.onecx.announcement.bff.rs.mappers; +import java.util.Set; +import java.util.stream.Collectors; + import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.tkit.quarkus.rs.mappers.OffsetDateTimeMapper; import gen.org.tkit.onecx.announcement.bff.rs.internal.model.*; import gen.org.tkit.onecx.announcement.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 AnnouncementMapper { + default Set workspaceNames(WorkspacePageResult result) { + if (result == null || result.getStream() == null) { + return Set.of(); + } + return result.getStream().stream().map(WorkspaceAbstract::getName).collect(Collectors.toSet()); + } + CreateAnnouncementRequest mapCreateAnnouncement(CreateAnnouncementRequestDTO createAnnouncementRequestDTO); UpdateAnnouncementRequest mapUpdateAnnouncement(UpdateAnnouncementRequestDTO updateAnnouncementRequestDTO); 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 5f5f614..3588380 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 @@ -9,7 +9,6 @@ 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; @@ -24,6 +23,8 @@ import gen.org.tkit.onecx.announcement.bff.rs.internal.model.*; import gen.org.tkit.onecx.announcement.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; @@ -392,15 +393,17 @@ void createAnnouncement_shouldReturnBadRequest_whenRunningIntoValidationConstrai @Test void getAllWorkspaceNames() { - Set 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") - .withMethod(HttpMethod.GET)) + .when(request().withPath("/v1/workspaces/search") + .withMethod(HttpMethod.POST)) .respond(httpRequest -> response().withStatusCode(Response.Status.OK.getStatusCode()) .withContentType(MediaType.APPLICATION_JSON) - .withBody(JsonBody.json(workspaceNames))); + .withBody(JsonBody.json(result))); var response = given() .when()