Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BE: Chore: Use dto builders in controller package #504

Merged
merged 4 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions api/src/main/java/io/kafbat/ui/controller/AccessController.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,34 @@ public Mono<ResponseEntity<AuthenticationInfoDTO>> getUserAuthInfo(ServerWebExch
.map(SecurityContext::getAuthentication)
.map(Principal::getName);

var 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<UserPermissionDTO> mapPermissions(List<Permission> permissions, List<String> 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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public Mono<ResponseEntity<KsqlCommandV2ResponseDTO>> executeKsql(String cluster
}

@Override
@SuppressWarnings("unchecked")
public Mono<ResponseEntity<Flux<KsqlResponseDTO>>> openKsqlResponsePipe(String clusterName,
String pipeId,
ServerWebExchange exchange) {
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;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
11 changes: 11 additions & 0 deletions contract/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${org.projectlombok.version}</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -100,6 +105,12 @@
<useTags>true</useTags>
<useSpringBoot3>true</useSpringBoot3>
<dateLibrary>java8</dateLibrary>
<generatedConstructorWithRequiredArgs>false</generatedConstructorWithRequiredArgs>
<additionalModelTypeAnnotations>
@lombok.experimental.SuperBuilder
@lombok.NoArgsConstructor
@lombok.AllArgsConstructor
</additionalModelTypeAnnotations>
</configOptions>
</configuration>
</execution>
Expand Down
Loading