private String repository;
private String key;
private String ruleProfileUuid;
+ private Boolean prioritizedRule;
public IndexedActiveRuleDto() {
// nothing to do here
public String getRuleProfileUuid() {
return ruleProfileUuid;
}
+
+ public Boolean getPrioritizedRule() {
+ return prioritizedRule;
+ }
}
import com.google.common.collect.Maps;
import java.util.Map;
+import java.util.Optional;
+import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.server.es.BaseDoc;
import org.sonar.server.qualityprofile.ActiveRuleInheritance;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_PROFILE_UUID;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_SEVERITY;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_UUID;
+import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_PRIORITIZED_RULE;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_RULE_UUID;
import static org.sonar.server.rule.index.RuleIndexDefinition.TYPE_ACTIVE_RULE;
return this;
}
+ ActiveRuleDoc setPrioritizedRule(@Nullable Boolean b) {
+ Boolean notNull = Optional.ofNullable(b).orElse(Boolean.FALSE);
+ setField(FIELD_PRIORITIZED_RULE, notNull);
+ return this;
+ }
+
ActiveRuleInheritance getInheritance() {
String inheritance = getNullableField(FIELD_ACTIVE_RULE_INHERITANCE);
if (inheritance == null || inheritance.isEmpty() ||
ActiveRuleDoc doc = new ActiveRuleDoc(dto.getUuid())
.setRuleUuid(dto.getRuleUuid())
.setRuleProfileUuid(dto.getRuleProfileUuid())
- .setSeverity(SeverityUtil.getSeverityFromOrdinal(dto.getSeverity()));
+ .setSeverity(SeverityUtil.getSeverityFromOrdinal(dto.getSeverity()))
+ .setPrioritizedRule(dto.getPrioritizedRule());
// all the fields must be present, even if value is null
String inheritance = dto.getInheritance();
doc.setInheritance(inheritance == null ? ActiveRuleInheritance.NONE.name() : inheritance);
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_INHERITANCE;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_PROFILE_UUID;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_SEVERITY;
+import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_PRIORITIZED_RULE;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_RULE_CLEAN_CODE_ATTRIBUTE_CATEGORY;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_RULE_CREATED_AT;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_RULE_CWE;
addTermFilter(activeRuleFilter, FIELD_ACTIVE_RULE_PROFILE_UUID, profile.getRulesProfileUuid());
addTermFilter(activeRuleFilter, FIELD_ACTIVE_RULE_INHERITANCE, query.getInheritance());
addTermFilter(activeRuleFilter, FIELD_ACTIVE_RULE_SEVERITY, query.getActiveSeverities());
+ addTermFilter(activeRuleFilter, FIELD_PRIORITIZED_RULE, query.getPrioritizedRule());
// ChildQuery
QueryBuilder childQuery;
return filter;
}
+ private static BoolQueryBuilder addTermFilter(BoolQueryBuilder filter, String field, @Nullable Boolean value) {
+ if (value != null) {
+ filter.must(QueryBuilders.termQuery(field, value));
+ }
+ return filter;
+ }
+
private static Map<String, AggregationBuilder> getFacets(RuleQuery query, SearchOptions options, QueryBuilder queryBuilder,
Map<String, QueryBuilder> filters) {
Map<String, AggregationBuilder> aggregations = new HashMap<>();
public static final String SUB_FIELD_SEVERITY = "severity";
public static final String FIELD_RULE_IMPACT_SOFTWARE_QUALITY = FIELD_RULE_IMPACTS + "." + SUB_FIELD_SOFTWARE_QUALITY;
public static final String FIELD_RULE_IMPACT_SEVERITY = FIELD_RULE_IMPACTS + "." + SUB_FIELD_SEVERITY;
+ public static final String FIELD_PRIORITIZED_RULE = "activeRule_prioritizedRule";
private final Configuration config;
private final boolean enableSource;
.keywordFieldBuilder(FIELD_ACTIVE_RULE_UUID).disableNorms().build()
.keywordFieldBuilder(FIELD_ACTIVE_RULE_PROFILE_UUID).disableNorms().build()
.keywordFieldBuilder(FIELD_ACTIVE_RULE_INHERITANCE).disableNorms().build()
- .keywordFieldBuilder(FIELD_ACTIVE_RULE_SEVERITY).disableNorms().build();
+ .keywordFieldBuilder(FIELD_ACTIVE_RULE_SEVERITY).disableNorms().build()
+ .createBooleanField(FIELD_PRIORITIZED_RULE);
}
}
private Collection<String> impactSeverities;
private Collection<String> impactSoftwareQualities;
private Collection<String> cleanCodeAttributesCategories;
+ private Boolean prioritizedRule;
@CheckForNull
return this;
}
+ @Nullable
+ public Boolean getPrioritizedRule() {
+ return prioritizedRule;
+ }
+
+ public RuleQuery setPrioritizedRule(@Nullable Boolean prioritizedRule) {
+ this.prioritizedRule = prioritizedRule;
+ return this;
+ }
}
assertThat(def.since()).isEqualTo("4.4");
assertThat(def.isInternal()).isFalse();
assertThat(def.responseExampleAsString()).isNotEmpty();
- assertThat(def.params()).hasSize(31);
+ assertThat(def.params()).hasSize(32);
WebService.Param compareToProfile = def.param("compareToProfile");
assertThat(compareToProfile.since()).isEqualTo("6.5");
import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_LANGUAGES;
import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_OWASP_TOP_10;
import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_OWASP_TOP_10_2021;
+import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_PRIORITIZED_RULE;
import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_QPROFILE;
import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_REPOSITORIES;
import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_RULE_KEY;
public RuleQuery createRuleSearchQuery(DbSession dbSession, Request request) {
RuleQuery query = createRuleQuery(dbSession, request);
query.setIncludeExternal(request.mandatoryParamAsBoolean(PARAM_INCLUDE_EXTERNAL));
+ query.setPrioritizedRule(request.paramAsBoolean(PARAM_PRIORITIZED_RULE));
return query;
}
import org.sonar.server.security.SecurityStandards.SQCategory;
import org.sonar.server.user.UserSession;
+import static java.lang.String.format;
import static org.sonar.api.server.ws.WebService.Param.ASCENDING;
import static org.sonar.api.server.ws.WebService.Param.SORT;
import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_LANGUAGES;
import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_OWASP_TOP_10;
import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_OWASP_TOP_10_2021;
+import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_PRIORITIZED_RULE;
import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_QPROFILE;
import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_REPOSITORIES;
import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_RULE_KEY;
.setSince("7.2");
}
+ static void definePrioritizedRuleParam(WebService.NewAction action) {
+ action
+ .createParam(PARAM_PRIORITIZED_RULE)
+ .setDescription(format("Filter on prioritized rules. Ignored if the parameter '%s' is not set.", PARAM_QPROFILE))
+ .setBooleanPossibleValues()
+ .setSince("10.6");
+ }
+
}
public static final String PARAM_IMPACT_SOFTWARE_QUALITIES = "impactSoftwareQualities";
public static final String PARAM_IMPACT_SEVERITIES = "impactSeverities";
public static final String PARAM_CLEAN_CODE_ATTRIBUTE_CATEGORIES = "cleanCodeAttributeCategories";
+ public static final String PARAM_PRIORITIZED_RULE = "prioritizedRule";
public static final String FIELD_REPO = "repo";
public static final String FIELD_NAME = "name";
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
+import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.api.issue.impact.SoftwareQuality;
import org.sonar.api.rule.Severity;
import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_LANGUAGES;
import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_OWASP_TOP_10;
import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_OWASP_TOP_10_2021;
+import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_PRIORITIZED_RULE;
import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_REPOSITORIES;
import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_SANS_TOP_25;
import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_SEVERITIES;
.addPagingParams(100, MAX_PAGE_SIZE)
.setHandler(this)
.setChangelog(
+ new Change("10.6", format("Parameter '%s has been added", PARAM_PRIORITIZED_RULE)),
new Change("5.5", "The field 'effortToFixDescription' has been deprecated, use 'gapDescription' instead"),
new Change("5.5", "The field 'debtRemFnCoeff' has been deprecated, use 'remFnGapMultiplier' instead"),
new Change("5.5", "The field 'defaultDebtRemFnCoeff' has been deprecated, use 'defaultRemFnGapMultiplier' instead"),
// Rule-specific search parameters
RuleWsSupport.defineGenericRuleSearchParameters(action);
RuleWsSupport.defineIsExternalParam(action);
+ RuleWsSupport.definePrioritizedRuleParam(action);
}
@Override
.setOwaspTop10(request.paramAsStrings(PARAM_OWASP_TOP_10))
.setOwaspTop10For2021(request.paramAsStrings(PARAM_OWASP_TOP_10_2021))
.setSansTop25(request.paramAsStrings(PARAM_SANS_TOP_25))
- .setSonarsourceSecurity(request.paramAsStrings(PARAM_SONARSOURCE_SECURITY));
+ .setSonarsourceSecurity(request.paramAsStrings(PARAM_SONARSOURCE_SECURITY))
+ .setPrioritizedRule(request.paramAsBoolean(PARAM_PRIORITIZED_RULE));
}
private static class SearchRequest {
private List<String> impactSeverities;
private List<String> impactSoftwareQualities;
private List<String> cleanCodeAttributesCategories;
+ private Boolean prioritizedRule;
private SearchRequest setActiveSeverities(List<String> activeSeverities) {
this.activeSeverities = activeSeverities;
this.cleanCodeAttributesCategories = cleanCodeAttributesCategories;
return this;
}
+
+ @CheckForNull
+ public Boolean getPrioritizedRule() {
+ return prioritizedRule;
+ }
+
+ public SearchRequest setPrioritizedRule(@Nullable Boolean prioritizedRule) {
+ this.prioritizedRule = prioritizedRule;
+ return this;
+ }
}
}