diff options
author | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2023-07-11 08:18:56 +0000 |
---|---|---|
committer | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2023-07-11 08:18:56 +0000 |
commit | 376886832fddb2880921b3e290af69fcb778b897 (patch) | |
tree | d88c4d0c3f47c54d9d0f5fc5084bc86b2e28c0f7 /lib | |
parent | e932b0f9b8aff49d9bfd78440bc693397b00c16c (diff) |
Remove vavr
Issue-ID: PORTALNG-12
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Change-Id: I13cc4998d082b1dbd3ab1c8986e4525cd177cf89
Diffstat (limited to 'lib')
9 files changed, 38 insertions, 207 deletions
diff --git a/lib/build.gradle b/lib/build.gradle index 19e9e72..9248ce3 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -75,6 +75,10 @@ spotless { } } +tasks.withType(JavaCompile) { + dependsOn 'spotlessApply' +} + spotbugs { ignoreFailures = false effort = "max" diff --git a/lib/src/main/java/org/onap/portal/bff/config/BeansConfig.java b/lib/src/main/java/org/onap/portal/bff/config/BeansConfig.java index a0d0555..ca4333b 100644 --- a/lib/src/main/java/org/onap/portal/bff/config/BeansConfig.java +++ b/lib/src/main/java/org/onap/portal/bff/config/BeansConfig.java @@ -28,7 +28,6 @@ import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import io.vavr.jackson.datatype.VavrModule; import java.time.Clock; import java.util.List; import lombok.extern.slf4j.Slf4j; @@ -176,7 +175,7 @@ public class BeansConfig { @Bean public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) { return builder - .modules(new VavrModule(), new ProblemModule(), new JavaTimeModule()) + .modules(new ProblemModule(), new JavaTimeModule()) .build() .setSerializationInclusion(JsonInclude.Include.NON_NULL); } diff --git a/lib/src/main/java/org/onap/portal/bff/config/ConversionServiceConfig.java b/lib/src/main/java/org/onap/portal/bff/config/ConversionServiceConfig.java index 09a8d53..18830ef 100644 --- a/lib/src/main/java/org/onap/portal/bff/config/ConversionServiceConfig.java +++ b/lib/src/main/java/org/onap/portal/bff/config/ConversionServiceConfig.java @@ -21,7 +21,7 @@ package org.onap.portal.bff.config; -import io.vavr.collection.List; +import java.util.List; import org.onap.portal.bff.mappers.ActionsMapper; import org.onap.portal.bff.mappers.PreferencesMapper; import org.onap.portal.bff.mappers.RolesMapper; diff --git a/lib/src/main/java/org/onap/portal/bff/config/PortalBffConfig.java b/lib/src/main/java/org/onap/portal/bff/config/PortalBffConfig.java index 42454c8..b80fe20 100644 --- a/lib/src/main/java/org/onap/portal/bff/config/PortalBffConfig.java +++ b/lib/src/main/java/org/onap/portal/bff/config/PortalBffConfig.java @@ -21,7 +21,6 @@ package org.onap.portal.bff.config; -import io.vavr.control.Option; import java.util.List; import java.util.Map; import javax.validation.Valid; @@ -53,11 +52,12 @@ public class PortalBffConfig { @NotNull private final Map<String, List<String>> accessControl; public Mono<List<String>> getRoles(String method) { - return Option.of(accessControl.get(method)) - .map(Mono::just) - .getOrElse( - Mono.error( - Problem.valueOf( - Status.FORBIDDEN, "The user does not have the necessary access rights"))); + return Mono.just(accessControl) + .map(control -> control.get(method)) + .onErrorResume( + e -> + Mono.error( + Problem.valueOf( + Status.FORBIDDEN, "The user does not have the necessary access rights"))); } } diff --git a/lib/src/main/java/org/onap/portal/bff/controller/UsersController.java b/lib/src/main/java/org/onap/portal/bff/controller/UsersController.java index f67809b..9214ebe 100644 --- a/lib/src/main/java/org/onap/portal/bff/controller/UsersController.java +++ b/lib/src/main/java/org/onap/portal/bff/controller/UsersController.java @@ -21,7 +21,6 @@ package org.onap.portal.bff.controller; -import io.vavr.collection.List; import org.onap.portal.bff.config.PortalBffConfig; import org.onap.portal.bff.openapi.server.api.UsersApi; import org.onap.portal.bff.openapi.server.model.CreateUserRequestApiDto; @@ -138,7 +137,6 @@ public class UsersController extends AbstractBffController implements UsersApi { String userId, String xRequestId, Flux<RoleApiDto> rolesFlux, ServerWebExchange exchange) { return checkRoleAccess(UPDATE_ROLES, exchange) .then(rolesFlux.collectList()) - .map(List::ofAll) .flatMap(roles -> keycloakService.updateAssignedRoles(userId, roles, xRequestId)) .map(ResponseEntity::ok); } diff --git a/lib/src/main/java/org/onap/portal/bff/services/KeycloakService.java b/lib/src/main/java/org/onap/portal/bff/services/KeycloakService.java index ff96b63..88c25c2 100644 --- a/lib/src/main/java/org/onap/portal/bff/services/KeycloakService.java +++ b/lib/src/main/java/org/onap/portal/bff/services/KeycloakService.java @@ -24,9 +24,10 @@ package org.onap.portal.bff.services; import io.vavr.API; import io.vavr.Tuple; import io.vavr.Tuple2; -import io.vavr.collection.List; -import io.vavr.control.Option; import java.net.URI; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.onap.portal.bff.exceptions.DownstreamApiProblemException; @@ -58,13 +59,13 @@ public class KeycloakService { log.debug("Create user in keycloak. request=`{}`", request); final List<RoleApiDto> rolesToBeAssigned = - Option.of(request.getRoles()).fold(List::empty, List::ofAll); + request.getRoles().isEmpty() ? Collections.emptyList() : request.getRoles(); return listRoles(xRequestId) .collectList() .flatMap( realmRoles -> { final List<RoleApiDto> absentRoles = - rolesToBeAssigned.filter(role -> !realmRoles.contains(role)); + rolesToBeAssigned.stream().filter(role -> !realmRoles.contains(role)).toList(); if (!absentRoles.isEmpty()) { return Mono.error( DownstreamApiProblemException.builder() @@ -72,41 +73,27 @@ public class KeycloakService { .detail( String.format( "Roles not found in the realm: %s", - absentRoles.map(RoleApiDto::getName).asJava())) + absentRoles.stream().map(RoleApiDto::getName).toList())) .downstreamSystem(ProblemApiDto.DownstreamSystemEnum.KEYCLOAK.toString()) .title(HttpStatus.NOT_FOUND.toString()) .build()); } return Mono.just(rolesToBeAssigned); }) - .flatMap(roles -> createUserWithRoles(request, xRequestId, List.ofAll(roles))); + .flatMap(roles -> createUserWithRoles(request, xRequestId, roles)); } private Mono<UserResponseApiDto> createUserWithRoles( CreateUserRequestApiDto request, String xRequestId, List<RoleApiDto> roles) { return keycloakApi .createUserWithHttpInfo( - usersMapper.convert( - request, List.of(RequiredActionsKeycloakDto.UPDATE_PASSWORD).asJava())) + usersMapper.convert(request, List.of(RequiredActionsKeycloakDto.UPDATE_PASSWORD))) + .map(responseEntit -> responseEntit.getHeaders().getLocation()) + .map(URI::toString) + .map(location -> location.substring(location.lastIndexOf("/") + 1)) + .flatMap(userId -> !roles.isEmpty() ? assignRoles(userId, roles) : Mono.just(userId)) .flatMap( - responseEntity -> - Option.of(responseEntity.getHeaders().getLocation()) - .map(URI::toString) - .map(location -> location.substring(location.lastIndexOf("/") + 1)) - .fold( - () -> Mono.error(DownstreamApiProblemException.builder().build()), - Mono::just)) - .flatMap( - userId -> { - if (!roles.isEmpty()) { - return assignRoles(userId, roles); - } - return Mono.just(userId); - }) - .flatMap( - userId -> - sendActionEmail( - userId, API.List(RequiredActionsKeycloakDto.UPDATE_PASSWORD).toJavaList())) + userId -> sendActionEmail(userId, List.of(RequiredActionsKeycloakDto.UPDATE_PASSWORD))) .onErrorResume( DownstreamApiProblemException.class, ex -> { @@ -167,20 +154,24 @@ public class KeycloakService { listUsersByRole(role.getName(), xRequestId) .map(user -> Tuple.of(user.getId(), role.getName()))) .collectList() - .map(List::ofAll) + .map(io.vavr.collection.List::ofAll) .map(list -> list.groupBy(t -> t._1).map((k, v) -> Tuple.of(k, v.map(Tuple2::_2))))) .map( tuple -> { final UserListResponseApiDto result = new UserListResponseApiDto(); result.setTotalCount(tuple.getT1()); result.setItems( - List.ofAll(tuple.getT2()) + io.vavr.collection.List.ofAll(tuple.getT2()) .map( user -> usersMapper.convert( user, tuple.getT3().getOrElse(user.getId(), API.List()).toJavaList())) .toJavaList()); + // result.setItems( + // tuple.getT2().stream() + // .map(user -> usersMapper.convert(user,tuple.getT3())) + // .toList()); return result; }) @@ -242,10 +233,10 @@ public class KeycloakService { log.debug( "Assign roles to user in keycloak. userId=`{}`, roleIds=`{}`", userId, - roles.map(RoleApiDto::getId).mkString(", ")); + roles.stream().map(RoleApiDto::getId).collect(Collectors.joining(", "))); return keycloakApi - .addRealmRoleMappingsToUser(userId, roles.map(rolesMapper::convert).toJavaList()) + .addRealmRoleMappingsToUser(userId, roles.stream().map(rolesMapper::convert).toList()) .thenReturn(userId); } @@ -254,10 +245,10 @@ public class KeycloakService { log.debug( "Update assigned roles for user in keycloak. userId=`{}`, roleIds=`{}`", userId, - roles.map(RoleApiDto::getId).mkString(", ")); + roles.stream().map(RoleApiDto::getId).collect(Collectors.joining(", "))); return getAssignedRoles(userId, xRequestId) - .map(response -> List.ofAll(response.getItems())) + .map(response -> response.getItems()) .flatMap( assignedRoles -> { if (assignedRoles.isEmpty()) { @@ -290,10 +281,10 @@ public class KeycloakService { log.debug( "Unassign roles from user in keycloak. userId=`{}`, roleIds=`{}`", userId, - roles.map(RoleApiDto::getId).mkString(", ")); + roles.stream().map(RoleApiDto::getId).collect(Collectors.joining(", "))); return keycloakApi.deleteRealmRoleMappingsByUserId( - userId, roles.map(rolesMapper::convert).toJavaList()); + userId, roles.stream().map(rolesMapper::convert).toList()); } public Mono<String> sendActionEmail( @@ -310,7 +301,6 @@ public class KeycloakService { public Flux<RoleApiDto> listRoles(String xRequestId) { return keycloakApi .getRoles(null, null, null, null) - .log() .map(role -> conversionService.convert(role, RoleApiDto.class)) .onErrorResume( DownstreamApiProblemException.class, diff --git a/lib/src/main/java/org/onap/portal/bff/utils/SortingChainResolver.java b/lib/src/main/java/org/onap/portal/bff/utils/SortingChainResolver.java deleted file mode 100644 index d162637..0000000 --- a/lib/src/main/java/org/onap/portal/bff/utils/SortingChainResolver.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * - * Copyright (c) 2022. Deutsche Telekom AG - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * - * - */ - -package org.onap.portal.bff.utils; - -import io.vavr.collection.Map; -import io.vavr.collection.Seq; -import io.vavr.control.Option; -import java.util.Comparator; - -public class SortingChainResolver<T> { - final Map<String, Comparator<T>> comparators; - - public SortingChainResolver(Map<String, Comparator<T>> comparators) { - this.comparators = comparators; - } - - public Option<Comparator<T>> resolve(Seq<SortingParser.SortingParam> sortingParams) { - final Seq<Comparator<T>> resolvedComparators = - sortingParams.flatMap( - sortingParam -> - comparators - .get(sortingParam.getName()) - .map( - comparator -> { - if (sortingParam.isDescending()) { - return comparator.reversed(); - } - return comparator; - })); - - if (resolvedComparators.isEmpty()) { - return Option.none(); - } - return Option.some(resolvedComparators.reduceLeft(Comparator::thenComparing)); - } -} diff --git a/lib/src/main/java/org/onap/portal/bff/utils/SortingParser.java b/lib/src/main/java/org/onap/portal/bff/utils/SortingParser.java deleted file mode 100644 index d08f775..0000000 --- a/lib/src/main/java/org/onap/portal/bff/utils/SortingParser.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * - * Copyright (c) 2022. Deutsche Telekom AG - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * - * - */ - -package org.onap.portal.bff.utils; - -import io.vavr.collection.List; -import io.vavr.collection.Seq; -import lombok.Builder; -import lombok.NonNull; -import lombok.Value; - -public class SortingParser { - private static final String DESC_PREFIX = "-"; - private static final String SEPARATOR = ","; - - private SortingParser() {} - - public static Seq<SortingParam> parse(String sort) { - return List.of(sort.split(SEPARATOR)) - .filter(name -> !name.isEmpty() && !name.equals(DESC_PREFIX)) - .map( - name -> { - if (name.startsWith(DESC_PREFIX)) { - return SortingParam.builder() - .name(name.substring(DESC_PREFIX.length())) - .isDescending(true) - .build(); - } - return SortingParam.builder().name(name).isDescending(false).build(); - }); - } - - @Builder - @Value - public static class SortingParam { - @NonNull String name; - boolean isDescending; - } -} diff --git a/lib/src/main/java/org/onap/portal/bff/utils/VersionComparator.java b/lib/src/main/java/org/onap/portal/bff/utils/VersionComparator.java deleted file mode 100644 index cb8ecf1..0000000 --- a/lib/src/main/java/org/onap/portal/bff/utils/VersionComparator.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * - * Copyright (c) 2022. Deutsche Telekom AG - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * - * - */ - -package org.onap.portal.bff.utils; - -import java.util.Comparator; -import java.util.regex.Pattern; - -public class VersionComparator implements Comparator<String> { - private static final Pattern SEPARATOR_PATTERN = Pattern.compile("\\."); - - @Override - public int compare(String version1, String version2) { - final String[] parsedVersion1 = SEPARATOR_PATTERN.split(version1); - final String[] parsedVersion2 = SEPARATOR_PATTERN.split(version2); - final int maxLength = Math.max(parsedVersion1.length, parsedVersion2.length); - - for (int i = 0; i < maxLength; i++) { - final Integer v1 = i < parsedVersion1.length ? Integer.parseInt(parsedVersion1[i]) : 0; - final Integer v2 = i < parsedVersion2.length ? Integer.parseInt(parsedVersion2[i]) : 0; - final int compare = v1.compareTo(v2); - - if (compare != 0) { - return compare; - } - } - - return 0; - } -} |