From e4b1726238b393de7c17b35c34a2f5811bb81993 Mon Sep 17 00:00:00 2001 From: Angular2guy Date: Fri, 29 Nov 2024 00:20:44 +0100 Subject: [PATCH] feat: improve streams --- .../moviemanager/adapter/repository/ActorRepositoryBean.java | 2 +- .../xxx/moviemanager/usecase/service/DataMigrationService.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/ch/xxx/moviemanager/adapter/repository/ActorRepositoryBean.java b/backend/src/main/java/ch/xxx/moviemanager/adapter/repository/ActorRepositoryBean.java index ade4e8d..a9f5c1f 100644 --- a/backend/src/main/java/ch/xxx/moviemanager/adapter/repository/ActorRepositoryBean.java +++ b/backend/src/main/java/ch/xxx/moviemanager/adapter/repository/ActorRepositoryBean.java @@ -95,7 +95,7 @@ public List findByFilterCriteria(ActorFilterCriteriaDto filterCriteriaDto cActor.get("birthday"), CommonUtils.convert(filterCriteriaDto.getBirthdayTo())))); Optional.ofNullable(filterCriteriaDto.getDead()).ifPresent( x -> predicates.add(this.entityManager.getCriteriaBuilder().isNotNull(cActor.get("deathday")))); - Optional.ofNullable(filterCriteriaDto.getGender()).stream().filter(myGender -> !Gender.Unknown.equals(myGender)) + Optional.ofNullable(filterCriteriaDto.getGender()).stream().filter(java.util.function.Predicate.not(Gender.Unknown::equals)) .findFirst().ifPresent(x -> predicates.add(this.entityManager.getCriteriaBuilder() .equal(cActor.get("gender"), filterCriteriaDto.getGender().getCode()))); Optional.ofNullable(filterCriteriaDto.getName()).stream().filter(myName -> myName.trim().length() > 2) diff --git a/backend/src/main/java/ch/xxx/moviemanager/usecase/service/DataMigrationService.java b/backend/src/main/java/ch/xxx/moviemanager/usecase/service/DataMigrationService.java index d64ac88..a1ae8b8 100644 --- a/backend/src/main/java/ch/xxx/moviemanager/usecase/service/DataMigrationService.java +++ b/backend/src/main/java/ch/xxx/moviemanager/usecase/service/DataMigrationService.java @@ -16,6 +16,7 @@ import java.util.Optional; import java.util.UUID; import java.util.concurrent.CompletableFuture; +import java.util.function.Predicate; import java.util.stream.Collectors; import org.springframework.scheduling.annotation.Async; @@ -40,7 +41,7 @@ public DataMigrationService(UserRepository userRepository, UserDetailService use @Async public CompletableFuture encryptUserKeys() { List migratedUsers = this.userRepository.findOpenMigrations(1L).stream().map(myUser -> { - myUser.setUuid(Optional.ofNullable(myUser.getUuid()).filter(myStr -> !myStr.isBlank()).orElse(UUID.randomUUID().toString())); + myUser.setUuid(Optional.ofNullable(myUser.getUuid()).filter(Predicate.not(String::isBlank)).orElse(UUID.randomUUID().toString())); myUser.setMoviedbkey(this.userDetailService.encrypt(myUser.getMoviedbkey(), myUser.getUuid())); myUser.setMigration(myUser.getMigration() + 1); return myUser;