Skip to content

Commit d8cb677

Browse files
committed
BE: Cleanup in controller package
1 parent 8c70126 commit d8cb677

File tree

5 files changed

+24
-29
lines changed

5 files changed

+24
-29
lines changed

api/src/main/java/io/kafbat/ui/controller/AccessController.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,17 @@ private List<UserPermissionDTO> mapPermissions(List<Permission> permissions, Lis
6060
return permissions
6161
.stream()
6262
.map(permission -> {
63-
UserPermissionDTO dto = new UserPermissionDTO();
64-
dto.setClusters(clusters);
65-
dto.setResource(ResourceTypeDTO.fromValue(permission.getResource().toString().toUpperCase()));
63+
UserPermissionDTO dto = new UserPermissionDTO(
64+
clusters,
65+
ResourceTypeDTO.fromValue(permission.getResource().toString().toUpperCase()),
66+
permission.getParsedActions()
67+
.stream()
68+
.map(p -> p.name().toUpperCase())
69+
.map(this::mapAction)
70+
.filter(Objects::nonNull)
71+
.toList()
72+
);
6673
dto.setValue(permission.getValue());
67-
dto.setActions(permission.getParsedActions()
68-
.stream()
69-
.map(p -> p.name().toUpperCase())
70-
.map(this::mapAction)
71-
.filter(Objects::nonNull)
72-
.toList());
7374
return dto;
7475
})
7576
.toList();

api/src/main/java/io/kafbat/ui/controller/ApplicationConfigController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public Mono<ResponseEntity<UploadedFileInfoDTO>> uploadConfigRelatedFile(Flux<Pa
109109
.then(fileFlux.single())
110110
.flatMap(file ->
111111
dynamicConfigOperations.uploadConfigRelatedFile((FilePart) file)
112-
.map(path -> new UploadedFileInfoDTO().location(path.toString()))
112+
.map(path -> new UploadedFileInfoDTO(path.toString()))
113113
.map(ResponseEntity::ok))
114114
.doOnEach(sig -> audit(context, sig));
115115
}

api/src/main/java/io/kafbat/ui/controller/KsqlController.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ public Mono<ResponseEntity<KsqlCommandV2ResponseDTO>> executeKsql(String cluster
4141
.operationParams(command)
4242
.build();
4343
return validateAccess(context).thenReturn(
44-
new KsqlCommandV2ResponseDTO().pipeId(
45-
ksqlServiceV2.registerCommand(
46-
getCluster(clusterName),
47-
command.getKsql(),
48-
Optional.ofNullable(command.getStreamsProperties()).orElse(Map.of()))))
44+
new KsqlCommandV2ResponseDTO(ksqlServiceV2.registerCommand(
45+
getCluster(clusterName),
46+
command.getKsql(),
47+
Optional.ofNullable(command.getStreamsProperties()).orElse(Map.of()))))
4948
.doOnEach(sig -> audit(context, sig));
5049
}
5150
)
5251
.map(ResponseEntity::ok);
5352
}
5453

5554
@Override
55+
@SuppressWarnings("unchecked")
5656
public Mono<ResponseEntity<Flux<KsqlResponseDTO>>> openKsqlResponsePipe(String clusterName,
5757
String pipeId,
5858
ServerWebExchange exchange) {

api/src/main/java/io/kafbat/ui/controller/SchemasController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public Mono<ResponseEntity<Flux<SchemaSubjectDTO>>> getAllVersionsBySubject(
160160
public Mono<ResponseEntity<CompatibilityLevelDTO>> getGlobalSchemaCompatibilityLevel(
161161
String clusterName, ServerWebExchange exchange) {
162162
return schemaRegistryService.getGlobalSchemaCompatibilityLevel(getCluster(clusterName))
163-
.map(c -> new CompatibilityLevelDTO().compatibility(kafkaSrMapper.toDto(c)))
163+
.map(c -> new CompatibilityLevelDTO(kafkaSrMapper.toDto(c)))
164164
.map(ResponseEntity::ok)
165165
.defaultIfEmpty(ResponseEntity.notFound().build());
166166
}

api/src/main/java/io/kafbat/ui/controller/TopicsController.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -350,18 +350,12 @@ private Comparator<InternalTopic> getComparatorForTopic(
350350
if (orderBy == null) {
351351
return defaultComparator;
352352
}
353-
switch (orderBy) {
354-
case TOTAL_PARTITIONS:
355-
return Comparator.comparing(InternalTopic::getPartitionCount);
356-
case OUT_OF_SYNC_REPLICAS:
357-
return Comparator.comparing(t -> t.getReplicas() - t.getInSyncReplicas());
358-
case REPLICATION_FACTOR:
359-
return Comparator.comparing(InternalTopic::getReplicationFactor);
360-
case SIZE:
361-
return Comparator.comparing(InternalTopic::getSegmentSize);
362-
case NAME:
363-
default:
364-
return defaultComparator;
365-
}
353+
return switch (orderBy) {
354+
case TOTAL_PARTITIONS -> Comparator.comparing(InternalTopic::getPartitionCount);
355+
case OUT_OF_SYNC_REPLICAS -> Comparator.comparing(t -> t.getReplicas() - t.getInSyncReplicas());
356+
case REPLICATION_FACTOR -> Comparator.comparing(InternalTopic::getReplicationFactor);
357+
case SIZE -> Comparator.comparing(InternalTopic::getSegmentSize);
358+
default -> defaultComparator;
359+
};
366360
}
367361
}

0 commit comments

Comments
 (0)