From b1b710b8e24c2bebf13a108ee75a3418f32fa6da Mon Sep 17 00:00:00 2001 From: Jacek Date: Fri, 12 Jun 2020 16:14:55 +0200 Subject: [PATCH] SONAR-13399 all applications should be disabled when issue sync in progress --- .../component/ws/SearchProjectsAction.java | 29 ++++++++++++------- .../sonar/server/component/ws/ShowAction.java | 5 ++-- 2 files changed, 21 insertions(+), 13 deletions(-) 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 52339a0e6d1..60682508513 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 @@ -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 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 organizationsByUuid) { - Function dbToWsComponent = new DbToWsComponent(request, organizationsByUuid, searchResults, userSession.isLoggedIn()); + private SearchProjectsWsResponse buildResponse(SearchProjectsRequest request, SearchResults searchResults, Map organizationsByUuid, + boolean needIssueSync) { + Function dbToWsComponent = new DbToWsComponent(request, organizationsByUuid, searchResults, userSession.isLoggedIn(), needIssueSync); Map organizationsByUuidForAdditionalInfo = new HashMap<>(); if (request.additionalFields.contains(ORGANIZATIONS)) { @@ -527,8 +530,10 @@ public class SearchProjectsAction implements ComponentsWsAction { private final boolean isUserLoggedIn; private final Map analysisByProjectUuid; private final Map applicationsLeakPeriod; + private final boolean needIssueSync; - private DbToWsComponent(SearchProjectsRequest request, Map organizationsByUuid, SearchResults searchResults, boolean isUserLoggedIn) { + private DbToWsComponent(SearchProjectsRequest request, Map 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(); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ShowAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ShowAction.java index 55b69539fb1..ce32a84ed95 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ShowAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ShowAction.java @@ -57,7 +57,7 @@ import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COM public class ShowAction implements ComponentsWsAction { private static final Set PROJECT_OR_APP_QUALIFIERS = ImmutableSet.of(Qualifiers.PROJECT, Qualifiers.APP); - private static final Set VIEW_OR_SUBVIEW_QUALIFIERS = ImmutableSet.of(Qualifiers.VIEW, Qualifiers.SUBVIEW); + private static final Set 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()); } -- 2.39.5