Skip to content

Commit

Permalink
feat: added workspaceName and getAllWorkspaceNames endpoint (#13)
Browse files Browse the repository at this point in the history
* feat: added workspaceName and getAllWorkspaceNames endpoint

* fix: fix search response and operationId
  • Loading branch information
JordenReuter authored Feb 13, 2024
1 parent 1faae64 commit db19504
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 16 deletions.
31 changes: 23 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,31 @@
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>
https://raw.githubusercontent.com/onecx/onecx-announcement-svc/main/src/main/openapi/announcement-openapi-internal.yaml
</url>
<outputDirectory>target/tmp/openapi</outputDirectory>
<outputFileName>onecx-announcement-svc.yaml</outputFileName>
<skipCache>true</skipCache>
</configuration>
</execution>
<execution>
<id>workspace-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-v1.yaml</outputFileName>
<skipCache>true</skipCache>
</configuration>
</execution>
</executions>
<configuration>
<url>
https://raw.githubusercontent.com/onecx/onecx-announcement-svc/main/src/main/openapi/announcement-openapi-internal.yaml
</url>
<outputDirectory>target/tmp/openapi</outputDirectory>
<outputFileName>onecx-announcement-svc.yaml</outputFileName>
<skipCache>true</skipCache>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -66,6 +69,15 @@ public Response getAllAppsWithAnnouncements() {
}
}

@Override
public Response getAllWorkspaceNames() {
HashSet<String> 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) {

Expand All @@ -77,7 +89,7 @@ public Response getAnnouncementById(String id) {
}

@Override
public Response getAnnouncements(AnnouncementSearchCriteriaDTO announcementSearchCriteriaDTO) {
public Response searchAnnouncements(AnnouncementSearchCriteriaDTO announcementSearchCriteriaDTO) {

try (Response response = client
.getAnnouncements(announcementMapper.mapAnnouncementSearchCriteria(announcementSearchCriteriaDTO))) {
Expand Down
37 changes: 33 additions & 4 deletions src/main/openapi/openapi-announcement-bff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ paths:
tags:
- AnnouncementInternal
summary: Find announcements by criteria
operationId: getAnnouncements
operationId: searchAnnouncements
requestBody:
required: true
content:
Expand All @@ -30,9 +30,7 @@ paths:
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/AnnouncementPageResult'
$ref: '#/components/schemas/AnnouncementPageResult'
"400":
description: Bad request
content:
Expand Down Expand Up @@ -166,6 +164,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:
Expand All @@ -175,6 +192,10 @@ components:
type: array
items:
type: string
workspaceNames:
type: array
items:
type: string
CreateAnnouncementRequest:
type: object
required:
Expand All @@ -197,6 +218,8 @@ components:
$ref: '#/components/schemas/OffsetDateTime'
appId:
type: string
workspaceName:
type: string
AnnouncementSearchCriteria:
type: object
properties:
Expand All @@ -220,6 +243,8 @@ components:
$ref: '#/components/schemas/OffsetDateTime'
appId:
type: string
workspaceName:
type: string
pageNumber:
format: int32
description: The number of page.
Expand Down Expand Up @@ -256,6 +281,8 @@ components:
$ref: '#/components/schemas/OffsetDateTime'
appId:
type: string
workspaceName:
type: string
Announcement:
type: object
properties:
Expand Down Expand Up @@ -288,6 +315,8 @@ components:
$ref: '#/components/schemas/OffsetDateTime'
appId:
type: string
workspaceName:
type: string
AnnouncementPageResult:
type: object
properties:
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -387,4 +389,31 @@ void createAnnouncement_shouldReturnBadRequest_whenRunningIntoValidationConstrai

Assertions.assertNotNull(response);
}

@Test
void getAllWorkspaceNames() {
Set<String> 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"));
}
}

0 comments on commit db19504

Please sign in to comment.