]> source.dussan.org Git - sonarqube.git/commitdiff
Do not store _source in index rules/activeRule
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 16 May 2016 11:32:55 +0000 (13:32 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 16 May 2016 12:26:38 +0000 (14:26 +0200)
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java

index 12cee53358e082fe433dfe9ce7b01a2c3480f374..5be909fa23b7bb6c20966801e030d92042e1282a 100644 (file)
  */
 package org.sonar.server.qualityprofile.index;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Maps;
-import java.util.Map;
 import javax.annotation.Nullable;
 import org.sonar.db.qualityprofile.ActiveRuleKey;
 import org.sonar.server.qualityprofile.ActiveRule;
 import org.sonar.server.search.BaseDoc;
 
+import static com.google.common.base.Preconditions.checkNotNull;
 import static org.apache.commons.lang.StringUtils.containsIgnoreCase;
 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;
@@ -37,19 +36,13 @@ import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_
 import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_SEVERITY;
 import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_UPDATED_AT;
 
-public class ActiveRuleDoc extends BaseDoc implements ActiveRule {
+public class ActiveRuleDoc extends BaseDoc {
 
   private final ActiveRuleKey key;
 
-  public ActiveRuleDoc(Map<String, Object> fields) {
-    super(fields);
-    this.key = ActiveRuleKey.parse((String) getField(FIELD_ACTIVE_RULE_KEY));
-    Preconditions.checkArgument(key != null, "ActiveRuleKey cannot be null");
-  }
-
   public ActiveRuleDoc(ActiveRuleKey key) {
     super(Maps.<String, Object>newHashMapWithExpectedSize(8));
-    Preconditions.checkNotNull(key, "ActiveRuleKey cannot be null");
+    checkNotNull(key, "ActiveRuleKey cannot be null");
     this.key = key;
     setField(FIELD_ACTIVE_RULE_KEY, key.toString());
     setField(FIELD_ACTIVE_RULE_PROFILE_KEY, key.qProfile());
@@ -57,13 +50,11 @@ public class ActiveRuleDoc extends BaseDoc implements ActiveRule {
     setField(FIELD_ACTIVE_RULE_REPOSITORY, key.ruleKey().repository());
   }
 
-  @Override
   public ActiveRuleKey key() {
     return key;
   }
 
-  @Override
-  public String severity() {
+  String severity() {
     return (String) getNullableField(FIELD_ACTIVE_RULE_SEVERITY);
   }
 
@@ -72,16 +63,15 @@ public class ActiveRuleDoc extends BaseDoc implements ActiveRule {
     return this;
   }
 
-  @Override
-  public ActiveRule.Inheritance inheritance() {
+  ActiveRule.Inheritance inheritance() {
     String inheritance = getNullableField(FIELD_ACTIVE_RULE_INHERITANCE);
     if (inheritance == null || inheritance.isEmpty() ||
       containsIgnoreCase(inheritance, "none")) {
-      return Inheritance.NONE;
+      return ActiveRule.Inheritance.NONE;
     } else if (containsIgnoreCase(inheritance, "herit")) {
-      return Inheritance.INHERITED;
+      return ActiveRule.Inheritance.INHERITED;
     } else if (containsIgnoreCase(inheritance, "over")) {
-      return Inheritance.OVERRIDES;
+      return ActiveRule.Inheritance.OVERRIDES;
     } else {
       throw new IllegalStateException("Value \"" + inheritance + "\" is not valid for rule's inheritance");
     }
@@ -92,8 +82,7 @@ public class ActiveRuleDoc extends BaseDoc implements ActiveRule {
     return this;
   }
 
-  @Override
-  public long createdAt() {
+  long createdAt() {
     return (Long) getField(FIELD_ACTIVE_RULE_CREATED_AT);
   }
 
@@ -102,8 +91,7 @@ public class ActiveRuleDoc extends BaseDoc implements ActiveRule {
     return this;
   }
 
-  @Override
-  public long updatedAt() {
+  long updatedAt() {
     return (Long) getField(FIELD_ACTIVE_RULE_UPDATED_AT);
   }
 
index e42975c7a9d8a1b1b3468643459535baf7289299..eb8e554d2d5958646d83a1aa1ac057cb760926f0 100644 (file)
@@ -110,6 +110,7 @@ public class RuleIndexDefinition implements IndexDefinition {
 
     // Active rule type
     NewIndex.NewIndexType activeRuleMapping = index.createType(RuleIndexDefinition.TYPE_ACTIVE_RULE);
+    activeRuleMapping.setEnableSource(false);
     activeRuleMapping.setAttribute("_id", ImmutableMap.of("path", RuleIndexDefinition.FIELD_ACTIVE_RULE_KEY));
     activeRuleMapping.setAttribute("_parent", ImmutableMap.of("type", RuleIndexDefinition.TYPE_RULE));
     activeRuleMapping.setAttribute("_routing", ImmutableMap.of("required", true, "path", RuleIndexDefinition.FIELD_ACTIVE_RULE_REPOSITORY));