@Override
public ActiveRule.Inheritance inheritance() {
String inheritance = (String) this.fields.get(ActiveRuleNormalizer.ActiveRuleField.INHERITANCE.key());
- if(inheritance == null || inheritance.isEmpty()){
+ if(inheritance == null || inheritance.isEmpty() ||
+ inheritance.toLowerCase().contains("none")){
return Inheritance.NONE;
- } else if(inheritance.toLowerCase().indexOf("herit") > 0) {
+ } else if(inheritance.toLowerCase().contains("herit")) {
return Inheritance.INHERIT;
- } else if(inheritance.toLowerCase().indexOf("over") > 0) {
+ } else if(inheritance.toLowerCase().contains("over")) {
return Inheritance.OVERRIDE;
} else {
throw new IllegalStateException("Value \"" +inheritance+"\" is not valid for rule's inheritance");
import org.sonar.core.persistence.DbSession;
import org.sonar.core.rule.RuleDto;
import org.sonar.server.db.DbClient;
+import org.sonar.server.qualityprofile.ActiveRule;
+import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
import org.sonar.server.rule2.index.RuleIndex;
import org.sonar.server.rule2.index.RuleNormalizer;
import org.sonar.server.rule2.index.RuleQuery;
public class RuleService implements ServerComponent {
private final RuleIndex index;
+ private final ActiveRuleIndex activeRuleIndex;
private final DbClient db;
- public RuleService(RuleIndex index, DbClient db) {
+ public RuleService(ActiveRuleIndex activeRuleIndex, RuleIndex index, DbClient db) {
this.index = index;
+ this.activeRuleIndex = activeRuleIndex;
this.db = db;
}
// keep only supported fields and add the fields to always return
options.filterFieldsToReturn(RuleIndex.PUBLIC_FIELDS);
options.addFieldsToReturn(RuleNormalizer.RuleField.REPOSITORY.key(), RuleNormalizer.RuleField.KEY.key());
- return index.search(query, options);
+
+ RuleResult result = index.search(query, options);
+ for(Rule rule:result.getHits()){
+ for(ActiveRule activeRule:activeRuleIndex.findByRule(rule.key())){
+ result.getActiveRules().put(rule.key().toString(),activeRule);
+ }
+ }
+ return result;
}
/**
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import org.elasticsearch.action.search.SearchResponse;
-import org.sonar.server.qualityprofile.index.ActiveRuleDoc;
+import org.sonar.server.qualityprofile.ActiveRule;
import org.sonar.server.rule2.Rule;
import org.sonar.server.search.Result;
public class RuleResult extends Result<Rule> {
- private Multimap<String,ActiveRuleDoc> activeRules;
+ private Multimap<String,ActiveRule> activeRules;
public RuleResult(SearchResponse response) {
super(response);
return super.getHits();
}
- public Multimap<String,ActiveRuleDoc> getActiveRules() {
+ public Multimap<String,ActiveRule> getActiveRules() {
return this.activeRules;
}
}
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
-import org.junit.Ignore;
import org.junit.Test;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
@Test
- @Ignore
- //FIXME
public void search_active_rules() throws Exception {
QualityProfileDto profile = newQualityProfile();
tester.get(QualityProfileDao.class).insert(profile, session);
}
@Test
- @Ignore
- //FIXME
public void search_active_rules_params() throws Exception {
QualityProfileDto profile = newQualityProfile();
tester.get(QualityProfileDao.class).insert(profile, session);
ActiveRuleParamDto activeRuleParam = ActiveRuleParamDto.createFor(param)
.setValue("The VALUE");
tester.get(ActiveRuleDao.class).addParam(activeRule, activeRuleParam, session);
+
+ ActiveRuleParamDto activeRuleParam2 = ActiveRuleParamDto.createFor(param2)
+ .setValue("The Other Value");
+ tester.get(ActiveRuleDao.class).addParam(activeRule, activeRuleParam2, session);
session.commit();
tester.get(RuleService.class).refresh();
-{"total": 1,"p":1,"ps":25, "rules": [
- {
- "key": "java:S001",
- "repo": "java",
- "lang": "js",
- "name": "Rule S001",
- "htmlDesc": "Description S001",
- "status": "READY",
- "template": false,
- "internalKey": "InternalKeyS001",
- "severity": "INFO",
- "tags": [],
- "sysTags": [],
- "debtRemediationFunctionType": "LINEAR",
- "debtRemediationFunctionCoefficient": "1h",
- "debtRemediationFunctionOffset": "5min",
- "params": [
- {
- "key": "my_var",
- "desc": "My small description",
- "defaultValue": "some value"
- }
- ],
- "actives": [
- {
- "key": "My Profile:java:java:S001",
- "inherit": "NONE",
- "severity": "BLOCKER",
- "params": [
- {
- "key": "my_var",
- "value": "The VALUE"
- }
- ]
- }
- ]
- }
-]}
+{
+ "p": 1,
+ "ps": 25,
+ "rules": [
+ {
+ "actives": [
+ {
+ "inherit": "NONE",
+ "key": "My Profile:java:java:S001",
+ "params": [
+ {
+ "key": "the_var",
+ "value": "The Other Value"
+ },
+ {
+ "key": "my_var",
+ "value": "The VALUE"
+ }
+ ],
+ "severity": "BLOCKER"
+ }
+ ],
+ "debtRemediationFunctionCoefficient": "1h",
+ "debtRemediationFunctionOffset": "5min",
+ "debtRemediationFunctionType": "LINEAR",
+ "htmlDesc": "Description S001",
+ "internalKey": "InternalKeyS001",
+ "key": "java:S001",
+ "lang": "js",
+ "name": "Rule S001",
+ "params": [
+ {
+ "defaultValue": "some value",
+ "desc": "My small description",
+ "key": "my_var"
+ },
+ {
+ "defaultValue": "other value",
+ "desc": "My small description",
+ "key": "the_var"
+ }
+ ],
+ "repo": "java",
+ "severity": "INFO",
+ "status": "READY",
+ "sysTags": [],
+ "tags": [],
+ "template": false
+ }
+ ],
+ "total": 1
+}