Search in sources :

Example 1 with FACETS

use of org.sonar.api.server.ws.WebService.Param.FACETS in project sonarqube by SonarSource.

the class SearchProjectsActionTest method json_example.

@Test
public void json_example() {
    userSession.logIn();
    MetricDto coverage = db.measures().insertMetric(c -> c.setKey(COVERAGE).setValueType("PERCENT"));
    ComponentDto project1 = insertProject(c -> c.setDbKey(KEY_PROJECT_EXAMPLE_001).setName("My Project 1"), p -> p.setTagsString("finance, java"), new Measure(coverage, c -> c.setValue(80d)));
    db.components().insertProjectBranch(db.components().getProjectDto(project1), branchDto -> branchDto.setNeedIssueSync(true));
    ComponentDto project2 = insertProject(c -> c.setDbKey(KEY_PROJECT_EXAMPLE_002).setName("My Project 2"), new Measure(coverage, c -> c.setValue(90d)));
    ComponentDto project3 = insertProject(c -> c.setDbKey(KEY_PROJECT_EXAMPLE_003).setName("My Project 3"), p -> p.setTagsString("sales, offshore, java"), new Measure(coverage, c -> c.setValue(20d)));
    addFavourite(project1);
    index();
    String jsonResult = ws.newRequest().setParam(FACETS, COVERAGE).setParam(FIELDS, "_all").execute().getInput();
    assertJson(jsonResult).ignoreFields("id").isSimilarTo(ws.getDef().responseExampleAsString());
    assertJson(ws.getDef().responseExampleAsString()).ignoreFields("id").isSimilarTo(jsonResult);
    SearchProjectsWsResponse protobufResult = ws.newRequest().setParam(FACETS, COVERAGE).executeProtobuf(SearchProjectsWsResponse.class);
    assertThat(protobufResult.getComponentsList()).extracting(Component::getKey).containsExactly(project1.getDbKey(), project2.getDbKey(), project3.getDbKey());
}
Also used : FACETS(org.sonar.api.server.ws.WebService.Param.FACETS) Arrays(java.util.Arrays) PermissionIndexerTester(org.sonar.server.permission.index.PermissionIndexerTester) SORT(org.sonar.api.server.ws.WebService.Param.SORT) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) DbSession(org.sonar.db.DbSession) RequestBuilder(org.sonar.server.component.ws.SearchProjectsAction.RequestBuilder) Collections.singletonList(java.util.Collections.singletonList) NEW_SECURITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY) PAGE(org.sonar.api.server.ws.WebService.Param.PAGE) Param(org.sonar.api.server.ws.WebService.Param) WebService(org.sonar.api.server.ws.WebService) ProjectsInWarning(org.sonar.server.qualitygate.ProjectsInWarning) Arrays.asList(java.util.Arrays.asList) NEW_MAINTAINABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_MAINTAINABILITY_RATING_KEY) PARAM_FILTER(org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FILTER) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) FILTER_LANGUAGES(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUAGES) RELIABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.RELIABILITY_RATING_KEY) MoreCollectors.toList(org.sonar.core.util.stream.MoreCollectors.toList) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) Set(java.util.Set) NEW_DUPLICATED_LINES_DENSITY_KEY(org.sonar.api.measures.CoreMetrics.NEW_DUPLICATED_LINES_DENSITY_KEY) LEVEL(org.sonar.api.measures.Metric.ValueType.LEVEL) FILTER_QUALIFIER(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_QUALIFIER) Common(org.sonarqube.ws.Common) DbClient(org.sonar.db.DbClient) NEW_RELIABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_RELIABILITY_RATING_KEY) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) ALERT_STATUS_KEY(org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY) Stream(java.util.stream.Stream) SQALE_RATING_KEY(org.sonar.api.measures.CoreMetrics.SQALE_RATING_KEY) ProjectDto(org.sonar.db.project.ProjectDto) Optional(java.util.Optional) PAGE_SIZE(org.sonar.api.server.ws.WebService.Param.PAGE_SIZE) FIELDS(org.sonar.api.server.ws.WebService.Param.FIELDS) PropertyDto(org.sonar.db.property.PropertyDto) Component(org.sonarqube.ws.Components.Component) Joiner(com.google.common.base.Joiner) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) NCLOC_LANGUAGE_DISTRIBUTION_KEY(org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY) EsTester(org.sonar.server.es.EsTester) RunWith(org.junit.runner.RunWith) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) ProjectMeasuresIndexer(org.sonar.server.measure.index.ProjectMeasuresIndexer) HashSet(java.util.HashSet) ProjectMeasuresIndex(org.sonar.server.measure.index.ProjectMeasuresIndex) WebAuthorizationTypeSupport(org.sonar.server.permission.index.WebAuthorizationTypeSupport) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SearchProjectsRequest(org.sonar.server.component.ws.SearchProjectsAction.SearchProjectsRequest) DATA(org.sonar.api.measures.Metric.ValueType.DATA) Nullable(javax.annotation.Nullable) Before(org.junit.Before) UserSessionRule(org.sonar.server.tester.UserSessionRule) SECURITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.SECURITY_RATING_KEY) NEW_LINES_KEY(org.sonar.api.measures.CoreMetrics.NEW_LINES_KEY) Assertions.tuple(org.assertj.core.api.Assertions.tuple) PlatformEditionProvider(org.sonar.core.platform.PlatformEditionProvider) Optional.ofNullable(java.util.Optional.ofNullable) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) DUPLICATED_LINES_DENSITY_KEY(org.sonar.api.measures.CoreMetrics.DUPLICATED_LINES_DENSITY_KEY) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) SearchProjectsWsResponse(org.sonarqube.ws.Components.SearchProjectsWsResponse) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) MetricDto(org.sonar.db.metric.MetricDto) Qualifiers(org.sonar.api.resources.Qualifiers) Edition(org.sonar.core.platform.EditionProvider.Edition) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) INT(org.sonar.api.measures.Metric.ValueType.INT) IssueIndexSyncProgressChecker(org.sonar.server.issue.index.IssueIndexSyncProgressChecker) ASCENDING(org.sonar.api.server.ws.WebService.Param.ASCENDING) KEY_PROJECT_EXAMPLE_002(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_002) KEY_PROJECT_EXAMPLE_001(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001) KEY_PROJECT_EXAMPLE_003(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_003) FILTER_TAGS(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_TAGS) Metric(org.sonar.api.measures.Metric) MetricDto(org.sonar.db.metric.MetricDto) SearchProjectsWsResponse(org.sonarqube.ws.Components.SearchProjectsWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 2 with FACETS

use of org.sonar.api.server.ws.WebService.Param.FACETS in project sonarqube by SonarSource.

the class SearchActionFacetsTest method assigned_to_me_facet_is_sticky_relative_to_assignees.

@Test
public void assigned_to_me_facet_is_sticky_relative_to_assignees() {
    ComponentDto project = db.components().insertPublicProject();
    indexPermissions();
    ComponentDto file = db.components().insertComponent(newFileDto(project));
    RuleDefinitionDto rule = db.rules().insertIssueRule();
    UserDto john = db.users().insertUser();
    UserDto alice = db.users().insertUser();
    db.issues().insertIssue(rule, project, file, i -> i.setAssigneeUuid(john.getUuid()));
    db.issues().insertIssue(rule, project, file, i -> i.setAssigneeUuid(alice.getUuid()));
    db.issues().insertIssue(rule, project, file, i -> i.setAssigneeUuid(null));
    indexIssues();
    userSession.logIn(john);
    SearchWsResponse response = ws.newRequest().setParam("resolved", "false").setParam("assignees", alice.getLogin()).setParam(FACETS, "assignees,assigned_to_me").executeProtobuf(SearchWsResponse.class);
    assertThat(response.getFacets().getFacetsList()).extracting(Common.Facet::getProperty, facet -> facet.getValuesList().stream().collect(toMap(FacetValue::getVal, FacetValue::getCount))).containsExactlyInAnyOrder(tuple("assignees", of(john.getLogin(), 1L, alice.getLogin(), 1L, "", 1L)), tuple("assigned_to_me", of(john.getLogin(), 1L)));
}
Also used : IntStream(java.util.stream.IntStream) FACETS(org.sonar.api.server.ws.WebService.Param.FACETS) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) EsTester(org.sonar.server.es.EsTester) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PARAM_PROJECTS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PROJECTS) Random(java.util.Random) RuleType(org.sonar.api.rules.RuleType) SearchWsResponse(org.sonarqube.ws.Issues.SearchWsResponse) Languages(org.sonar.api.resources.Languages) WebService(org.sonar.api.server.ws.WebService) TransitionService(org.sonar.server.issue.TransitionService) WebAuthorizationTypeSupport(org.sonar.server.permission.index.WebAuthorizationTypeSupport) Collectors.toMap(java.util.stream.Collectors.toMap) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) TextRangeResponseFormatter(org.sonar.server.issue.TextRangeResponseFormatter) IssueIndex(org.sonar.server.issue.index.IssueIndex) IssueIteratorFactory(org.sonar.server.issue.index.IssueIteratorFactory) UserSessionRule.standalone(org.sonar.server.tester.UserSessionRule.standalone) PARAM_FILES(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_FILES) Map(java.util.Map) AvatarResolverImpl(org.sonar.server.issue.AvatarResolverImpl) IssueQueryFactory(org.sonar.server.issue.index.IssueQueryFactory) PARAM_COMPONENT_KEYS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) PermissionIndexer(org.sonar.server.permission.index.PermissionIndexer) ImmutableMap(com.google.common.collect.ImmutableMap) System2(org.sonar.api.utils.System2) Durations(org.sonar.api.utils.Durations) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) ImmutableMap.of(com.google.common.collect.ImmutableMap.of) Common(org.sonarqube.ws.Common) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) Issue(org.sonar.api.issue.Issue) FacetValue(org.sonarqube.ws.Common.FacetValue) IssueIndexSyncProgressChecker(org.sonar.server.issue.index.IssueIndexSyncProgressChecker) Clock(java.time.Clock) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) ComponentTesting.newDirectory(org.sonar.db.component.ComponentTesting.newDirectory) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) ComponentTesting.newModuleDto(org.sonar.db.component.ComponentTesting.newModuleDto) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) SearchWsResponse(org.sonarqube.ws.Issues.SearchWsResponse) Common(org.sonarqube.ws.Common) Test(org.junit.Test)

Example 3 with FACETS

use of org.sonar.api.server.ws.WebService.Param.FACETS in project sonarqube by SonarSource.

the class SearchActionFacetsTest method display_zero_valued_facets_for_selected_items_having_no_issue.

@Test
public void display_zero_valued_facets_for_selected_items_having_no_issue() {
    ComponentDto project1 = db.components().insertPublicProject();
    ComponentDto module1 = db.components().insertComponent(newModuleDto(project1));
    ComponentDto module2 = db.components().insertComponent(newModuleDto(project1));
    ComponentDto project2 = db.components().insertPublicProject();
    ComponentDto file1 = db.components().insertComponent(newFileDto(module1));
    ComponentDto file2 = db.components().insertComponent(newFileDto(module1));
    RuleDefinitionDto rule1 = db.rules().insertIssueRule();
    RuleDefinitionDto rule2 = db.rules().insertIssueRule();
    UserDto user1 = db.users().insertUser();
    UserDto user2 = db.users().insertUser();
    db.issues().insertIssue(rule1, project1, file1, i -> i.setSeverity("MAJOR").setStatus("OPEN").setResolution(null).setType(RuleType.CODE_SMELL).setEffort(10L).setAssigneeUuid(user1.getUuid()));
    indexPermissions();
    indexIssues();
    SearchWsResponse response = ws.newRequest().setParam(PARAM_PROJECTS, project1.getKey() + "," + project2.getKey()).setParam(PARAM_FILES, file1.path() + "," + file2.path()).setParam("rules", rule1.getKey().toString() + "," + rule2.getKey().toString()).setParam("severities", "MAJOR,MINOR").setParam("languages", rule1.getLanguage() + "," + rule2.getLanguage()).setParam("assignees", user1.getLogin() + "," + user2.getLogin()).setParam(FACETS, "severities,statuses,resolutions,rules,types,languages,projects,moduleUuids,files,assignees").executeProtobuf(SearchWsResponse.class);
    Map<String, Number> expectedStatuses = ImmutableMap.<String, Number>builder().put("OPEN", 1L).put("CONFIRMED", 0L).put("REOPENED", 0L).put("RESOLVED", 0L).put("CLOSED", 0L).build();
    assertThat(response.getFacets().getFacetsList()).extracting(Common.Facet::getProperty, facet -> facet.getValuesList().stream().collect(toMap(FacetValue::getVal, FacetValue::getCount))).containsExactlyInAnyOrder(tuple("severities", of("INFO", 0L, "MINOR", 0L, "MAJOR", 1L, "CRITICAL", 0L, "BLOCKER", 0L)), tuple("statuses", expectedStatuses), tuple("resolutions", of("", 1L, "FALSE-POSITIVE", 0L, "FIXED", 0L, "REMOVED", 0L, "WONTFIX", 0L)), tuple("rules", of(rule1.getKey().toString(), 1L, rule2.getKey().toString(), 0L)), tuple("types", of("CODE_SMELL", 1L, "BUG", 0L, "VULNERABILITY", 0L)), tuple("languages", of(rule1.getLanguage(), 1L, rule2.getLanguage(), 0L)), tuple("projects", of(project1.getKey(), 1L, project2.getKey(), 0L)), tuple("moduleUuids", of(module1.uuid(), 1L)), tuple("files", of(file1.path(), 1L, file2.path(), 0L)), tuple("assignees", of("", 0L, user1.getLogin(), 1L, user2.getLogin(), 0L)));
}
Also used : IntStream(java.util.stream.IntStream) FACETS(org.sonar.api.server.ws.WebService.Param.FACETS) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) EsTester(org.sonar.server.es.EsTester) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PARAM_PROJECTS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PROJECTS) Random(java.util.Random) RuleType(org.sonar.api.rules.RuleType) SearchWsResponse(org.sonarqube.ws.Issues.SearchWsResponse) Languages(org.sonar.api.resources.Languages) WebService(org.sonar.api.server.ws.WebService) TransitionService(org.sonar.server.issue.TransitionService) WebAuthorizationTypeSupport(org.sonar.server.permission.index.WebAuthorizationTypeSupport) Collectors.toMap(java.util.stream.Collectors.toMap) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) TextRangeResponseFormatter(org.sonar.server.issue.TextRangeResponseFormatter) IssueIndex(org.sonar.server.issue.index.IssueIndex) IssueIteratorFactory(org.sonar.server.issue.index.IssueIteratorFactory) UserSessionRule.standalone(org.sonar.server.tester.UserSessionRule.standalone) PARAM_FILES(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_FILES) Map(java.util.Map) AvatarResolverImpl(org.sonar.server.issue.AvatarResolverImpl) IssueQueryFactory(org.sonar.server.issue.index.IssueQueryFactory) PARAM_COMPONENT_KEYS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) PermissionIndexer(org.sonar.server.permission.index.PermissionIndexer) ImmutableMap(com.google.common.collect.ImmutableMap) System2(org.sonar.api.utils.System2) Durations(org.sonar.api.utils.Durations) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) ImmutableMap.of(com.google.common.collect.ImmutableMap.of) Common(org.sonarqube.ws.Common) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) Issue(org.sonar.api.issue.Issue) FacetValue(org.sonarqube.ws.Common.FacetValue) IssueIndexSyncProgressChecker(org.sonar.server.issue.index.IssueIndexSyncProgressChecker) Clock(java.time.Clock) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) ComponentTesting.newDirectory(org.sonar.db.component.ComponentTesting.newDirectory) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) ComponentTesting.newModuleDto(org.sonar.db.component.ComponentTesting.newModuleDto) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) SearchWsResponse(org.sonarqube.ws.Issues.SearchWsResponse) Common(org.sonarqube.ws.Common) Test(org.junit.Test)

Example 4 with FACETS

use of org.sonar.api.server.ws.WebService.Param.FACETS in project sonarqube by SonarSource.

the class SearchActionFacetsTest method assignedToMe_facet_must_escape_login_of_authenticated_user.

@Test
public void assignedToMe_facet_must_escape_login_of_authenticated_user() {
    // login looks like an invalid regexp
    UserDto user = db.users().insertUser(u -> u.setLogin("foo["));
    userSession.logIn(user);
    // should not fail
    SearchWsResponse response = ws.newRequest().setParam(FACETS, "assigned_to_me").executeProtobuf(SearchWsResponse.class);
    assertThat(response.getFacets().getFacetsList()).extracting(Common.Facet::getProperty, facet -> facet.getValuesList().stream().collect(toMap(FacetValue::getVal, FacetValue::getCount))).containsExactlyInAnyOrder(tuple("assigned_to_me", of("foo[", 0L)));
}
Also used : IntStream(java.util.stream.IntStream) FACETS(org.sonar.api.server.ws.WebService.Param.FACETS) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) EsTester(org.sonar.server.es.EsTester) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PARAM_PROJECTS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PROJECTS) Random(java.util.Random) RuleType(org.sonar.api.rules.RuleType) SearchWsResponse(org.sonarqube.ws.Issues.SearchWsResponse) Languages(org.sonar.api.resources.Languages) WebService(org.sonar.api.server.ws.WebService) TransitionService(org.sonar.server.issue.TransitionService) WebAuthorizationTypeSupport(org.sonar.server.permission.index.WebAuthorizationTypeSupport) Collectors.toMap(java.util.stream.Collectors.toMap) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) TextRangeResponseFormatter(org.sonar.server.issue.TextRangeResponseFormatter) IssueIndex(org.sonar.server.issue.index.IssueIndex) IssueIteratorFactory(org.sonar.server.issue.index.IssueIteratorFactory) UserSessionRule.standalone(org.sonar.server.tester.UserSessionRule.standalone) PARAM_FILES(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_FILES) Map(java.util.Map) AvatarResolverImpl(org.sonar.server.issue.AvatarResolverImpl) IssueQueryFactory(org.sonar.server.issue.index.IssueQueryFactory) PARAM_COMPONENT_KEYS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) PermissionIndexer(org.sonar.server.permission.index.PermissionIndexer) ImmutableMap(com.google.common.collect.ImmutableMap) System2(org.sonar.api.utils.System2) Durations(org.sonar.api.utils.Durations) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) ImmutableMap.of(com.google.common.collect.ImmutableMap.of) Common(org.sonarqube.ws.Common) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) Issue(org.sonar.api.issue.Issue) FacetValue(org.sonarqube.ws.Common.FacetValue) IssueIndexSyncProgressChecker(org.sonar.server.issue.index.IssueIndexSyncProgressChecker) Clock(java.time.Clock) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) ComponentTesting.newDirectory(org.sonar.db.component.ComponentTesting.newDirectory) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) ComponentTesting.newModuleDto(org.sonar.db.component.ComponentTesting.newModuleDto) UserDto(org.sonar.db.user.UserDto) SearchWsResponse(org.sonarqube.ws.Issues.SearchWsResponse) Common(org.sonarqube.ws.Common) Test(org.junit.Test)

Example 5 with FACETS

use of org.sonar.api.server.ws.WebService.Param.FACETS in project sonarqube by SonarSource.

the class SearchProjectsAction method addFacets.

private static SearchProjectsWsResponse.Builder addFacets(SearchResults searchResults, SearchProjectsWsResponse.Builder wsResponse) {
    Facets esFacets = searchResults.facets;
    EsToWsFacet esToWsFacet = new EsToWsFacet();
    searchResults.query.getLanguages().ifPresent(languages -> addMandatoryValuesToFacet(esFacets, FILTER_LANGUAGES, languages));
    searchResults.query.getTags().ifPresent(tags -> addMandatoryValuesToFacet(esFacets, FILTER_TAGS, tags));
    Common.Facets wsFacets = esFacets.getAll().entrySet().stream().map(esToWsFacet).collect(Collector.of(Common.Facets::newBuilder, Common.Facets.Builder::addFacets, (result1, result2) -> {
        throw new IllegalStateException("Parallel execution forbidden");
    }, Common.Facets.Builder::build));
    wsResponse.setFacets(wsFacets);
    return wsResponse;
}
Also used : FACETS(org.sonar.api.server.ws.WebService.Param.FACETS) Arrays(java.util.Arrays) Facets(org.sonar.server.es.Facets) DbSession(org.sonar.db.DbSession) Request(org.sonar.api.server.ws.Request) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Param(org.sonar.api.server.ws.WebService.Param) WebService(org.sonar.api.server.ws.WebService) PropertyQuery(org.sonar.db.property.PropertyQuery) ProjectsInWarning(org.sonar.server.qualitygate.ProjectsInWarning) SORT_BY_LAST_ANALYSIS_DATE(org.sonar.server.measure.index.ProjectMeasuresQuery.SORT_BY_LAST_ANALYSIS_DATE) Map(java.util.Map) ProjectMeasuresQueryFactory.newProjectMeasuresQuery(org.sonar.server.component.ws.ProjectMeasuresQueryFactory.newProjectMeasuresQuery) Visibility(org.sonar.server.project.Visibility) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) PARAM_FILTER(org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FILTER) Collector(java.util.stream.Collector) Criterion(org.sonar.server.component.ws.FilterParser.Criterion) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) FILTER_LANGUAGES(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUAGES) MoreCollectors.toList(org.sonar.core.util.stream.MoreCollectors.toList) SearchIdResult(org.sonar.server.es.SearchIdResult) SORT_BY_NAME(org.sonar.server.measure.index.ProjectMeasuresQuery.SORT_BY_NAME) Set(java.util.Set) Collectors(java.util.stream.Collectors) SearchResultsBuilder(org.sonar.server.component.ws.SearchProjectsAction.SearchResults.SearchResultsBuilder) Sets(com.google.common.collect.Sets) Common(org.sonarqube.ws.Common) Objects(java.util.Objects) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) ALERT_STATUS_KEY(org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY) Stream(java.util.stream.Stream) ProjectMeasuresQuery(org.sonar.server.measure.index.ProjectMeasuresQuery) Entry(java.util.Map.Entry) ProjectDto(org.sonar.db.project.ProjectDto) Optional(java.util.Optional) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) FIELDS(org.sonar.api.server.ws.WebService.Param.FIELDS) PropertyDto(org.sonar.db.property.PropertyDto) Component(org.sonarqube.ws.Components.Component) WsUtils.writeProtobuf(org.sonar.server.ws.WsUtils.writeProtobuf) NON_METRIC_SORT_KEYS(org.sonar.server.component.ws.ProjectMeasuresQueryValidator.NON_METRIC_SORT_KEYS) IS_FAVORITE_CRITERION(org.sonar.server.component.ws.ProjectMeasuresQueryFactory.IS_FAVORITE_CRITERION) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) ProjectMeasuresIndex(org.sonar.server.measure.index.ProjectMeasuresIndex) Objects.requireNonNull(java.util.Objects.requireNonNull) Response(org.sonar.api.server.ws.Response) MoreCollectors(org.sonar.core.util.stream.MoreCollectors) Nullable(javax.annotation.Nullable) Collections.emptyMap(java.util.Collections.emptyMap) PlatformEditionProvider(org.sonar.core.platform.PlatformEditionProvider) Optional.ofNullable(java.util.Optional.ofNullable) METRIC_KEYS(org.sonar.db.measure.ProjectMeasuresIndexerIterator.METRIC_KEYS) SearchProjectsWsResponse(org.sonarqube.ws.Components.SearchProjectsWsResponse) Maps(com.google.common.collect.Maps) ACTION_SEARCH_PROJECTS(org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SEARCH_PROJECTS) Ordering(com.google.common.collect.Ordering) Qualifiers(org.sonar.api.resources.Qualifiers) Edition(org.sonar.core.platform.EditionProvider.Edition) IssueIndexSyncProgressChecker(org.sonar.server.issue.index.IssueIndexSyncProgressChecker) Change(org.sonar.api.server.ws.Change) UserSession(org.sonar.server.user.UserSession) FILTER_TAGS(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_TAGS) SnapshotDto(org.sonar.db.component.SnapshotDto) Collections(java.util.Collections) CheckForNull(javax.annotation.CheckForNull) Facets(org.sonar.server.es.Facets) Common(org.sonarqube.ws.Common)

Aggregations

WebService (org.sonar.api.server.ws.WebService)6 FACETS (org.sonar.api.server.ws.WebService.Param.FACETS)6 ComponentDto (org.sonar.db.component.ComponentDto)6 IssueIndexSyncProgressChecker (org.sonar.server.issue.index.IssueIndexSyncProgressChecker)6 Common (org.sonarqube.ws.Common)6 Map (java.util.Map)5 IntStream (java.util.stream.IntStream)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 ImmutableMap.of (com.google.common.collect.ImmutableMap.of)4 Clock (java.time.Clock)4 Random (java.util.Random)4 Collectors.toMap (java.util.stream.Collectors.toMap)4 Tuple.tuple (org.assertj.core.groups.Tuple.tuple)4 Rule (org.junit.Rule)4 Test (org.junit.Test)4 System2 (org.sonar.api.utils.System2)4 DbTester (org.sonar.db.DbTester)4 EsTester (org.sonar.server.es.EsTester)4