From: Eric Giffon Date: Mon, 3 Jul 2023 13:41:13 +0000 (+0200) Subject: SONAR-19728 Remove needIssueSync flag from api/components/search_projects X-Git-Tag: 10.2.0.77647~358 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=94a4bcb075f6a86b5bf42fccc9e6841bd0f43ee4;p=sonarqube.git SONAR-19728 Remove needIssueSync flag from api/components/search_projects --- diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/SearchProjectsActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/SearchProjectsActionIT.java index 16d0c715ee7..bf5ae518aba 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/SearchProjectsActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/SearchProjectsActionIT.java @@ -56,7 +56,6 @@ import org.sonar.db.property.PropertyDto; import org.sonar.server.component.ws.SearchProjectsAction.RequestBuilder; import org.sonar.server.component.ws.SearchProjectsAction.SearchProjectsRequest; import org.sonar.server.es.EsTester; -import org.sonar.server.issue.index.IssueIndexSyncProgressChecker; import org.sonar.server.measure.index.ProjectMeasuresIndex; import org.sonar.server.measure.index.ProjectMeasuresIndexer; import org.sonar.server.permission.index.PermissionIndexerTester; @@ -167,8 +166,7 @@ public class SearchProjectsActionIT { private ProjectMeasuresIndex index = new ProjectMeasuresIndex(es.client(), new WebAuthorizationTypeSupport(userSession), System2.INSTANCE); private ProjectMeasuresIndexer projectMeasuresIndexer = new ProjectMeasuresIndexer(db.getDbClient(), es.client()); - private WsActionTester ws = new WsActionTester(new SearchProjectsAction(dbClient, index, userSession, editionProviderMock, - new IssueIndexSyncProgressChecker(db.getDbClient()))); + private WsActionTester ws = new WsActionTester(new SearchProjectsAction(dbClient, index, userSession, editionProviderMock)); private RequestBuilder request = SearchProjectsRequest.builder(); @@ -182,7 +180,7 @@ public class SearchProjectsActionIT { assertThat(def.isPost()).isFalse(); assertThat(def.responseExampleAsString()).isNotEmpty(); assertThat(def.params().stream().map(Param::key).toList()).containsOnly("filter", "facets", "s", "asc", "ps", "p", "f"); - assertThat(def.changelog()).hasSize(2); + assertThat(def.changelog()).hasSize(3); Param sort = def.param("s"); assertThat(sort.defaultValue()).isEqualTo("name"); @@ -233,8 +231,6 @@ public class SearchProjectsActionIT { p -> p.setTagsString("finance, java"), new Measure(coverage, c -> c.setValue(80d))); - db.components().insertProjectBranch(db.components().getProjectDtoByMainBranch(project1), branchDto -> branchDto.setNeedIssueSync(true)); - ComponentDto project2 = insertProject( c -> c.setKey(KEY_PROJECT_EXAMPLE_002).setName("My Project 2"), new Measure(coverage, c -> c.setValue(90d))); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java index d3ea6366c0f..f031289552d 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java @@ -60,7 +60,6 @@ import org.sonar.server.component.ws.SearchProjectsAction.SearchResults.SearchRe import org.sonar.server.es.Facets; import org.sonar.server.es.SearchIdResult; import org.sonar.server.es.SearchOptions; -import org.sonar.server.issue.index.IssueIndexSyncProgressChecker; import org.sonar.server.measure.index.ProjectMeasuresIndex; import org.sonar.server.measure.index.ProjectMeasuresQuery; import org.sonar.server.project.Visibility; @@ -108,15 +107,13 @@ public class SearchProjectsAction implements ComponentsWsAction { private final ProjectMeasuresIndex index; private final UserSession userSession; private final PlatformEditionProvider editionProvider; - private final IssueIndexSyncProgressChecker issueIndexSyncProgressChecker; public SearchProjectsAction(DbClient dbClient, ProjectMeasuresIndex index, UserSession userSession, - PlatformEditionProvider editionProvider, IssueIndexSyncProgressChecker issueIndexSyncProgressChecker) { + PlatformEditionProvider editionProvider) { this.dbClient = dbClient; this.index = index; this.userSession = userSession; this.editionProvider = editionProvider; - this.issueIndexSyncProgressChecker = issueIndexSyncProgressChecker; } @Override @@ -127,8 +124,9 @@ public class SearchProjectsAction implements ComponentsWsAction { .addPagingParams(DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE) .setInternal(true) .setChangelog( + new Change("10.2", "Field 'needIssueSync' removed from response"), new Change("8.3", "Add 'qualifier' filter and facet"), - new Change("8.0", "Field 'id' from response has been removed")) + new Change("8.0", "Field 'id' removed from response")) .setResponseExample(getClass().getResource("search_projects-example.json")) .setHandler(this); @@ -219,8 +217,7 @@ public class SearchProjectsAction implements ComponentsWsAction { private SearchProjectsWsResponse doHandle(SearchProjectsRequest request) { try (DbSession dbSession = dbClient.openSession(false)) { SearchResults searchResults = searchData(dbSession, request); - boolean needIssueSync = dbClient.branchDao().hasAnyBranchWhereNeedIssueSync(dbSession, true); - return buildResponse(request, searchResults, needIssueSync); + return buildResponse(request, searchResults); } } @@ -255,23 +252,16 @@ public class SearchProjectsAction implements ComponentsWsAction { .stream() .collect(Collectors.toMap(e -> mainBranchByUuid.get(e.getKey()).getProjectUuid(), Entry::getValue)); - List projectsInsync = getProjectUuidsWithBranchesNeedIssueSync(dbSession, Sets.newHashSet(projectUuids)); - return SearchResultsBuilder.builder() .projects(projects) .favoriteProjectUuids(favoriteProjectUuids) .searchResults(esResults) .analysisByProjectUuid(analysisByProjectUuid) .applicationsLeakPeriods(applicationsLeakPeriod) - .projectsWithIssuesInSync(projectsInsync) .query(query) .build(); } - private List getProjectUuidsWithBranchesNeedIssueSync(DbSession dbSession, Set projectUuids) { - return issueIndexSyncProgressChecker.findProjectUuidsWithIssuesSyncNeed(dbSession, projectUuids); - } - private Set getQualifiersBasedOnEdition(ProjectMeasuresQuery query) { Set availableQualifiers = getQualifiersFromEdition(); Set requestQualifiers = query.getQualifiers().orElse(availableQualifiers); @@ -368,8 +358,8 @@ public class SearchProjectsAction implements ComponentsWsAction { return request.build(); } - private SearchProjectsWsResponse buildResponse(SearchProjectsRequest request, SearchResults searchResults, boolean needIssueSync) { - Function dbToWsComponent = new DbToWsComponent(request, searchResults, userSession.isLoggedIn(), needIssueSync); + private SearchProjectsWsResponse buildResponse(SearchProjectsRequest request, SearchResults searchResults) { + Function dbToWsComponent = new DbToWsComponent(request, searchResults, userSession.isLoggedIn()); return Stream.of(SearchProjectsWsResponse.newBuilder()) .map(response -> response.setPaging(Common.Paging.newBuilder() @@ -465,22 +455,17 @@ public class SearchProjectsAction implements ComponentsWsAction { private final SearchProjectsRequest request; private final Component.Builder wsComponent; private final Set favoriteProjectUuids; - private final List projectsWithIssuesInSync; private final boolean isUserLoggedIn; private final Map analysisByProjectUuid; private final Map applicationsLeakPeriod; - private final boolean needIssueSync; - private DbToWsComponent(SearchProjectsRequest request, SearchResults searchResults, boolean isUserLoggedIn, - boolean needIssueSync) { + private DbToWsComponent(SearchProjectsRequest request, SearchResults searchResults, boolean isUserLoggedIn) { this.request = request; this.analysisByProjectUuid = searchResults.analysisByProjectUuid; this.applicationsLeakPeriod = searchResults.applicationsLeakPeriods; this.wsComponent = Component.newBuilder(); this.favoriteProjectUuids = searchResults.favoriteProjectUuids; - this.projectsWithIssuesInSync = searchResults.projectsWithIssuesInSync; this.isUserLoggedIn = isUserLoggedIn; - this.needIssueSync = needIssueSync; } @Override @@ -511,11 +496,6 @@ public class SearchProjectsAction implements ComponentsWsAction { wsComponent.setIsFavorite(favoriteProjectUuids.contains(dbProject.getUuid())); } - if (Qualifiers.APP.equals(dbProject.getQualifier())) { - wsComponent.setNeedIssueSync(needIssueSync); - } else { - wsComponent.setNeedIssueSync(projectsWithIssuesInSync.contains(dbProject.getUuid())); - } return wsComponent.build(); } } @@ -523,7 +503,6 @@ public class SearchProjectsAction implements ComponentsWsAction { public static class SearchResults { private final List projects; private final Set favoriteProjectUuids; - private final List projectsWithIssuesInSync; private final Facets facets; private final Map analysisByProjectUuid; private final Map applicationsLeakPeriods; @@ -531,10 +510,9 @@ public class SearchProjectsAction implements ComponentsWsAction { private final int total; private SearchResults(List projects, Set favoriteProjectUuids, SearchIdResult searchResults, Map analysisByProjectUuid, - Map applicationsLeakPeriods, List projectsWithIssuesInSync, ProjectMeasuresQuery query) { + Map applicationsLeakPeriods, ProjectMeasuresQuery query) { this.projects = projects; this.favoriteProjectUuids = favoriteProjectUuids; - this.projectsWithIssuesInSync = projectsWithIssuesInSync; this.total = (int) searchResults.getTotal(); this.facets = searchResults.getFacets(); this.analysisByProjectUuid = analysisByProjectUuid; @@ -546,7 +524,6 @@ public class SearchProjectsAction implements ComponentsWsAction { private List projects; private Set favoriteProjectUuids; - private List projectsWithIssuesInSync; private Map analysisByProjectUuid; private Map applicationsLeakPeriods; private ProjectMeasuresQuery query; @@ -569,11 +546,6 @@ public class SearchProjectsAction implements ComponentsWsAction { return this; } - public SearchResultsBuilder projectsWithIssuesInSync(List projectsWithIssuesInSync) { - this.projectsWithIssuesInSync = projectsWithIssuesInSync; - return this; - } - public SearchResultsBuilder analysisByProjectUuid(Map analysisByProjectUuid) { this.analysisByProjectUuid = analysisByProjectUuid; return this; @@ -595,8 +567,7 @@ public class SearchProjectsAction implements ComponentsWsAction { } public SearchResults build() { - return new SearchResults(projects, favoriteProjectUuids, searchResults, analysisByProjectUuid, applicationsLeakPeriods, - projectsWithIssuesInSync, query); + return new SearchResults(projects, favoriteProjectUuids, searchResults, analysisByProjectUuid, applicationsLeakPeriods, query); } } } diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/search_projects-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/search_projects-example.json index a9f810413b7..44890a1a238 100644 --- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/search_projects-example.json +++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/search_projects-example.json @@ -14,8 +14,7 @@ "finance", "java" ], - "visibility": "public", - "needIssueSync": true + "visibility": "public" }, { "key": "another_project", @@ -23,8 +22,7 @@ "qualifier": "TRK", "isFavorite": false, "tags": [], - "visibility": "public", - "needIssueSync": false + "visibility": "public" }, { "key": "third_project", @@ -36,8 +34,7 @@ "offshore", "java" ], - "visibility": "public", - "needIssueSync": false + "visibility": "public" } ], "facets": [