From 5f00885cfb613879e60f8ae423ab3619cb9f9be6 Mon Sep 17 00:00:00 2001 From: Dmitry Werner Date: Sat, 27 Jul 2024 01:58:06 +0500 Subject: [PATCH 1/2] BE: Cleanup in controller package BE: Cleanup in controller package --- .../ui/controller/AccessController.java | 39 ++++++++++--------- .../kafbat/ui/controller/KsqlController.java | 1 + .../ui/controller/TopicsController.java | 20 ++++------ .../kafbat/ui/emitter/MessageFiltersTest.java | 6 ++- contract/pom.xml | 11 ++++++ 5 files changed, 44 insertions(+), 33 deletions(-) diff --git a/api/src/main/java/io/kafbat/ui/controller/AccessController.java b/api/src/main/java/io/kafbat/ui/controller/AccessController.java index 5833f2e3c..d50679dd2 100644 --- a/api/src/main/java/io/kafbat/ui/controller/AccessController.java +++ b/api/src/main/java/io/kafbat/ui/controller/AccessController.java @@ -45,33 +45,34 @@ public Mono> getUserAuthInfo(ServerWebExch .map(SecurityContext::getAuthentication) .map(Principal::getName); + AuthenticationInfoDTO.AuthenticationInfoDTOBuilder builder = AuthenticationInfoDTO.builder() + .rbacEnabled(accessControlService.isRbacEnabled()); + return userName .zipWith(permissions) - .map(data -> { - var dto = new AuthenticationInfoDTO(accessControlService.isRbacEnabled()); - dto.setUserInfo(new UserInfoDTO(data.getT1(), data.getT2())); - return dto; - }) - .switchIfEmpty(Mono.just(new AuthenticationInfoDTO(accessControlService.isRbacEnabled()))) + .map(data -> (AuthenticationInfoDTO) builder + .userInfo(new UserInfoDTO(data.getT1(), data.getT2())) + .build() + ) + .switchIfEmpty(Mono.just(builder.build())) .map(ResponseEntity::ok); } private List mapPermissions(List permissions, List clusters) { return permissions .stream() - .map(permission -> { - UserPermissionDTO dto = new UserPermissionDTO(); - dto.setClusters(clusters); - dto.setResource(ResourceTypeDTO.fromValue(permission.getResource().toString().toUpperCase())); - dto.setValue(permission.getValue()); - dto.setActions(permission.getParsedActions() - .stream() - .map(p -> p.name().toUpperCase()) - .map(this::mapAction) - .filter(Objects::nonNull) - .toList()); - return dto; - }) + .map(permission -> (UserPermissionDTO) UserPermissionDTO.builder() + .clusters(clusters) + .resource(ResourceTypeDTO.fromValue(permission.getResource().toString().toUpperCase())) + .value(permission.getValue()) + .actions(permission.getParsedActions() + .stream() + .map(p -> p.name().toUpperCase()) + .map(this::mapAction) + .filter(Objects::nonNull) + .toList()) + .build() + ) .toList(); } diff --git a/api/src/main/java/io/kafbat/ui/controller/KsqlController.java b/api/src/main/java/io/kafbat/ui/controller/KsqlController.java index 6c633ee2c..d8b3203a9 100644 --- a/api/src/main/java/io/kafbat/ui/controller/KsqlController.java +++ b/api/src/main/java/io/kafbat/ui/controller/KsqlController.java @@ -53,6 +53,7 @@ public Mono> executeKsql(String cluster } @Override + @SuppressWarnings("unchecked") public Mono>> openKsqlResponsePipe(String clusterName, String pipeId, ServerWebExchange exchange) { diff --git a/api/src/main/java/io/kafbat/ui/controller/TopicsController.java b/api/src/main/java/io/kafbat/ui/controller/TopicsController.java index 53e9fc8cd..6ccfd18fd 100644 --- a/api/src/main/java/io/kafbat/ui/controller/TopicsController.java +++ b/api/src/main/java/io/kafbat/ui/controller/TopicsController.java @@ -350,18 +350,12 @@ private Comparator getComparatorForTopic( if (orderBy == null) { return defaultComparator; } - switch (orderBy) { - case TOTAL_PARTITIONS: - return Comparator.comparing(InternalTopic::getPartitionCount); - case OUT_OF_SYNC_REPLICAS: - return Comparator.comparing(t -> t.getReplicas() - t.getInSyncReplicas()); - case REPLICATION_FACTOR: - return Comparator.comparing(InternalTopic::getReplicationFactor); - case SIZE: - return Comparator.comparing(InternalTopic::getSegmentSize); - case NAME: - default: - return defaultComparator; - } + return switch (orderBy) { + case TOTAL_PARTITIONS -> Comparator.comparing(InternalTopic::getPartitionCount); + case OUT_OF_SYNC_REPLICAS -> Comparator.comparing(t -> t.getReplicas() - t.getInSyncReplicas()); + case REPLICATION_FACTOR -> Comparator.comparing(InternalTopic::getReplicationFactor); + case SIZE -> Comparator.comparing(InternalTopic::getSegmentSize); + default -> defaultComparator; + }; } } diff --git a/api/src/test/java/io/kafbat/ui/emitter/MessageFiltersTest.java b/api/src/test/java/io/kafbat/ui/emitter/MessageFiltersTest.java index cae8629eb..617cfb0c1 100644 --- a/api/src/test/java/io/kafbat/ui/emitter/MessageFiltersTest.java +++ b/api/src/test/java/io/kafbat/ui/emitter/MessageFiltersTest.java @@ -199,6 +199,10 @@ void testBase64DecodingWorks() { } private TopicMessageDTO msg() { - return new TopicMessageDTO(1, -1L, OffsetDateTime.now()); + return TopicMessageDTO.builder() + .partition(1) + .offset(-1L) + .timestamp(OffsetDateTime.now()) + .build(); } } diff --git a/contract/pom.xml b/contract/pom.xml index 994185c96..8d7e76cea 100644 --- a/contract/pom.xml +++ b/contract/pom.xml @@ -46,6 +46,11 @@ javax.annotation-api 1.3.2 + + org.projectlombok + lombok + ${org.projectlombok.version} + @@ -100,6 +105,12 @@ true true java8 + false + + @lombok.experimental.SuperBuilder + @lombok.NoArgsConstructor + @lombok.AllArgsConstructor + From 4ceda81bc235350cd0862d7754ffbc68acd79299 Mon Sep 17 00:00:00 2001 From: Roman Zabaluev Date: Mon, 5 Aug 2024 13:30:02 +0500 Subject: [PATCH 2/2] Minor polishing --- api/src/main/java/io/kafbat/ui/controller/AccessController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/io/kafbat/ui/controller/AccessController.java b/api/src/main/java/io/kafbat/ui/controller/AccessController.java index d50679dd2..e5b1ea438 100644 --- a/api/src/main/java/io/kafbat/ui/controller/AccessController.java +++ b/api/src/main/java/io/kafbat/ui/controller/AccessController.java @@ -45,7 +45,7 @@ public Mono> getUserAuthInfo(ServerWebExch .map(SecurityContext::getAuthentication) .map(Principal::getName); - AuthenticationInfoDTO.AuthenticationInfoDTOBuilder builder = AuthenticationInfoDTO.builder() + var builder = AuthenticationInfoDTO.builder() .rbacEnabled(accessControlService.isRbacEnabled()); return userName