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;
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();
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");
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)));
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;
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
.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);
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);
}
}
.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);
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()
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
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();
}
}
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;
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;
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;
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;
}
public SearchResults build() {
- return new SearchResults(projects, favoriteProjectUuids, searchResults, analysisByProjectUuid, applicationsLeakPeriods,
- projectsWithIssuesInSync, query);
+ return new SearchResults(projects, favoriteProjectUuids, searchResults, analysisByProjectUuid, applicationsLeakPeriods, query);
}
}
}