*
*/
private static final String PARAM_NAMEORKEY = "nameOrKey";
+ private static final String PARAM_STATUS = "status";
private static final String INDEX_RULES = "rules";
private static final String TYPE_RULE = "rule";
if (params.containsKey(PARAM_NAMEORKEY)) {
searchQuery.searchString(params.remove(PARAM_NAMEORKEY));
}
+ if (! params.containsKey(PARAM_STATUS)) {
+ searchQuery.notField(PARAM_STATUS, Rule.STATUS_REMOVED);
+ }
for(Map.Entry<String, String> param: params.entrySet()) {
searchQuery.field(param.getKey(), param.getValue().split("\\|"));
private List<String> indices;
private List<String> types;
private Multimap<String, String> fieldCriteria;
+ private Multimap<String, String> notFieldCriteria;
private Map<String, String> termFacets;
private SearchQuery() {
indices = Lists.newArrayList();
types = Lists.newArrayList();
fieldCriteria = ArrayListMultimap.create();
+ notFieldCriteria = ArrayListMultimap.create();
termFacets = Maps.newHashMap();
}
return this;
}
+ public SearchQuery notField(String fieldName, String... fieldValues) {
+ notFieldCriteria.putAll(fieldName, Lists.newArrayList(fieldValues));
+ return this;
+ }
+
public SearchQuery facet(String facetName, String fieldName) {
termFacets.put(facetName, fieldName);
return this;
if (StringUtils.isNotBlank(searchString)) {
filters.add(queryFilter(QueryBuilders.queryString(searchString)));
}
+
for (String field: fieldCriteria.keySet()) {
if (fieldCriteria.get(field).size() > 1) {
filters.add(termsFilter(field, fieldCriteria.get(field)));
}
}
+ for (String field: notFieldCriteria.keySet()) {
+ if (notFieldCriteria.get(field).size() > 1) {
+ filters.add(notFilter(termsFilter(field, notFieldCriteria.get(field))));
+ } else {
+ filters.add(notFilter(termFilter(field, notFieldCriteria.get(field))));
+ }
+ }
+
if (filters.isEmpty()) {
builder.setFilter(matchAllFilter());
} else if(filters.size() == 1) {
conditions << "id IN (:ids)"
values[:ids] = Array(Internal.rules.findIds(params))
-=begin TODO Correctly handle status != STATUS_REMOVED
- status = options[:status]
- if status.blank?
- conditions << ['status <> :status']
- values[:status] = STATUS_REMOVED
- elsif status == 'ACTIVE' || status == 'INACTIVE'
- # For retro compatibility for the Sqale plugin
- # To be removed when SonarQube version will no more be compatible with SQALE version < 1.10
- options[:activation] = status
- conditions << ['status <> :status']
- values[:status] = STATUS_REMOVED
- else
- conditions << "status IN (:status)"
- values[:status] = options[:status]
- end
-=end
-
includes=(options[:include_parameters_and_notes] ? [:rules_parameters, :rule_note] : nil)
rules = Rule.all(:include => includes, :conditions => [conditions.join(" AND "), values])
rules = Rule.sort_by(rules, options[:sort_by])
String source1 = IOUtils.toString(TestUtils.getResource(getClass(), "rules/rule1.json").toURI());
String source2 = IOUtils.toString(TestUtils.getResource(getClass(), "rules/rule2.json").toURI());
+ String source3 = IOUtils.toString(TestUtils.getResource(getClass(), "rules/rule3.json").toURI());
esSetup.execute(
EsSetup.index("rules", "rule", "1").withSource(source1),
- EsSetup.index("rules", "rule", "2").withSource(source2)
+ EsSetup.index("rules", "rule", "2").withSource(source2),
+ EsSetup.index("rules", "rule", "3").withSource(source3)
);
}
}
@Test
- public void should_find_all_rule_ids() {
-
+ public void should_filter_removed_rules() {
assertThat(registry.findIds(new HashMap<String, String>())).containsOnly(1, 2);
}
@Test
- public void should_filter_on_name_or_key() throws Exception {
+ public void should_display_disabled_rule() {
+ assertThat(registry.findIds(ImmutableMap.of("status", "BETA|REMOVED"))).containsOnly(2, 3);
+ }
+ @Test
+ public void should_filter_on_name_or_key() throws Exception {
assertThat(registry.findIds(ImmutableMap.of("nameOrKey", "parameters"))).containsOnly(1);
}
@Test
public void should_filter_on_key() throws Exception {
-
assertThat(registry.findIds(ImmutableMap.of("key", "OneIssuePerLine"))).containsOnly(2);
}
"parentKey": null,
"repositoryKey": "xoo",
"severity": "MAJOR",
- "status": "READY",
+ "status": "BETA",
"createdAt": "2013-10-28T13:07:26.339Z",
"updatedAt": "2013-11-08T10:52:53.487Z"
}
--- /dev/null
+{
+ "id": 1,
+ "key": "RemobedRule",
+ "language": "xoo",
+ "name": "Removed rule",
+ "description": "Removed rule that should be filtered out in default query",
+ "parentKey": null,
+ "repositoryKey": "xoo",
+ "severity": "CRITICAL",
+ "status": "REMOVED",
+ "createdAt": "2013-10-28T13:07:26.329Z",
+ "updatedAt": "2013-11-08T10:52:53.473Z"
+}