]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13399 all applications should be disabled when issue sync in progress
authorJacek <jacek.poreda@sonarsource.com>
Fri, 12 Jun 2020 14:14:55 +0000 (16:14 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 26 Jun 2020 20:04:57 +0000 (20:04 +0000)
server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ShowAction.java

index 52339a0e6d1a3857036406611c0c6555ec498720..60682508513567a98813bd259a5e5b14566d31ae 100644 (file)
@@ -123,9 +123,9 @@ public class SearchProjectsAction implements ComponentsWsAction {
   private final IssueIndexSyncProgressChecker issueIndexSyncProgressChecker;
 
   public SearchProjectsAction(DbClient dbClient, ProjectMeasuresIndex index, UserSession userSession,
-      ProjectsInWarning projectsInWarning,
-      PlatformEditionProvider editionProvider,
-      IssueIndexSyncProgressChecker issueIndexSyncProgressChecker) {
+    ProjectsInWarning projectsInWarning,
+    PlatformEditionProvider editionProvider,
+    IssueIndexSyncProgressChecker issueIndexSyncProgressChecker) {
     this.dbClient = dbClient;
     this.index = index;
     this.userSession = userSession;
@@ -256,12 +256,14 @@ public class SearchProjectsAction implements ComponentsWsAction {
     Map<String, OrganizationDto> organizationsByUuid = dbClient.organizationDao().selectByUuids(dbSession, organizationUuids)
       .stream()
       .collect(MoreCollectors.uniqueIndex(OrganizationDto::getUuid));
-    return buildResponse(request, searchResults, organizationsByUuid);
+    boolean needIssueSync = dbClient.branchDao().hasAnyBranchWhereNeedIssueSync(dbSession, true);
+    return buildResponse(request, searchResults, organizationsByUuid, needIssueSync);
   }
 
   private SearchProjectsWsResponse handleForOrganization(DbSession dbSession, SearchProjectsRequest request, OrganizationDto organization) {
     SearchResults searchResults = searchData(dbSession, request, organization);
-    return buildResponse(request, searchResults, ImmutableMap.of(organization.getUuid(), organization));
+    boolean needIssueSync = dbClient.branchDao().hasAnyBranchWhereNeedIssueSync(dbSession, true);
+    return buildResponse(request, searchResults, ImmutableMap.of(organization.getUuid(), organization), needIssueSync);
   }
 
   private SearchResults searchData(DbSession dbSession, SearchProjectsRequest request, @Nullable OrganizationDto organization) {
@@ -411,8 +413,9 @@ public class SearchProjectsAction implements ComponentsWsAction {
     return request.build();
   }
 
-  private SearchProjectsWsResponse buildResponse(SearchProjectsRequest request, SearchResults searchResults, Map<String, OrganizationDto> organizationsByUuid) {
-    Function<ProjectDto, Component> dbToWsComponent = new DbToWsComponent(request, organizationsByUuid, searchResults, userSession.isLoggedIn());
+  private SearchProjectsWsResponse buildResponse(SearchProjectsRequest request, SearchResults searchResults, Map<String, OrganizationDto> organizationsByUuid,
+    boolean needIssueSync) {
+    Function<ProjectDto, Component> dbToWsComponent = new DbToWsComponent(request, organizationsByUuid, searchResults, userSession.isLoggedIn(), needIssueSync);
 
     Map<String, OrganizationDto> organizationsByUuidForAdditionalInfo = new HashMap<>();
     if (request.additionalFields.contains(ORGANIZATIONS)) {
@@ -527,8 +530,10 @@ public class SearchProjectsAction implements ComponentsWsAction {
     private final boolean isUserLoggedIn;
     private final Map<String, SnapshotDto> analysisByProjectUuid;
     private final Map<String, Long> applicationsLeakPeriod;
+    private final boolean needIssueSync;
 
-    private DbToWsComponent(SearchProjectsRequest request, Map<String, OrganizationDto> organizationsByUuid, SearchResults searchResults, boolean isUserLoggedIn) {
+    private DbToWsComponent(SearchProjectsRequest request, Map<String, OrganizationDto> organizationsByUuid, SearchResults searchResults, boolean isUserLoggedIn,
+      boolean needIssueSync) {
       this.request = request;
       this.analysisByProjectUuid = searchResults.analysisByProjectUuid;
       this.applicationsLeakPeriod = searchResults.applicationsLeakPeriods;
@@ -537,6 +542,7 @@ public class SearchProjectsAction implements ComponentsWsAction {
       this.favoriteProjectUuids = searchResults.favoriteProjectUuids;
       this.projectsWithIssuesInSync = searchResults.projectsWithIssuesInSync;
       this.isUserLoggedIn = isUserLoggedIn;
+      this.needIssueSync = needIssueSync;
     }
 
     @Override
@@ -571,8 +577,11 @@ public class SearchProjectsAction implements ComponentsWsAction {
         wsComponent.setIsFavorite(favoriteProjectUuids.contains(dbProject.getUuid()));
       }
 
-      wsComponent.setNeedIssueSync(projectsWithIssuesInSync.contains(dbProject.getUuid()));
-
+      if (Qualifiers.APP.equals(dbProject.getQualifier())) {
+        wsComponent.setNeedIssueSync(needIssueSync);
+      } else {
+        wsComponent.setNeedIssueSync(projectsWithIssuesInSync.contains(dbProject.getUuid()));
+      }
       return wsComponent.build();
     }
   }
index 55b69539fb117eb561ce5a1f7899354663ce823d..ce32a84ed9547a4d111e71a51180191cce35b1ed 100644 (file)
@@ -57,7 +57,7 @@ import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COM
 
 public class ShowAction implements ComponentsWsAction {
   private static final Set<String> PROJECT_OR_APP_QUALIFIERS = ImmutableSet.of(Qualifiers.PROJECT, Qualifiers.APP);
-  private static final Set<String> VIEW_OR_SUBVIEW_QUALIFIERS = ImmutableSet.of(Qualifiers.VIEW, Qualifiers.SUBVIEW);
+  private static final Set<String> APP_VIEW_OR_SUBVIEW_QUALIFIERS = ImmutableSet.of(Qualifiers.APP, Qualifiers.VIEW, Qualifiers.SUBVIEW);
   private final UserSession userSession;
   private final DbClient dbClient;
   private final ComponentFinder componentFinder;
@@ -166,10 +166,9 @@ public class ShowAction implements ComponentsWsAction {
   }
 
   private boolean needIssueSync(DbSession dbSession, ComponentDto component, @Nullable ProjectDto projectDto) {
-    if (projectDto == null || VIEW_OR_SUBVIEW_QUALIFIERS.contains(component.qualifier())) {
+    if (projectDto == null || APP_VIEW_OR_SUBVIEW_QUALIFIERS.contains(component.qualifier())) {
       return issueIndexSyncProgressChecker.isIssueSyncInProgress(dbSession);
     }
-
     return issueIndexSyncProgressChecker.doProjectNeedIssueSync(dbSession, projectDto.getUuid());
   }