]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9489 fix routing of docs in index rules
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 27 Jun 2017 20:13:38 +0000 (22:13 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 30 Jun 2017 08:58:10 +0000 (10:58 +0200)
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleDoc.java
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleExtensionDoc.java
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexer.java

index 5fd9c3c256072909e161ab6997b6013f33a3eae5..4eddf1685b497fd89960db01c4e067315d070e09 100644 (file)
@@ -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() {
index df14d9757eb57da772d48b05f62c7175690accf7..1cd6a8f8c63be717ea32710ccf8d1e7e97973b86 100644 (file)
@@ -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());
   }
index 94d6a38d84d03daeae75a6ce57ff58f10f5d6053..a13c452c811e26d0014ff1c99c8b41fdea7d99e3 100644 (file)
@@ -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) {
index c205a8af62942032234324236ae53ec7b8d80f51..21c0316a9ec5d5a2d77b831086e4fd04f757a33c 100644 (file)
@@ -44,7 +44,7 @@ public class RuleExtensionDoc extends BaseDoc {
 
   @Override
   public String getRouting() {
-    return null;
+    return getRuleKey().toString();
   }
 
   @Override
index adf9617d2e589ab4ed317dfc368f99127c595a36..ae950c9d135e2ced7ef2e40a3ab64cb7e45197f9 100644 (file)
@@ -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());
   }