]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19728 Remove needIssueSync flag from api/components/search_projects
authorEric Giffon <eric.giffon@sonarsource.com>
Mon, 3 Jul 2023 13:41:13 +0000 (15:41 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 19 Jul 2023 20:03:04 +0000 (20:03 +0000)
server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/SearchProjectsActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/search_projects-example.json

index 16d0c715ee7cf3f64e5b54efc263d621296c40f8..bf5ae518aba781f3c3f28084aedf333e2ec647c0 100644 (file)
@@ -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)));
index d3ea6366c0f4180612f363f010ac9602542c3add..f031289552d87a8f938b4e2cef32b74fbd6e7ddf 100644 (file)
@@ -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<String> 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<String> getProjectUuidsWithBranchesNeedIssueSync(DbSession dbSession, Set<String> projectUuids) {
-    return issueIndexSyncProgressChecker.findProjectUuidsWithIssuesSyncNeed(dbSession, projectUuids);
-  }
-
   private Set<String> getQualifiersBasedOnEdition(ProjectMeasuresQuery query) {
     Set<String> availableQualifiers = getQualifiersFromEdition();
     Set<String> 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<ProjectDto, Component> dbToWsComponent = new DbToWsComponent(request, searchResults, userSession.isLoggedIn(), needIssueSync);
+  private SearchProjectsWsResponse buildResponse(SearchProjectsRequest request, SearchResults searchResults) {
+    Function<ProjectDto, Component> 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<String> favoriteProjectUuids;
-    private final List<String> projectsWithIssuesInSync;
     private final boolean isUserLoggedIn;
     private final Map<String, SnapshotDto> analysisByProjectUuid;
     private final Map<String, Long> 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<ProjectDto> projects;
     private final Set<String> favoriteProjectUuids;
-    private final List<String> projectsWithIssuesInSync;
     private final Facets facets;
     private final Map<String, SnapshotDto> analysisByProjectUuid;
     private final Map<String, Long> applicationsLeakPeriods;
@@ -531,10 +510,9 @@ public class SearchProjectsAction implements ComponentsWsAction {
     private final int total;
 
     private SearchResults(List<ProjectDto> projects, Set<String> favoriteProjectUuids, SearchIdResult<String> searchResults, Map<String, SnapshotDto> analysisByProjectUuid,
-      Map<String, Long> applicationsLeakPeriods, List<String> projectsWithIssuesInSync, ProjectMeasuresQuery query) {
+      Map<String, Long> 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<ProjectDto> projects;
       private Set<String> favoriteProjectUuids;
-      private List<String> projectsWithIssuesInSync;
       private Map<String, SnapshotDto> analysisByProjectUuid;
       private Map<String, Long> applicationsLeakPeriods;
       private ProjectMeasuresQuery query;
@@ -569,11 +546,6 @@ public class SearchProjectsAction implements ComponentsWsAction {
         return this;
       }
 
-      public SearchResultsBuilder projectsWithIssuesInSync(List<String> projectsWithIssuesInSync) {
-        this.projectsWithIssuesInSync = projectsWithIssuesInSync;
-        return this;
-      }
-
       public SearchResultsBuilder analysisByProjectUuid(Map<String, SnapshotDto> 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);
       }
     }
   }
index a9f810413b737367a3917010f098cf16f74dd85e..44890a1a2383ca171533d11046b2654ea455decb 100644 (file)
@@ -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": [