*/
package org.sonar.server.qualityprofile;
-import javax.annotation.CheckForNull;
import org.sonar.db.qualityprofile.ActiveRuleKey;
public interface ActiveRule {
Inheritance inheritance();
- @CheckForNull
- ActiveRuleKey parentKey();
-
}
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
import java.util.Map;
-import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.server.qualityprofile.ActiveRule;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_CREATED_AT;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_INHERITANCE;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_KEY;
-import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_PARENT_KEY;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_PROFILE_KEY;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_REPOSITORY;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_RULE_KEY;
return this;
}
- @Override
- @CheckForNull
- public ActiveRuleKey parentKey() {
- String data = getNullableField(FIELD_ACTIVE_RULE_PARENT_KEY);
- if (data != null && !data.isEmpty()) {
- return ActiveRuleKey.parse(data);
- }
- return null;
- }
-
- public ActiveRuleDoc setParentKey(@Nullable String s) {
- setField(FIELD_ACTIVE_RULE_PARENT_KEY, s);
- return this;
- }
-
@Override
public long createdAt() {
return (Long) getField(FIELD_ACTIVE_RULE_CREATED_AT);
"r.plugin_rule_key",
"r.plugin_name",
"qp.kee",
- "profile_parent.kee",
"a.created_at",
"a.updated_at"
};
private static final String SQL_ALL = "SELECT " + StringUtils.join(FIELDS, ",") + " FROM active_rules a " +
"INNER JOIN rules_profiles qp ON qp.id=a.profile_id " +
- "INNER JOIN rules r ON r.id = a.rule_id " +
- "LEFT JOIN rules_profiles profile_parent ON profile_parent.kee=qp.parent_kee ";
+ "INNER JOIN rules r ON r.id = a.rule_id";
private static final String SQL_AFTER_DATE = SQL_ALL + " WHERE a.updated_at>?";
doc.setSeverity(SeverityUtil.getSeverityFromOrdinal(rs.getInt(1)));
String inheritance = rs.getString(2);
- if (inheritance != null) {
- doc.setInheritance(inheritance);
- } else {
- doc.setInheritance(ActiveRule.Inheritance.NONE.name());
- }
-
- String parentProfileKey = rs.getString(6);
- if (parentProfileKey != null) {
- doc.setParentKey(ActiveRuleKey.of(parentProfileKey, ruleKey).toString());
- } else {
- doc.setParentKey(null);
- }
-
- doc.setCreatedAt(rs.getLong(7));
- doc.setUpdatedAt(rs.getLong(8));
+ doc.setInheritance(inheritance == null ? ActiveRule.Inheritance.NONE.name() : inheritance);
+ doc.setCreatedAt(rs.getLong(6));
+ doc.setUpdatedAt(rs.getLong(7));
return doc;
}
public static final String FIELD_ACTIVE_RULE_INHERITANCE = "inheritance";
public static final String FIELD_ACTIVE_RULE_PROFILE_KEY = "profile";
public static final String FIELD_ACTIVE_RULE_SEVERITY = "severity";
- public static final String FIELD_ACTIVE_RULE_PARENT_KEY = "parentKey";
public static final String FIELD_ACTIVE_RULE_RULE_KEY = "ruleKey";
public static final String FIELD_ACTIVE_RULE_CREATED_AT = "createdAt";
public static final String FIELD_ACTIVE_RULE_UPDATED_AT = "updatedAt";
activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_PROFILE_KEY).docValues().build();
activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_INHERITANCE).docValues().build();
activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_SEVERITY).docValues().build();
- activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_PARENT_KEY).disableSearch().docValues().build();
activeRuleMapping.createLongField(RuleIndexDefinition.FIELD_ACTIVE_RULE_CREATED_AT);
activeRuleMapping.createLongField(RuleIndexDefinition.FIELD_ACTIVE_RULE_UPDATED_AT);
public static ActiveRuleDoc newDoc(ActiveRuleKey key) {
return new ActiveRuleDoc(key)
.setSeverity(Severity.CRITICAL)
- .setParentKey(null)
.setInheritance(null).setCreatedAt(150000000L)
.setUpdatedAt(160000000L);
}
ActiveRuleDocTesting.newDoc(activeRuleKey1).setSeverity(BLOCKER),
ActiveRuleDocTesting.newDoc(activeRuleKey2).setSeverity(MINOR),
// Profile 2 is a child a profile 1
- ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_1)).setSeverity(MAJOR)
- .setParentKey(activeRuleKey1.toString()).setInheritance(INHERITED.name()),
- ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_2)).setSeverity(BLOCKER)
- .setParentKey(activeRuleKey2.toString()).setInheritance(OVERRIDES.name()));
+ ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_1)).setSeverity(MAJOR).setInheritance(INHERITED.name()),
+ ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_2)).setSeverity(BLOCKER).setInheritance(OVERRIDES.name()));
// 0. Test base case
assertThat(tester.countDocuments(INDEX, TYPE_ACTIVE_RULE)).isEqualTo(4);
docs.add(ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(profileKey, RULE_KEY_1)).setSeverity(BLOCKER));
docs.add(ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(profileKey, RULE_KEY_2)).setSeverity(MAJOR));
}
- indexActiveRules(docs.toArray(new ActiveRuleDoc[]{}));
+ indexActiveRules(docs.toArray(new ActiveRuleDoc[] {}));
Map<String, Multimap<String, FacetValue>> stats = index.getStatsByProfileKeys(profileKeys);
assertThat(stats).hasSize(30);
indexRules(
RuleDocTesting.newDoc(RULE_KEY_1),
RuleDocTesting.newDoc(RULE_KEY_2),
- RuleDocTesting.newDoc(RuleKey.of("xoo", "removed")).setStatus(RuleStatus.REMOVED.name())
- );
+ RuleDocTesting.newDoc(RuleKey.of("xoo", "removed")).setStatus(RuleStatus.REMOVED.name()));
indexActiveRules(
ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY1, RULE_KEY_1)),
// Removed rule can still be activated for instance when removing the checkstyle plugin, active rules related on checkstyle are not
// removed
// because if the plugin is re-install, quality profiles using these rule are not changed.
- ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RuleKey.of("xoo", "removed")))
- );
+ ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RuleKey.of("xoo", "removed"))));
// 1. find by rule key
ActiveRuleDocTesting.newDoc(activeRuleKey2),
ActiveRuleDocTesting.newDoc(activeRuleKey3),
// Profile 2 is a child a profile 1
- ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_1))
- .setParentKey(activeRuleKey1.toString()).setInheritance(INHERITED.name()),
- ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_2))
- .setParentKey(activeRuleKey2.toString()).setInheritance(OVERRIDES.name()),
- ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_3))
- .setParentKey(activeRuleKey3.toString()).setInheritance(INHERITED.name()));
+ ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_1)).setInheritance(INHERITED.name()),
+ ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_2)).setInheritance(OVERRIDES.name()),
+ ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_3)).setInheritance(INHERITED.name()));
// 0. get all rules
assertThat(index.search(new RuleQuery(), new SearchOptions()).getIds())