Skip to content

Commit

Permalink
feat: added new endpoint (#29)
Browse files Browse the repository at this point in the history
* feat: added new endppint

* feat: reworked implementation

* feat: updated pom and added docs

* fix: sonar issues

* feat: bugfix and improved exception mapper
  • Loading branch information
JordenReuter authored Apr 23, 2024
1 parent 22cc53c commit a27adb0
Show file tree
Hide file tree
Showing 12 changed files with 511 additions and 9 deletions.
3 changes: 3 additions & 0 deletions docs/antora.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: onecx-announcement
title: Announcement Management
version: latest
1 change: 1 addition & 0 deletions docs/modules/onecx-announcement-bff/nav.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* xref:onecx-announcement-bff:index.adoc[Announcement Bff]
8 changes: 8 additions & 0 deletions docs/modules/onecx-announcement-bff/pages/index.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include::onecx-announcement-bff-attributes.adoc[opts=optional]

== onecx-announcement-bff

include::docs.adoc[opts=optional]


include::onecx-announcement-bff-docs.adoc[opts=optional]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

:docker-registry: https://github.com/onecx/onecx-announcement-bff/pkgs/container/onecx-announcement-bff
:helm-registry: https://github.com/onecx/onecx-announcement-bff/pkgs/container/charts%2Fonecx-announcement-bff
:properties-file: src/main/resources/application.properties
:helm-file: src/main/helm/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

include::onecx-announcement-bff-attributes.adoc[opts=optional]

=== Default properties

.{properties-file}
[%collapsible%open]
====
[source,properties,subs=attributes+]
----
quarkus.http.auth.permission.health.paths=/q/*
quarkus.http.auth.permission.health.policy=permit
quarkus.http.auth.permission.default.paths=/*
quarkus.http.auth.permission.default.policy=authenticated
onecx.permissions.application-id=${quarkus.application.name}
org.eclipse.microprofile.rest.client.propagateHeaders=apm-principal-token
%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}
quarkus.openapi-generator.codegen.input-base-dir=target/tmp/openapi
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;
quarkus.openapi-generator.codegen.spec.onecx_announcement_svc.additional-model-type-annotations=@io.quarkus.runtime.annotations.RegisterForReflection;
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;
quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_v1_yaml.additional-model-type-annotations=@io.quarkus.runtime.annotations.RegisterForReflection;
onecx.permissions.product-name=application
----
====

=== Extensions

include::onecx-announcement-bff-extensions.adoc[opts=optional]

=== Container

{docker-registry}[Docker registry]


=== Helm

{helm-registry}[Helm registry]

Default values

.{helm-file}
[source,yaml]
----
app:
name: bff
image:
repository: "onecx/onecx-announcement-bff"
operator:
# Permission
permission:
enabled: true
spec:
permissions:
announcement:
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
----

Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@

include::onecx-announcement-bff-attributes.adoc[opts=optional]

[.extension.table.searchable, cols="50,.^15,.^15,.^20"]
|===
h| Extensions
h| Documentation
h| Configuration
h| Version

| quarkus-rest

| https://quarkus.io/guides/rest[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-rest.adoc[Link]
| 3.9.3
| quarkus-smallrye-openapi
| https://quarkus.io/guides/openapi-swaggerui[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-smallrye-openapi.adoc[Link]
| 3.9.3
| quarkus-rest-jackson
| https://quarkus.io/guides/rest-json[Link]
|
| 3.9.3
| quarkus-smallrye-health
| https://quarkus.io/guides/smallrye-health[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-smallrye-health.adoc[Link]
| 3.9.3
| quarkus-openapi-generator
| https://docs.quarkiverse.io/quarkus-openapi-generator/dev/index.html[Link]
| https://github.com/quarkiverse/quarkus-openapi-generator/blob/2.4.1/docs/modules/ROOT/pages/includes/quarkus-openapi-generator.adoc[Link]
| 2.4.1
| quarkus-rest-client-reactive-jackson
| https://quarkus.io/guides/rest-client[Link]
|
| 3.9.3
| 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.22.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-cdi.adoc[Link]
| 2.22.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.22.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-rs.adoc[Link]
| 2.22.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.22.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-json.adoc[Link]
| 2.22.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.22.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest.adoc[Link]
| 2.22.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.22.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest-context.adoc[Link]
| 2.22.0
| quarkus-hibernate-validator
| https://quarkus.io/guides/validation[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-hibernate-validator.adoc[Link]
| 3.9.3
| quarkus-opentelemetry
| https://quarkus.io/guides/opentelemetry[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-opentelemetry.adoc[Link]
| 3.9.3
| quarkus-micrometer-registry-prometheus
| https://quarkus.io/guides/telemetry-micrometer[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-micrometer-registry-prometheus.adoc[Link]
| 3.9.3
| onecx-permissions
| https://onecx.github.io/docs/onecx-quarkus/current/onecx-quarkus/onecx-permissions.html[Link]
| https://github.com/onecx/onecx-quarkus/blob/0.17.0/docs/modules/onecx-quarkus/pages/includes/onecx-permissions.adoc[Link]
| 0.17.0
| quarkus-oidc
| https://quarkus.io/guides/security-oidc-bearer-token-authentication-tutorial[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-oidc.adoc[Link]
| 3.9.3
| quarkus-oidc-client-reactive-filter
| https://quarkus.io/guides/security-openid-connect-client-reference[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-oidc-client-reactive-filter.adoc[Link]
| 3.9.3
| 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.22.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-security.adoc[Link]
| 2.22.0
| onecx-core
| https://onecx.github.io/docs/onecx-quarkus/current/onecx-quarkus/onecx-core.html[Link]
|
| 0.17.0
| quarkus-arc
| https://quarkus.io/guides/cdi-reference[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-arc.adoc[Link]
| 3.9.3
| quarkus-container-image-docker
| https://quarkus.io/guides/container-image[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-container-image-docker.adoc[Link]
| 3.9.3
|===
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
<parent>
<groupId>org.tkit.onecx</groupId>
<artifactId>onecx-quarkus3-parent</artifactId>
<version>0.37.0</version>
<version>0.47.0</version>
</parent>

<artifactId>onecx-announcement-bff</artifactId>
<version>999-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive</artifactId>
<artifactId>quarkus-rest</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
<artifactId>quarkus-rest-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
import jakarta.validation.ConstraintViolationException;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Response;

import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.jboss.resteasy.reactive.ClientWebApplicationException;
import org.jboss.resteasy.reactive.RestResponse;
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;
import org.tkit.onecx.announcement.bff.rs.mappers.AnnouncementMapper;
Expand Down Expand Up @@ -91,6 +91,23 @@ public Response getAnnouncementById(String id) {
}
}

@Override
public Response searchActiveAnnouncements(ActiveAnnouncementsSearchCriteriaDTO activeAnnouncementsSearchCriteriaDTO) {
var searchCriteria = announcementMapper.mapActiveAnnouncementSearchCriteria(activeAnnouncementsSearchCriteriaDTO);
searchCriteria.setPageSize(100);
searchCriteria.setPageNumber(0);
try (Response response = client
.getAnnouncements(searchCriteria)) {
AnnouncementPageResult announcementPageResult = response.readEntity(AnnouncementPageResult.class);
ActiveAnnouncementsPageResultDTO announcementPageResultDTO = announcementMapper
.mapAnnouncementPageResultToActiveAnnouncementPageResultDTO(announcementPageResult);
announcementPageResultDTO = announcementMapper.filterAndSort(announcementPageResultDTO,
activeAnnouncementsSearchCriteriaDTO);

return Response.status(response.getStatus()).entity(announcementPageResultDTO).build();
}
}

@Override
public Response searchAnnouncements(AnnouncementSearchCriteriaDTO announcementSearchCriteriaDTO) {

Expand All @@ -116,13 +133,11 @@ public Response updateAnnouncementById(String id, UpdateAnnouncementRequestDTO u

@ServerExceptionMapper
public RestResponse<ProblemDetailResponseDTO> constraint(ConstraintViolationException ex) {

return exceptionMapper.constraint(ex);
}

@ServerExceptionMapper
public Response restException(WebApplicationException ex) {

return Response.status(ex.getResponse().getStatus()).build();
public Response restException(ClientWebApplicationException ex) {
return exceptionMapper.clientException(ex);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.tkit.onecx.announcement.bff.rs.mappers;

import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

import org.mapstruct.Mapper;
Expand Down Expand Up @@ -33,4 +33,74 @@ default Set<String> workspaceNames(WorkspacePageResult result) {
@Mapping(target = "removeStreamItem", ignore = true)
AnnouncementPageResultDTO mapAnnouncementPageResultToAnnouncementPageResultDTO(
AnnouncementPageResult announcementPageResult);

@Mapping(target = "type", ignore = true)
@Mapping(target = "title", ignore = true)
@Mapping(target = "status", constant = "ACTIVE")
@Mapping(target = "startDateTo", source = "currentDate")
@Mapping(target = "startDateFrom", ignore = true)
@Mapping(target = "priority", ignore = true)
@Mapping(target = "endDateTo", ignore = true)
@Mapping(target = "endDateFrom", source = "currentDate")
@Mapping(target = "content", ignore = true)
@Mapping(target = "appId", ignore = true)
@Mapping(target = "workspaceName", ignore = true)
AnnouncementSearchCriteria mapActiveAnnouncementSearchCriteria(
ActiveAnnouncementsSearchCriteriaDTO activeAnnouncementsSearchCriteriaDTO);

@Mapping(target = "removeStreamItem", ignore = true)
ActiveAnnouncementsPageResultDTO mapAnnouncementPageResultToActiveAnnouncementPageResultDTO(
AnnouncementPageResult announcementPageResult);

default List<AnnouncementAbstractDTO> sort(List<AnnouncementAbstractDTO> mergedResult) {
List<AnnouncementAbstractDTO> sortedList = new ArrayList<>(mergedResult);
sortedList.sort(Comparator.comparing(AnnouncementAbstractDTO::getPriority)
.thenComparing((AnnouncementAbstractDTO item) -> item.getWorkspaceName() == null ? 0 : 1)
.thenComparing(AnnouncementAbstractDTO::getTitle));
return sortedList;
}

default ActiveAnnouncementsPageResultDTO filterAndSort(ActiveAnnouncementsPageResultDTO announcementPageResultDTO,
ActiveAnnouncementsSearchCriteriaDTO activeAnnouncementsSearchCriteriaDTO) {
ActiveAnnouncementsPageResultDTO pageResult = new ActiveAnnouncementsPageResultDTO();

if (activeAnnouncementsSearchCriteriaDTO.getWorkspaceName() != null) {
pageResult.setStream(announcementPageResultDTO.getStream().stream()
.filter(announcementAbstractDTO -> announcementAbstractDTO.getWorkspaceName() == null
|| announcementAbstractDTO.getWorkspaceName().equals(activeAnnouncementsSearchCriteriaDTO
.getWorkspaceName()))
.toList());
} else {
pageResult.setStream(announcementPageResultDTO.getStream().stream()
.filter(announcementAbstractDTO -> announcementAbstractDTO.getWorkspaceName() == null).toList());
}
//remove duplicates
HashSet<AnnouncementAbstractDTO> set = new HashSet<>(pageResult.getStream());
pageResult.setStream(sort(set.stream().toList()));

pageResult.setTotalElements((long) pageResult.getStream().size());
pageResult.setNumber(activeAnnouncementsSearchCriteriaDTO.getPageNumber());
pageResult.setSize(activeAnnouncementsSearchCriteriaDTO.getPageSize());
pageResult.setTotalPages(1L);
if (pageResult.getTotalElements() / pageResult.getSize() > 0) {
pageResult.setTotalPages(pageResult.getTotalElements() / pageResult.getSize());
}
int startIndex = 0;
int endIndex = Math.toIntExact(pageResult.getTotalElements());
if (activeAnnouncementsSearchCriteriaDTO.getPageNumber() != 0) {
startIndex = (activeAnnouncementsSearchCriteriaDTO.getPageSize()
* activeAnnouncementsSearchCriteriaDTO.getPageNumber());
endIndex = startIndex + activeAnnouncementsSearchCriteriaDTO.getPageSize() - 1;
}
if (activeAnnouncementsSearchCriteriaDTO.getPageSize() != 100) {
endIndex = startIndex + activeAnnouncementsSearchCriteriaDTO.getPageSize();
}
if (startIndex <= pageResult.getStream().size()) {
pageResult.setStream(
pageResult.getStream().subList(startIndex, Math.min(endIndex, pageResult.getStream().size())));
} else {
pageResult.setStream(new ArrayList<>());
}
return pageResult;
}
}
Loading

0 comments on commit a27adb0

Please sign in to comment.