Skip to content

Commit

Permalink
BE: Cleanup in controller package
Browse files Browse the repository at this point in the history
  • Loading branch information
wernerdv committed Jul 26, 2024
1 parent 8c70126 commit d8cb677
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 29 deletions.
19 changes: 10 additions & 9 deletions api/src/main/java/io/kafbat/ui/controller/AccessController.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,17 @@ private List<UserPermissionDTO> mapPermissions(List<Permission> permissions, Lis
return permissions
.stream()
.map(permission -> {
UserPermissionDTO dto = new UserPermissionDTO();
dto.setClusters(clusters);
dto.setResource(ResourceTypeDTO.fromValue(permission.getResource().toString().toUpperCase()));
UserPermissionDTO dto = new UserPermissionDTO(
clusters,
ResourceTypeDTO.fromValue(permission.getResource().toString().toUpperCase()),
permission.getParsedActions()
.stream()
.map(p -> p.name().toUpperCase())
.map(this::mapAction)
.filter(Objects::nonNull)
.toList()
);
dto.setValue(permission.getValue());
dto.setActions(permission.getParsedActions()
.stream()
.map(p -> p.name().toUpperCase())
.map(this::mapAction)
.filter(Objects::nonNull)
.toList());
return dto;
})
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public Mono<ResponseEntity<UploadedFileInfoDTO>> uploadConfigRelatedFile(Flux<Pa
.then(fileFlux.single())
.flatMap(file ->
dynamicConfigOperations.uploadConfigRelatedFile((FilePart) file)
.map(path -> new UploadedFileInfoDTO().location(path.toString()))
.map(path -> new UploadedFileInfoDTO(path.toString()))
.map(ResponseEntity::ok))
.doOnEach(sig -> audit(context, sig));
}
Expand Down
10 changes: 5 additions & 5 deletions api/src/main/java/io/kafbat/ui/controller/KsqlController.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ public Mono<ResponseEntity<KsqlCommandV2ResponseDTO>> executeKsql(String cluster
.operationParams(command)
.build();
return validateAccess(context).thenReturn(
new KsqlCommandV2ResponseDTO().pipeId(
ksqlServiceV2.registerCommand(
getCluster(clusterName),
command.getKsql(),
Optional.ofNullable(command.getStreamsProperties()).orElse(Map.of()))))
new KsqlCommandV2ResponseDTO(ksqlServiceV2.registerCommand(
getCluster(clusterName),
command.getKsql(),
Optional.ofNullable(command.getStreamsProperties()).orElse(Map.of()))))
.doOnEach(sig -> audit(context, sig));
}
)
.map(ResponseEntity::ok);
}

@Override
@SuppressWarnings("unchecked")
public Mono<ResponseEntity<Flux<KsqlResponseDTO>>> openKsqlResponsePipe(String clusterName,
String pipeId,
ServerWebExchange exchange) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public Mono<ResponseEntity<Flux<SchemaSubjectDTO>>> getAllVersionsBySubject(
public Mono<ResponseEntity<CompatibilityLevelDTO>> getGlobalSchemaCompatibilityLevel(
String clusterName, ServerWebExchange exchange) {
return schemaRegistryService.getGlobalSchemaCompatibilityLevel(getCluster(clusterName))
.map(c -> new CompatibilityLevelDTO().compatibility(kafkaSrMapper.toDto(c)))
.map(c -> new CompatibilityLevelDTO(kafkaSrMapper.toDto(c)))
.map(ResponseEntity::ok)
.defaultIfEmpty(ResponseEntity.notFound().build());
}
Expand Down
20 changes: 7 additions & 13 deletions api/src/main/java/io/kafbat/ui/controller/TopicsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,18 +350,12 @@ private Comparator<InternalTopic> 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;
};
}
}

0 comments on commit d8cb677

Please sign in to comment.