Skip to content

Move paging and sorting report to new Boot Upgrade Report #537

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

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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@


import lombok.Setter;
import lombok.Value;
import org.jetbrains.annotations.NotNull;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Recipe;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Copyright 2021 - 2022 the original author or authors.
*
* 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
*
* https://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.
*/

package org.springframework.sbm.boot.upgrade_27_30.report.helper;

import org.jetbrains.annotations.NotNull;
import org.openrewrite.ExecutionContext;
import org.openrewrite.java.JavaIsoVisitor;
import org.openrewrite.java.tree.J;
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
import org.springframework.sbm.support.openrewrite.GenericOpenRewriteRecipe;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class PagingAndSortingHelper implements SpringBootUpgradeReportSection.Helper<List<String>> {
private List<String> pagingAndSortingRepo;
private List<String> reactivePagingAndSortingRepo;
private List<String> rxJavaSortingRepo;

@Override
public String getDescription() {
return null;
}

@Override
public boolean evaluate(ProjectContext context) {
//CrudRepositoryExtension
List<RewriteSourceFileHolder<J.CompilationUnit>> pagingAndSortingFileHolders =
context.getProjectJavaSources().find(pagingAndSortingFinders("org.springframework.data.repository.PagingAndSortingRepository"));
List<RewriteSourceFileHolder<J.CompilationUnit>> reactiveSortingFileHolders =
context.getProjectJavaSources().find(pagingAndSortingFinders("org.springframework.data.repository.reactive.ReactiveSortingRepository"));
List<RewriteSourceFileHolder<J.CompilationUnit>> rxJavaSortingFileHolders =
context.getProjectJavaSources().find(pagingAndSortingFinders("org.springframework.data.repository.reactive.RxJava3SortingRepository"));

pagingAndSortingRepo = pagingAndSortingFileHolders
.stream()
.map(k -> k.getAbsolutePath().toString()).toList();

reactivePagingAndSortingRepo = reactiveSortingFileHolders.stream()
.map(k -> k.getAbsolutePath().toString()).collect(Collectors.toList());

rxJavaSortingRepo = rxJavaSortingFileHolders.stream()
.map(k -> k.getAbsolutePath().toString()).collect(Collectors.toList());

return !pagingAndSortingFileHolders.isEmpty()
|| !reactiveSortingFileHolders.isEmpty()
|| !rxJavaSortingFileHolders.isEmpty();
}

@NotNull
private GenericOpenRewriteRecipe<JavaIsoVisitor<ExecutionContext>> pagingAndSortingFinders(String clazz) {
return new GenericOpenRewriteRecipe<>(() -> new JavaIsoVisitor<>() {
@Override
@NotNull
public J.ClassDeclaration visitClassDeclaration(@NotNull J.ClassDeclaration classDecl, @NotNull ExecutionContext executionContext) {
return doesItExtendPagingAndSorting(classDecl) ? applyThisRecipe(classDecl) : ceaseVisit(classDecl);
}

private boolean doesItExtendPagingAndSorting(J.ClassDeclaration classDecl) {
if (classDecl.getImplements() == null) {
return false;
}
return classDecl.getType().getInterfaces().stream()
.anyMatch(impl -> impl.getFullyQualifiedName().equals(clazz));
}

private J.ClassDeclaration ceaseVisit(J.ClassDeclaration classDecl) {
return classDecl;
}

@NotNull
private J.ClassDeclaration applyThisRecipe(J.ClassDeclaration classDecl) {
return classDecl.withMarkers(classDecl.getMarkers().searchResult());
}
});
}

@Override
public Map<String, List<String>> getData() {
Map<String, List<String>> map = new HashMap<>();
map.put("pagingAndSortingRepos", pagingAndSortingRepo);
map.put("reactivePagingAndSortingRepos", reactivePagingAndSortingRepo);
map.put("rxJavaSortingRepos", rxJavaSortingRepo);

return map;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,49 @@
contributors:
- Fabian Krüger[@fabapp2]

- title: Paging and sorting repository
helper: org.springframework.sbm.boot.upgrade_27_30.report.helper.PagingAndSortingHelper
change: |-
Sorting repositories no longer extend their respective CRUD repository.

The affected interfaces are:

* `PagingAndSortingRepository` no longer extends `CrudRepository`
* `ReactiveSortingRepository` no longer extends `ReactiveCrudRepository`
* `RxJavaSortingRepository` no longer extends `RxJavaCrudRepository`
sources:
- https://github.com/spring-projects/spring-data-commons/wiki/Spring-Data-2022.0-%28Turing%29-Release-Notes#sorting-repositories-no-longer-inherit-from-crud-repositories
affected: |-
<#if pagingAndSortingRepos?size != 0>
We found classes which uses `PagingAndSortingRepository` in following files:

<#list pagingAndSortingRepos as file>
* ${file}
</#list>

</#if>
<#if reactivePagingAndSortingRepos?size != 0>
We found classes which uses `ReactiveSortingRepository` in following files:

<#list reactivePagingAndSortingRepos as file>
* ${file}
</#list>

</#if>
<#if rxJavaSortingRepos?size != 0>
We found classes which uses `RxJavaSortingRepository` in following files:

<#list rxJavaSortingRepos as file>
* ${file}
</#list>

</#if>
remediation:
description: |-
If one requires the old behavior one must extend not only the sorting repository, but also the respective CRUD repository explicitly. This was done so the sorting support could easily be combined with the List repositories introduced above.
gitHubIssue: 518
contributors:
- "Sandeep Nagaraj[@sanagaraj-pivotal]"

footer: |-
We want to say thank you to all Contributors:
Expand Down
Loading