@@ -42,17 +42,17 @@ import static org.sonar.server.component.ws.FilterParser.Operator.EQ; | |||
import static org.sonar.server.component.ws.FilterParser.Operator.IN; | |||
import static org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion; | |||
import static org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUAGES; | |||
import static org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_TAGS; | |||
class ProjectMeasuresQueryFactory { | |||
public static final String IS_FAVORITE_CRITERION = "isFavorite"; | |||
public static final String CRITERION_TAG = "tag"; | |||
public static final String QUERY_KEY = "query"; | |||
private static final Map<String, BiConsumer<Criterion, ProjectMeasuresQuery>> CRITERION_PROCESSORS = ImmutableMap.<String, BiConsumer<Criterion, ProjectMeasuresQuery>>builder() | |||
.put(IS_FAVORITE_CRITERION.toLowerCase(ENGLISH), (criterion, query) -> processIsFavorite(criterion)) | |||
.put(FILTER_LANGUAGES, ProjectMeasuresQueryFactory::processLanguages) | |||
.put(CRITERION_TAG, ProjectMeasuresQueryFactory::processTags) | |||
.put(FILTER_TAGS, ProjectMeasuresQueryFactory::processTags) | |||
.put(QUERY_KEY, ProjectMeasuresQueryFactory::processQuery) | |||
.put(ALERT_STATUS_KEY, ProjectMeasuresQueryFactory::processQualityGateStatus) | |||
.build(); | |||
@@ -106,7 +106,7 @@ class ProjectMeasuresQueryFactory { | |||
query.setTags(new HashSet<>(values)); | |||
return; | |||
} | |||
throw new IllegalArgumentException("Tag should be set either by using 'tag = java' or 'tag IN (finance, platform)'"); | |||
throw new IllegalArgumentException("Tags should be set either by using 'tags = java' or 'tags IN (finance, platform)'"); | |||
} | |||
private static void processQuery(Criterion criterion, ProjectMeasuresQuery query) { |
@@ -83,6 +83,7 @@ import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIEL | |||
import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.INDEX_TYPE_PROJECT_MEASURES; | |||
import static org.sonar.server.measure.index.ProjectMeasuresQuery.SORT_BY_NAME; | |||
import static org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUAGES; | |||
import static org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_TAGS; | |||
public class ProjectMeasuresIndex extends BaseIndex { | |||
@@ -95,7 +96,7 @@ public class ProjectMeasuresIndex extends BaseIndex { | |||
SECURITY_RATING_KEY, | |||
ALERT_STATUS_KEY, | |||
FILTER_LANGUAGES, | |||
FIELD_TAGS); | |||
FILTER_TAGS); | |||
private static final String FIELD_MEASURES_KEY = FIELD_MEASURES + "." + ProjectMeasuresIndexDefinition.FIELD_MEASURES_KEY; | |||
private static final String FIELD_MEASURES_VALUE = FIELD_MEASURES + "." + ProjectMeasuresIndexDefinition.FIELD_MEASURES_VALUE; |
@@ -154,7 +154,7 @@ public class ProjectMeasuresQueryFactoryTest { | |||
@Test | |||
public void create_query_on_tag_using_in_operator() throws Exception { | |||
ProjectMeasuresQuery query = newProjectMeasuresQuery( | |||
singletonList(Criterion.builder().setKey("tag").setOperator(IN).setValues(asList("java", "js")).build()), | |||
singletonList(Criterion.builder().setKey("tags").setOperator(IN).setValues(asList("java", "js")).build()), | |||
emptySet()); | |||
assertThat(query.getTags().get()).containsOnly("java", "js"); | |||
@@ -163,7 +163,7 @@ public class ProjectMeasuresQueryFactoryTest { | |||
@Test | |||
public void create_query_on_tag_using_equals_operator() throws Exception { | |||
ProjectMeasuresQuery query = newProjectMeasuresQuery( | |||
singletonList(Criterion.builder().setKey("tag").setOperator(EQ).setValue("java").build()), | |||
singletonList(Criterion.builder().setKey("tags").setOperator(EQ).setValue("java").build()), | |||
emptySet()); | |||
assertThat(query.getTags().get()).containsOnly("java"); | |||
@@ -172,17 +172,17 @@ public class ProjectMeasuresQueryFactoryTest { | |||
@Test | |||
public void fail_to_create_query_on_tag_using_in_operator_and_value() throws Exception { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Tag should be set either by using 'tag = java' or 'tag IN (finance, platform)"); | |||
expectedException.expectMessage("Tags should be set either by using 'tags = java' or 'tags IN (finance, platform)"); | |||
newProjectMeasuresQuery(singletonList(Criterion.builder().setKey("tag").setOperator(IN).setValue("java").build()), emptySet()); | |||
newProjectMeasuresQuery(singletonList(Criterion.builder().setKey("tags").setOperator(IN).setValue("java").build()), emptySet()); | |||
} | |||
@Test | |||
public void fail_to_create_query_on_tag_using_eq_operator_and_values() throws Exception { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Tag should be set either by using 'tag = java' or 'tag IN (finance, platform)"); | |||
expectedException.expectMessage("Tags should be set either by using 'tags = java' or 'tags IN (finance, platform)"); | |||
newProjectMeasuresQuery(singletonList(Criterion.builder().setKey("tag").setOperator(EQ).setValues(asList("java")).build()), emptySet()); | |||
newProjectMeasuresQuery(singletonList(Criterion.builder().setKey("tags").setOperator(EQ).setValues(asList("java")).build()), emptySet()); | |||
} | |||
@Test |
@@ -307,7 +307,7 @@ public class SearchProjectsActionTest { | |||
insertProjectInDbAndEs(newProjectDto(organizationDto).setName("Sonar Markdown").setTags(singletonList("marketing"))); | |||
insertProjectInDbAndEs(newProjectDto(organizationDto).setName("Sonar Qube").setTags(newArrayList("offshore"))); | |||
insertMetrics(COVERAGE, NCLOC); | |||
request.setFilter("tag in (finance, offshore)"); | |||
request.setFilter("tags in (finance, offshore)"); | |||
SearchProjectsWsResponse result = call(request); | |||
@@ -42,6 +42,7 @@ public class ProjectsWsParameters { | |||
public static final String PARAM_DRY_RUN = "dryRun"; | |||
public static final String FILTER_LANGUAGES = "languages"; | |||
public static final String FILTER_TAGS = "tags"; | |||
private ProjectsWsParameters() { | |||
// static utils only |