From: Simon Brandhof Date: Tue, 27 Jun 2017 20:13:38 +0000 (+0200) Subject: SONAR-9489 fix routing of docs in index rules X-Git-Tag: 6.5-M2~60 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=90e2bc7b5149d2d64a1987a11cf50dfce1b8457d;p=sonarqube.git SONAR-9489 fix routing of docs in index rules --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java index 5fd9c3c2560..4eddf1685b4 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java @@ -51,7 +51,7 @@ public class ActiveRuleDoc extends BaseDoc { @Override public String getRouting() { - return null; + return getRuleKeyAsString(); } @Override @@ -60,7 +60,11 @@ public class ActiveRuleDoc extends BaseDoc { } RuleKey getRuleKey() { - return RuleKey.parse(getField(FIELD_ACTIVE_RULE_RULE_KEY)); + return RuleKey.parse(getRuleKeyAsString()); + } + + private String getRuleKeyAsString() { + return getField(FIELD_ACTIVE_RULE_RULE_KEY); } String getRuleRepository() { diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java index df14d9757eb..1cd6a8f8c63 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java @@ -88,7 +88,7 @@ public class ActiveRuleIndexer implements StartupIndexer { .filter(c -> c.getActiveRule() != null) .forEach(c -> { if (c.getType().equals(ActiveRuleChange.Type.DEACTIVATED)) { - bulk.addDeletion(INDEX_TYPE_ACTIVE_RULE, String.valueOf(c.getActiveRule().getId())); + bulk.addDeletion(INDEX_TYPE_ACTIVE_RULE, String.valueOf(c.getActiveRule().getId()), c.getKey().getRuleKey().toString()); } else { idsOfTouchedActiveRules.add(c.getActiveRule().getId()); } @@ -129,7 +129,9 @@ public class ActiveRuleIndexer implements StartupIndexer { } private static IndexRequest newIndexRequest(ActiveRuleDoc doc) { - return new IndexRequest(INDEX_TYPE_ACTIVE_RULE.getIndex(), INDEX_TYPE_ACTIVE_RULE.getType(), doc.getId()) + return new IndexRequest(INDEX_TYPE_ACTIVE_RULE.getIndex(), INDEX_TYPE_ACTIVE_RULE.getType()) + .id(doc.getId()) + .routing(doc.getRouting()) .parent(doc.getRuleKey().toString()) .source(doc.getFields()); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleDoc.java b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleDoc.java index 94d6a38d84d..a13c452c811 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleDoc.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleDoc.java @@ -49,7 +49,7 @@ public class RuleDoc extends BaseDoc { @Override public String getRouting() { - return null; + return keyAsString(); } @Override @@ -58,7 +58,11 @@ public class RuleDoc extends BaseDoc { } public RuleKey key() { - return RuleKey.parse(this.getField(RuleIndexDefinition.FIELD_RULE_KEY)); + return RuleKey.parse(keyAsString()); + } + + private String keyAsString() { + return getField(RuleIndexDefinition.FIELD_RULE_KEY); } public RuleDoc setKey(@Nullable String s) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleExtensionDoc.java b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleExtensionDoc.java index c205a8af629..21c0316a9ec 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleExtensionDoc.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleExtensionDoc.java @@ -44,7 +44,7 @@ public class RuleExtensionDoc extends BaseDoc { @Override public String getRouting() { - return null; + return getRuleKey().toString(); } @Override diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexer.java b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexer.java index adf9617d2e5..ae950c9d135 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexer.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexer.java @@ -123,11 +123,16 @@ public class RuleIndexer implements StartupIndexer { } private static IndexRequest newIndexRequest(RuleDoc rule) { - return new IndexRequest(INDEX_TYPE_RULE.getIndex(), INDEX_TYPE_RULE.getType(), rule.key().toString()).source(rule.getFields()); + return new IndexRequest(INDEX_TYPE_RULE.getIndex(), INDEX_TYPE_RULE.getType()) + .id(rule.getId()) + .routing(rule.getRouting()) + .source(rule.getFields()); } private static IndexRequest newIndexRequest(RuleExtensionDoc ruleExtension) { - return new IndexRequest(INDEX_TYPE_RULE_EXTENSION.getIndex(), INDEX_TYPE_RULE_EXTENSION.getType(), ruleExtension.getId()) + return new IndexRequest(INDEX_TYPE_RULE_EXTENSION.getIndex(), INDEX_TYPE_RULE_EXTENSION.getType()) + .id(ruleExtension.getId()) + .routing(ruleExtension.getRouting()) .source(ruleExtension.getFields()) .parent(ruleExtension.getParent()); }