Skip to content

Commit 812dbe8

Browse files
518 paging and sorting report (#537)
* Generate Report for classes extends PagingAndSortingRepository interface * Fixes merge conflicts and passes all tests * Removing hardcoded paths in tests
1 parent b008431 commit 812dbe8

File tree

4 files changed

+468
-1
lines changed

4 files changed

+468
-1
lines changed

components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/CrudRepositoryExtension.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818

1919
import lombok.Setter;
20-
import lombok.Value;
2120
import org.jetbrains.annotations.NotNull;
2221
import org.openrewrite.ExecutionContext;
2322
import org.openrewrite.Recipe;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright 2021 - 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.sbm.boot.upgrade_27_30.report.helper;
18+
19+
import org.jetbrains.annotations.NotNull;
20+
import org.openrewrite.ExecutionContext;
21+
import org.openrewrite.java.JavaIsoVisitor;
22+
import org.openrewrite.java.tree.J;
23+
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
24+
import org.springframework.sbm.engine.context.ProjectContext;
25+
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
26+
import org.springframework.sbm.support.openrewrite.GenericOpenRewriteRecipe;
27+
28+
import java.util.HashMap;
29+
import java.util.List;
30+
import java.util.Map;
31+
import java.util.stream.Collectors;
32+
33+
public class PagingAndSortingHelper implements SpringBootUpgradeReportSection.Helper<List<String>> {
34+
private List<String> pagingAndSortingRepo;
35+
private List<String> reactivePagingAndSortingRepo;
36+
private List<String> rxJavaSortingRepo;
37+
38+
@Override
39+
public String getDescription() {
40+
return null;
41+
}
42+
43+
@Override
44+
public boolean evaluate(ProjectContext context) {
45+
//CrudRepositoryExtension
46+
List<RewriteSourceFileHolder<J.CompilationUnit>> pagingAndSortingFileHolders =
47+
context.getProjectJavaSources().find(pagingAndSortingFinders("org.springframework.data.repository.PagingAndSortingRepository"));
48+
List<RewriteSourceFileHolder<J.CompilationUnit>> reactiveSortingFileHolders =
49+
context.getProjectJavaSources().find(pagingAndSortingFinders("org.springframework.data.repository.reactive.ReactiveSortingRepository"));
50+
List<RewriteSourceFileHolder<J.CompilationUnit>> rxJavaSortingFileHolders =
51+
context.getProjectJavaSources().find(pagingAndSortingFinders("org.springframework.data.repository.reactive.RxJava3SortingRepository"));
52+
53+
pagingAndSortingRepo = pagingAndSortingFileHolders
54+
.stream()
55+
.map(k -> k.getAbsolutePath().toString()).toList();
56+
57+
reactivePagingAndSortingRepo = reactiveSortingFileHolders.stream()
58+
.map(k -> k.getAbsolutePath().toString()).collect(Collectors.toList());
59+
60+
rxJavaSortingRepo = rxJavaSortingFileHolders.stream()
61+
.map(k -> k.getAbsolutePath().toString()).collect(Collectors.toList());
62+
63+
return !pagingAndSortingFileHolders.isEmpty()
64+
|| !reactiveSortingFileHolders.isEmpty()
65+
|| !rxJavaSortingFileHolders.isEmpty();
66+
}
67+
68+
@NotNull
69+
private GenericOpenRewriteRecipe<JavaIsoVisitor<ExecutionContext>> pagingAndSortingFinders(String clazz) {
70+
return new GenericOpenRewriteRecipe<>(() -> new JavaIsoVisitor<>() {
71+
@Override
72+
@NotNull
73+
public J.ClassDeclaration visitClassDeclaration(@NotNull J.ClassDeclaration classDecl, @NotNull ExecutionContext executionContext) {
74+
return doesItExtendPagingAndSorting(classDecl) ? applyThisRecipe(classDecl) : ceaseVisit(classDecl);
75+
}
76+
77+
private boolean doesItExtendPagingAndSorting(J.ClassDeclaration classDecl) {
78+
if (classDecl.getImplements() == null) {
79+
return false;
80+
}
81+
return classDecl.getType().getInterfaces().stream()
82+
.anyMatch(impl -> impl.getFullyQualifiedName().equals(clazz));
83+
}
84+
85+
private J.ClassDeclaration ceaseVisit(J.ClassDeclaration classDecl) {
86+
return classDecl;
87+
}
88+
89+
@NotNull
90+
private J.ClassDeclaration applyThisRecipe(J.ClassDeclaration classDecl) {
91+
return classDecl.withMarkers(classDecl.getMarkers().searchResult());
92+
}
93+
});
94+
}
95+
96+
@Override
97+
public Map<String, List<String>> getData() {
98+
Map<String, List<String>> map = new HashMap<>();
99+
map.put("pagingAndSortingRepos", pagingAndSortingRepo);
100+
map.put("reactivePagingAndSortingRepos", reactivePagingAndSortingRepo);
101+
map.put("rxJavaSortingRepos", rxJavaSortingRepo);
102+
103+
return map;
104+
}
105+
}

components/sbm-recipes-boot-upgrade/src/main/resources/recipes/boot-new-report.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,49 @@
265265
contributors:
266266
- Fabian Krüger[@fabapp2]
267267

268+
- title: Paging and sorting repository
269+
helper: org.springframework.sbm.boot.upgrade_27_30.report.helper.PagingAndSortingHelper
270+
change: |-
271+
Sorting repositories no longer extend their respective CRUD repository.
272+
273+
The affected interfaces are:
274+
275+
* `PagingAndSortingRepository` no longer extends `CrudRepository`
276+
* `ReactiveSortingRepository` no longer extends `ReactiveCrudRepository`
277+
* `RxJavaSortingRepository` no longer extends `RxJavaCrudRepository`
278+
sources:
279+
- 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
280+
affected: |-
281+
<#if pagingAndSortingRepos?size != 0>
282+
We found classes which uses `PagingAndSortingRepository` in following files:
283+
284+
<#list pagingAndSortingRepos as file>
285+
* ${file}
286+
</#list>
287+
288+
</#if>
289+
<#if reactivePagingAndSortingRepos?size != 0>
290+
We found classes which uses `ReactiveSortingRepository` in following files:
291+
292+
<#list reactivePagingAndSortingRepos as file>
293+
* ${file}
294+
</#list>
295+
296+
</#if>
297+
<#if rxJavaSortingRepos?size != 0>
298+
We found classes which uses `RxJavaSortingRepository` in following files:
299+
300+
<#list rxJavaSortingRepos as file>
301+
* ${file}
302+
</#list>
303+
304+
</#if>
305+
remediation:
306+
description: |-
307+
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.
308+
gitHubIssue: 518
309+
contributors:
310+
- "Sandeep Nagaraj[@sanagaraj-pivotal]"
268311

269312
footer: |-
270313
We want to say thank you to all Contributors:

0 commit comments

Comments
 (0)