From e8515c5c16edec6595b05291651e9ee1fc096aac Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Fri, 9 Feb 2024 18:40:28 +0000 Subject: [PATCH] feat : sonar fixes --- graphql/boot-graphql-querydsl/pom.xml | 2 +- graphql/boot-graphql-webflux/pom.xml | 2 +- .../graphql/mapper/NewPostRequestToPostEntityMapper.java | 9 +++++++++ .../envers/config/DatasourceProxyBeanPostProcessor.java | 4 ++-- .../keysetpagination/services/EntitySpecification.java | 3 +-- .../locks/config/DatasourceProxyBeanPostProcessor.java | 4 ++-- .../src/main/java/com/example/locks/entities/Movie.java | 4 ++-- .../example/locks/entities/{Review.java => Reviews.java} | 2 +- .../java/com/example/locks/mapper/JpaLocksMapper.java | 7 +++---- .../com/example/locks/repositories/ReviewRepository.java | 6 ------ .../example/locks/repositories/ReviewsRepository.java | 6 ++++++ .../java/com/example/locks/entities/ActorEntityTest.java | 4 ++-- .../example/locks/web/controllers/MovieControllerIT.java | 4 ++-- 13 files changed, 32 insertions(+), 25 deletions(-) rename jpa/boot-jpa-locks/src/main/java/com/example/locks/entities/{Review.java => Reviews.java} (95%) delete mode 100644 jpa/boot-jpa-locks/src/main/java/com/example/locks/repositories/ReviewRepository.java create mode 100644 jpa/boot-jpa-locks/src/main/java/com/example/locks/repositories/ReviewsRepository.java diff --git a/graphql/boot-graphql-querydsl/pom.xml b/graphql/boot-graphql-querydsl/pom.xml index 1ed7311b1..7aca6f8cc 100644 --- a/graphql/boot-graphql-querydsl/pom.xml +++ b/graphql/boot-graphql-querydsl/pom.xml @@ -316,7 +316,7 @@ - 2.38.0 + 2.39.0 diff --git a/graphql/boot-graphql-webflux/pom.xml b/graphql/boot-graphql-webflux/pom.xml index 5da4a3ee2..794c3df70 100644 --- a/graphql/boot-graphql-webflux/pom.xml +++ b/graphql/boot-graphql-webflux/pom.xml @@ -227,7 +227,7 @@ - 2.38.0 + 2.39.0 diff --git a/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/mapper/NewPostRequestToPostEntityMapper.java b/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/mapper/NewPostRequestToPostEntityMapper.java index dfc990ef9..77cad3ccb 100644 --- a/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/mapper/NewPostRequestToPostEntityMapper.java +++ b/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/mapper/NewPostRequestToPostEntityMapper.java @@ -61,6 +61,15 @@ default void afterMapping( .contains(tagEntity.getTagName())) .toList(); + for (TagEntity tagEntity : tagEntitiesToUpdate) { + for (TagsRequest tagsRequest : newPostRequest.tags()) { + if (tagEntity.getTagName().equalsIgnoreCase(tagsRequest.tagName())) { + tagEntity.setTagDescription(tagsRequest.tagDescription()); + break; + } + } + } + List tagEntitiesToInsert = newPostRequest.tags().stream() .filter( diff --git a/jpa/boot-data-envers/src/main/java/com/example/envers/config/DatasourceProxyBeanPostProcessor.java b/jpa/boot-data-envers/src/main/java/com/example/envers/config/DatasourceProxyBeanPostProcessor.java index c72a1e861..818b33ee7 100644 --- a/jpa/boot-data-envers/src/main/java/com/example/envers/config/DatasourceProxyBeanPostProcessor.java +++ b/jpa/boot-data-envers/src/main/java/com/example/envers/config/DatasourceProxyBeanPostProcessor.java @@ -23,11 +23,11 @@ public class DatasourceProxyBeanPostProcessor implements BeanPostProcessor { @Override public Object postProcessAfterInitialization(@NonNull Object bean, @NonNull String beanName) { - if (bean instanceof DataSource && !(bean instanceof ProxyDataSource)) { + if (bean instanceof DataSource dataSource && !(bean instanceof ProxyDataSource)) { final ProxyFactory factory = new ProxyFactory(bean); factory.setProxyTargetClass(true); - factory.addAdvice(new ProxyDataSourceInterceptor((DataSource) bean)); + factory.addAdvice(new ProxyDataSourceInterceptor(dataSource)); return factory.getProxy(); } return bean; diff --git a/jpa/boot-data-keyset-pagination/src/main/java/com/example/keysetpagination/services/EntitySpecification.java b/jpa/boot-data-keyset-pagination/src/main/java/com/example/keysetpagination/services/EntitySpecification.java index a3c414964..c6bdec3f9 100644 --- a/jpa/boot-data-keyset-pagination/src/main/java/com/example/keysetpagination/services/EntitySpecification.java +++ b/jpa/boot-data-keyset-pagination/src/main/java/com/example/keysetpagination/services/EntitySpecification.java @@ -15,7 +15,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Component; @@ -29,7 +28,7 @@ public Specification specificationBuilder(SearchCriteria[] searchCriteria) { Stream.of(searchCriteria) .filter(Objects::nonNull) .map(this::createSpecification) - .collect(Collectors.toList()); + .toList(); return Specification.allOf(specifications); } diff --git a/jpa/boot-jpa-locks/src/main/java/com/example/locks/config/DatasourceProxyBeanPostProcessor.java b/jpa/boot-jpa-locks/src/main/java/com/example/locks/config/DatasourceProxyBeanPostProcessor.java index 9aba1f54b..32ad72681 100644 --- a/jpa/boot-jpa-locks/src/main/java/com/example/locks/config/DatasourceProxyBeanPostProcessor.java +++ b/jpa/boot-jpa-locks/src/main/java/com/example/locks/config/DatasourceProxyBeanPostProcessor.java @@ -23,11 +23,11 @@ public class DatasourceProxyBeanPostProcessor implements BeanPostProcessor { @Override public Object postProcessAfterInitialization(@NonNull Object bean, @NonNull String beanName) { - if (bean instanceof DataSource && !(bean instanceof ProxyDataSource)) { + if (bean instanceof DataSource dataSource && !(bean instanceof ProxyDataSource)) { final ProxyFactory factory = new ProxyFactory(bean); factory.setProxyTargetClass(true); - factory.addAdvice(new ProxyDataSourceInterceptor((DataSource) bean)); + factory.addAdvice(new ProxyDataSourceInterceptor(dataSource)); return factory.getProxy(); } return bean; diff --git a/jpa/boot-jpa-locks/src/main/java/com/example/locks/entities/Movie.java b/jpa/boot-jpa-locks/src/main/java/com/example/locks/entities/Movie.java index 64172beb2..fb1df7fa6 100644 --- a/jpa/boot-jpa-locks/src/main/java/com/example/locks/entities/Movie.java +++ b/jpa/boot-jpa-locks/src/main/java/com/example/locks/entities/Movie.java @@ -28,7 +28,7 @@ public class Movie { private BigDecimal budget; @OneToMany(mappedBy = "movie", cascade = CascadeType.ALL) - private List reviews; + private List reviews; @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "director_id") @@ -66,7 +66,7 @@ public Movie setBudget(BigDecimal budget) { return this; } - public Movie setReviews(List reviews) { + public Movie setReviews(List reviews) { this.reviews = reviews; return this; } diff --git a/jpa/boot-jpa-locks/src/main/java/com/example/locks/entities/Review.java b/jpa/boot-jpa-locks/src/main/java/com/example/locks/entities/Reviews.java similarity index 95% rename from jpa/boot-jpa-locks/src/main/java/com/example/locks/entities/Review.java rename to jpa/boot-jpa-locks/src/main/java/com/example/locks/entities/Reviews.java index 1fbcc7831..74aa5e56e 100644 --- a/jpa/boot-jpa-locks/src/main/java/com/example/locks/entities/Review.java +++ b/jpa/boot-jpa-locks/src/main/java/com/example/locks/entities/Reviews.java @@ -10,7 +10,7 @@ @Setter @NoArgsConstructor @Table(name = "reviews") -public class Review { +public class Reviews { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) diff --git a/jpa/boot-jpa-locks/src/main/java/com/example/locks/mapper/JpaLocksMapper.java b/jpa/boot-jpa-locks/src/main/java/com/example/locks/mapper/JpaLocksMapper.java index 337f827e3..161caef14 100644 --- a/jpa/boot-jpa-locks/src/main/java/com/example/locks/mapper/JpaLocksMapper.java +++ b/jpa/boot-jpa-locks/src/main/java/com/example/locks/mapper/JpaLocksMapper.java @@ -3,13 +3,12 @@ import com.example.locks.entities.Actor; import com.example.locks.entities.Genre; import com.example.locks.entities.Movie; -import com.example.locks.entities.Review; +import com.example.locks.entities.Reviews; import com.example.locks.model.request.ActorRequest; import com.example.locks.model.request.MovieRequest; import com.example.locks.model.response.ActorResponse; import com.example.locks.model.response.MovieResponse; import java.util.List; -import java.util.stream.Collectors; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.MappingTarget; @@ -23,7 +22,7 @@ public interface JpaLocksMapper { default Movie movieRequestToMovieEntity(MovieRequest movieRequest) { var movie = movieRequestToMovie(movieRequest); for (Actor a : movie.getActors()) a.setMovies(List.of(movie)); - for (Review r : movie.getReviews()) r.setMovie(movie); + for (Reviews r : movie.getReviews()) r.setMovie(movie); for (Genre g : movie.getGenres()) g.setMovies(List.of(movie)); return movie; } @@ -33,7 +32,7 @@ default Movie movieRequestToMovieEntity(MovieRequest movieRequest) { MovieResponse movieToMovieResponse(Movie movie); default List moviesListToMovieResponseList(List moviesList) { - return moviesList.stream().map(this::movieToMovieResponse).collect(Collectors.toList()); + return moviesList.stream().map(this::movieToMovieResponse).toList(); } ActorResponse actorToActorResponse(Actor actor); diff --git a/jpa/boot-jpa-locks/src/main/java/com/example/locks/repositories/ReviewRepository.java b/jpa/boot-jpa-locks/src/main/java/com/example/locks/repositories/ReviewRepository.java deleted file mode 100644 index b70c7b71d..000000000 --- a/jpa/boot-jpa-locks/src/main/java/com/example/locks/repositories/ReviewRepository.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.example.locks.repositories; - -import com.example.locks.entities.Review; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface ReviewRepository extends JpaRepository {} diff --git a/jpa/boot-jpa-locks/src/main/java/com/example/locks/repositories/ReviewsRepository.java b/jpa/boot-jpa-locks/src/main/java/com/example/locks/repositories/ReviewsRepository.java new file mode 100644 index 000000000..5c6965ab5 --- /dev/null +++ b/jpa/boot-jpa-locks/src/main/java/com/example/locks/repositories/ReviewsRepository.java @@ -0,0 +1,6 @@ +package com.example.locks.repositories; + +import com.example.locks.entities.Reviews; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ReviewsRepository extends JpaRepository {} diff --git a/jpa/boot-jpa-locks/src/test/java/com/example/locks/entities/ActorEntityTest.java b/jpa/boot-jpa-locks/src/test/java/com/example/locks/entities/ActorEntityTest.java index ccdb25e11..94178de07 100644 --- a/jpa/boot-jpa-locks/src/test/java/com/example/locks/entities/ActorEntityTest.java +++ b/jpa/boot-jpa-locks/src/test/java/com/example/locks/entities/ActorEntityTest.java @@ -16,7 +16,7 @@ @DataJpaTest @Disabled -public class ActorEntityTest { +class ActorEntityTest { @Autowired private TestEntityManager entityManager; @@ -26,7 +26,7 @@ public class ActorEntityTest { @Test @Transactional - public void testPessimisticWriteLock() { + void testPessimisticWriteLock() { Actor entityToSave = new Actor(); entityToSave.setActorName("TestEntityName"); diff --git a/jpa/boot-jpa-locks/src/test/java/com/example/locks/web/controllers/MovieControllerIT.java b/jpa/boot-jpa-locks/src/test/java/com/example/locks/web/controllers/MovieControllerIT.java index beb352784..198e5ab76 100644 --- a/jpa/boot-jpa-locks/src/test/java/com/example/locks/web/controllers/MovieControllerIT.java +++ b/jpa/boot-jpa-locks/src/test/java/com/example/locks/web/controllers/MovieControllerIT.java @@ -22,7 +22,7 @@ import com.example.locks.model.request.MovieRequest; import com.example.locks.model.request.ReviewRequest; import com.example.locks.repositories.MovieRepository; -import com.example.locks.repositories.ReviewRepository; +import com.example.locks.repositories.ReviewsRepository; import java.math.BigDecimal; import java.time.LocalDate; import java.util.ArrayList; @@ -39,7 +39,7 @@ class MovieControllerIT extends AbstractIntegrationTest { private MovieRepository movieRepository; @Autowired - private ReviewRepository reviewRepository; + private ReviewsRepository reviewRepository; private List movieList = null;