]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7330 drop RuleNormalizer and RuleMapping
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 1 Mar 2016 08:26:04 +0000 (09:26 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 1 Mar 2016 13:27:28 +0000 (14:27 +0100)
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapper.java
server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapping.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java
server/sonar-server/src/main/java/org/sonar/server/search/ws/SearchOptions.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleMappingTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java
sonar-ws/src/main/java/org/sonarqube/ws/client/rule/RulesWsParameters.java [new file with mode: 0644]
sonar-ws/src/main/java/org/sonarqube/ws/client/rule/package-info.java [new file with mode: 0644]

index 8462ff54dd2df2188debe3e8cd40209623516f53..f30c6d0e2bc5f44e388b36458de565afd0881469 100644 (file)
@@ -262,7 +262,6 @@ import org.sonar.server.rule.index.RuleIndexer;
 import org.sonar.server.rule.ws.ActiveRuleCompleter;
 import org.sonar.server.rule.ws.RepositoriesAction;
 import org.sonar.server.rule.ws.RuleMapper;
-import org.sonar.server.rule.ws.RuleMapping;
 import org.sonar.server.rule.ws.RulesWs;
 import org.sonar.server.rule.ws.TagsAction;
 import org.sonar.server.source.HtmlSourceDecorator;
@@ -458,7 +457,6 @@ public class PlatformLevel4 extends PlatformLevel {
       org.sonar.server.rule.ws.DeleteAction.class,
       org.sonar.server.rule.ws.ListAction.class,
       TagsAction.class,
-      RuleMapping.class,
       RuleMapper.class,
       ActiveRuleCompleter.class,
       RepositoriesAction.class,
diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java
deleted file mode 100644 (file)
index 442e04a..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.rule.index;
-
-import com.google.common.collect.ImmutableSet;
-import java.util.Set;
-import org.sonar.server.search.IndexField;
-import org.sonar.server.search.Indexable;
-
-/**
- * Only used by RuleMapping and RuleMapper, should be removed
- */
-@Deprecated
-public class RuleNormalizer {
-
-  public static final String UPDATED_AT_FIELD = "updatedAt";
-
-  public static final class RuleParamField extends Indexable {
-
-    public static final IndexField NAME = add(IndexField.Type.STRING, "name");
-    public static final IndexField TYPE = add(IndexField.Type.STRING, "type");
-    public static final IndexField DESCRIPTION = addSearchable(IndexField.Type.TEXT, "description");
-    public static final IndexField DEFAULT_VALUE = add(IndexField.Type.STRING, "defaultValue");
-
-    public static final Set<IndexField> ALL_FIELDS = ImmutableSet.of(NAME, TYPE, DESCRIPTION, DEFAULT_VALUE);
-  }
-
-  public static final class RuleField extends Indexable {
-
-    /**
-     * @deprecated because key should be used instead of id. This field is kept for compatibility with
-     * SQALE console.
-     */
-    @Deprecated
-    public static final IndexField ID = addSortable(IndexField.Type.DOUBLE, "id");
-
-    public static final IndexField KEY = addSortable(IndexField.Type.STRING, "key");
-    public static final IndexField _KEY = add(IndexField.Type.STRING, "_key");
-    public static final IndexField REPOSITORY = add(IndexField.Type.STRING, "repo");
-    public static final IndexField RULE_KEY = add(IndexField.Type.STRING, "ruleKey");
-
-    public static final IndexField NAME = addSortableAndSearchable(IndexField.Type.STRING, "name");
-    public static final IndexField CREATED_AT = addSortable(IndexField.Type.DATE, "createdAt");
-    public static final IndexField UPDATED_AT = addSortable(IndexField.Type.DATE, UPDATED_AT_FIELD);
-    public static final IndexField HTML_DESCRIPTION = addSearchable(IndexField.Type.TEXT, "htmlDesc");
-    public static final IndexField MARKDOWN_DESCRIPTION = add(IndexField.Type.TEXT, "mdDesc");
-    public static final IndexField SEVERITY = add(IndexField.Type.STRING, "severity");
-    public static final IndexField STATUS = add(IndexField.Type.STRING, "status");
-    public static final IndexField FIX_DESCRIPTION = add(IndexField.Type.STRING, "effortToFix");
-    public static final IndexField LANGUAGE = add(IndexField.Type.STRING, "lang");
-    public static final IndexField TAGS = add(IndexField.Type.STRING, "tags");
-    public static final IndexField SYSTEM_TAGS = add(IndexField.Type.STRING, "sysTags");
-    public static final IndexField INTERNAL_KEY = add(IndexField.Type.STRING, "internalKey");
-    public static final IndexField IS_TEMPLATE = add(IndexField.Type.BOOLEAN, "isTemplate");
-    public static final IndexField TEMPLATE_KEY = add(IndexField.Type.STRING, "templateKey");
-
-    public static final IndexField DEFAULT_CHARACTERISTIC = add(IndexField.Type.STRING, "_debtChar");
-    public static final IndexField DEFAULT_SUB_CHARACTERISTIC = add(IndexField.Type.STRING, "_debtSubChar");
-    public static final IndexField DEFAULT_DEBT_FUNCTION_TYPE = add(IndexField.Type.STRING, "_debtRemFnType");
-    public static final IndexField DEFAULT_DEBT_FUNCTION_COEFFICIENT = add(IndexField.Type.STRING, "_debtRemFnCoefficient");
-    public static final IndexField DEFAULT_DEBT_FUNCTION_OFFSET = add(IndexField.Type.STRING, "_debtRemFnOffset");
-
-    public static final IndexField CHARACTERISTIC = add(IndexField.Type.STRING, "debtChar");
-    public static final IndexField SUB_CHARACTERISTIC = add(IndexField.Type.STRING, "debtSubChar");
-    public static final IndexField DEBT_FUNCTION_TYPE = add(IndexField.Type.STRING, "debtRemFnType");
-    public static final IndexField DEBT_FUNCTION_COEFFICIENT = add(IndexField.Type.STRING, "debtRemFnCoefficient");
-    public static final IndexField DEBT_FUNCTION_OFFSET = add(IndexField.Type.STRING, "debtRemFnOffset");
-
-    public static final IndexField CHARACTERISTIC_OVERLOADED = add(IndexField.Type.BOOLEAN, "debtCharOverloaded");
-    public static final IndexField SUB_CHARACTERISTIC_OVERLOADED = add(IndexField.Type.BOOLEAN, "debtSubCharOverloaded");
-    public static final IndexField DEBT_FUNCTION_TYPE_OVERLOADED = add(IndexField.Type.BOOLEAN, "debtRemFnTypeOverloaded");
-
-    public static final IndexField NOTE = add(IndexField.Type.TEXT, "markdownNote");
-    public static final IndexField NOTE_LOGIN = add(IndexField.Type.STRING, "noteLogin");
-    public static final IndexField NOTE_CREATED_AT = add(IndexField.Type.DATE, "noteCreatedAt");
-    public static final IndexField NOTE_UPDATED_AT = add(IndexField.Type.DATE, "noteUpdatedAt");
-    public static final IndexField ALL_TAGS = addSearchable(IndexField.Type.STRING, "allTags");
-    public static final IndexField PARAMS = addEmbedded("params", RuleParamField.ALL_FIELDS);
-
-    public static final Set<IndexField> ALL_FIELDS = ImmutableSet.of(ID, KEY, _KEY, REPOSITORY, RULE_KEY, NAME, CREATED_AT,
-      UPDATED_AT, HTML_DESCRIPTION, MARKDOWN_DESCRIPTION, SEVERITY, STATUS, FIX_DESCRIPTION,
-      LANGUAGE, TAGS, SYSTEM_TAGS, INTERNAL_KEY, IS_TEMPLATE, TEMPLATE_KEY, DEFAULT_DEBT_FUNCTION_TYPE,
-      DEFAULT_DEBT_FUNCTION_COEFFICIENT, DEFAULT_DEBT_FUNCTION_OFFSET, DEBT_FUNCTION_TYPE, DEBT_FUNCTION_COEFFICIENT,
-      DEBT_FUNCTION_OFFSET, DEFAULT_CHARACTERISTIC, DEFAULT_SUB_CHARACTERISTIC, CHARACTERISTIC, SUB_CHARACTERISTIC,
-      DEBT_FUNCTION_TYPE_OVERLOADED, CHARACTERISTIC_OVERLOADED, SUB_CHARACTERISTIC_OVERLOADED,
-      NOTE, NOTE_LOGIN, NOTE_CREATED_AT, NOTE_UPDATED_AT, ALL_TAGS, PARAMS);
-
-    /**
-     * Warning - O(n) complexity
-     */
-    public static IndexField of(String fieldName) {
-      for (IndexField field : ALL_FIELDS) {
-        if (field.field().equals(fieldName)) {
-          return field;
-        }
-      }
-      throw new IllegalStateException("Could not find an IndexField for '" + fieldName + "'");
-    }
-  }
-
-}
index bbb6cbf112a5211d84c45d552fafcb060febb78d..0afad0b787033c2a11d4e01517f949c89b8f0ac8 100644 (file)
@@ -31,15 +31,33 @@ import org.sonar.api.server.debt.DebtRemediationFunction;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.db.rule.RuleParamDto;
 import org.sonar.markdown.Markdown;
-import org.sonar.server.rule.index.RuleNormalizer;
 import org.sonar.server.rule.ws.SearchAction.SearchResult;
-import org.sonar.server.search.IndexField;
 import org.sonar.server.text.MacroInterpreter;
 import org.sonarqube.ws.Common;
 import org.sonarqube.ws.Rules;
 
 import static java.lang.String.format;
 import static org.sonar.api.utils.DateUtils.formatDateTime;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_CREATED_AT;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_DEBT_OVERLOADED;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_DEBT_REM_FUNCTION;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_DEFAULT_DEBT_REM_FUNCTION;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_EFFORT_TO_FIX_DESCRIPTION;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_HTML_DESCRIPTION;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_INTERNAL_KEY;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_IS_TEMPLATE;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_LANGUAGE;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_LANGUAGE_NAME;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_MARKDOWN_DESCRIPTION;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_NAME;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_NOTE_LOGIN;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_PARAMS;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_REPO;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_SEVERITY;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_STATUS;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_SYSTEM_TAGS;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_TAGS;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.FIELD_TEMPLATE_KEY;
 
 /**
  * Conversion of {@link org.sonar.db.rule.RuleDto} to {@link org.sonarqube.ws.Rules.Rule}
@@ -85,25 +103,25 @@ public class RuleMapper {
   }
 
   private static void setRepository(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.REPOSITORY)) {
+    if (shouldReturnField(fieldsToReturn, FIELD_REPO)) {
       ruleResponse.setRepo(ruleDto.getKey().repository());
     }
   }
 
   private static void setEffortToFixDescription(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.FIX_DESCRIPTION) && ruleDto.getEffortToFixDescription() != null) {
+    if (shouldReturnField(fieldsToReturn, FIELD_EFFORT_TO_FIX_DESCRIPTION) && ruleDto.getEffortToFixDescription() != null) {
       ruleResponse.setEffortToFixDescription(ruleDto.getEffortToFixDescription());
     }
   }
 
   private static void setIsDebtOverloaded(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, "debtOverloaded")) {
+    if (shouldReturnField(fieldsToReturn, FIELD_DEBT_OVERLOADED)) {
       ruleResponse.setDebtOverloaded(ruleToOverloaded(ruleDto));
     }
   }
 
   private static void setDefaultDebtRemediationFunctionFields(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, "defaultDebtRemFn")) {
+    if (shouldReturnField(fieldsToReturn, FIELD_DEFAULT_DEBT_REM_FUNCTION)) {
       DebtRemediationFunction defaultDebtRemediationFunction = defaultDebtRemediationFunction(ruleDto);
       if (defaultDebtRemediationFunction != null) {
         if (defaultDebtRemediationFunction.coefficient() != null) {
@@ -120,7 +138,7 @@ public class RuleMapper {
   }
 
   private static void setDebtRemediationFunctionFields(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, "debtRemFn")) {
+    if (shouldReturnField(fieldsToReturn, FIELD_DEBT_REM_FUNCTION)) {
       DebtRemediationFunction debtRemediationFunction = debtRemediationFunction(ruleDto);
       if (debtRemediationFunction != null) {
         if (debtRemediationFunction.type() != null) {
@@ -137,31 +155,31 @@ public class RuleMapper {
   }
 
   private static void setName(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.NAME) && ruleDto.getName() != null) {
+    if (shouldReturnField(fieldsToReturn, FIELD_NAME) && ruleDto.getName() != null) {
       ruleResponse.setName(ruleDto.getName());
     }
   }
 
   private static void setStatus(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.STATUS) && ruleDto.getStatus() != null) {
+    if (shouldReturnField(fieldsToReturn, FIELD_STATUS) && ruleDto.getStatus() != null) {
       ruleResponse.setStatus(Common.RuleStatus.valueOf(ruleDto.getStatus().toString()));
     }
   }
 
   private static void setTags(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.TAGS)) {
+    if (shouldReturnField(fieldsToReturn, FIELD_TAGS)) {
       ruleResponse.getTagsBuilder().addAllTags(ruleDto.getTags());
     }
   }
 
   private static void setSysTags(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.SYSTEM_TAGS)) {
+    if (shouldReturnField(fieldsToReturn, FIELD_SYSTEM_TAGS)) {
       ruleResponse.getSysTagsBuilder().addAllSysTags(ruleDto.getSystemTags());
     }
   }
 
   private static void setParams(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, SearchResult searchResult, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.PARAMS)) {
+    if (shouldReturnField(fieldsToReturn, FIELD_PARAMS)) {
       List<RuleParamDto> ruleParameters = searchResult.getRuleParamsByRuleId().get(ruleDto.getId());
       ruleResponse.getParamsBuilder().addAllParams(FluentIterable.from(ruleParameters)
         .transform(RuleParamDtoToWsRuleParam.INSTANCE)
@@ -170,13 +188,13 @@ public class RuleMapper {
   }
 
   private static void setCreatedAt(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.CREATED_AT)) {
+    if (shouldReturnField(fieldsToReturn, FIELD_CREATED_AT)) {
       ruleResponse.setCreatedAt(formatDateTime(ruleDto.getCreatedAt()));
     }
   }
 
   private void setDescriptionFields(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.HTML_DESCRIPTION)) {
+    if (shouldReturnField(fieldsToReturn, FIELD_HTML_DESCRIPTION)) {
       String description = ruleDto.getDescription();
       if (description != null) {
         switch (ruleDto.getDescriptionFormat()) {
@@ -192,7 +210,7 @@ public class RuleMapper {
       }
     }
 
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.MARKDOWN_DESCRIPTION) && ruleDto.getDescription() != null) {
+    if (shouldReturnField(fieldsToReturn, FIELD_MARKDOWN_DESCRIPTION) && ruleDto.getDescription() != null) {
       ruleResponse.setMdDesc(ruleDto.getDescription());
     }
   }
@@ -204,31 +222,31 @@ public class RuleMapper {
     if (shouldReturnField(fieldsToReturn, "mdNote") && ruleDto.getNoteData() != null) {
       ruleResponse.setMdNote(ruleDto.getNoteData());
     }
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.NOTE_LOGIN) && ruleDto.getNoteUserLogin() != null) {
+    if (shouldReturnField(fieldsToReturn, FIELD_NOTE_LOGIN) && ruleDto.getNoteUserLogin() != null) {
       ruleResponse.setNoteLogin(ruleDto.getNoteUserLogin());
     }
   }
 
   private static void setSeverity(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.SEVERITY) && ruleDto.getSeverityString() != null) {
+    if (shouldReturnField(fieldsToReturn, FIELD_SEVERITY) && ruleDto.getSeverityString() != null) {
       ruleResponse.setSeverity(ruleDto.getSeverityString());
     }
   }
 
   private static void setInternalKey(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.INTERNAL_KEY) && ruleDto.getConfigKey() != null) {
+    if (shouldReturnField(fieldsToReturn, FIELD_INTERNAL_KEY) && ruleDto.getConfigKey() != null) {
       ruleResponse.setInternalKey(ruleDto.getConfigKey());
     }
   }
 
   private static void setLanguage(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.LANGUAGE) && ruleDto.getLanguage() != null) {
+    if (shouldReturnField(fieldsToReturn, FIELD_LANGUAGE) && ruleDto.getLanguage() != null) {
       ruleResponse.setLang(ruleDto.getLanguage());
     }
   }
 
   private void setLanguageName(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, "langName") && ruleDto.getLanguage() != null) {
+    if (shouldReturnField(fieldsToReturn, FIELD_LANGUAGE_NAME) && ruleDto.getLanguage() != null) {
       String languageKey = ruleDto.getLanguage();
       Language language = languages.get(languageKey);
       ruleResponse.setLangName(language == null ? languageKey : language.getName());
@@ -236,13 +254,13 @@ public class RuleMapper {
   }
 
   private static void setIsTemplate(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.IS_TEMPLATE)) {
+    if (shouldReturnField(fieldsToReturn, FIELD_IS_TEMPLATE)) {
       ruleResponse.setIsTemplate(ruleDto.isTemplate());
     }
   }
 
   private static void setTemplateKey(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, SearchResult result, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.TEMPLATE_KEY) && ruleDto.getTemplateId() != null) {
+    if (shouldReturnField(fieldsToReturn, FIELD_TEMPLATE_KEY) && ruleDto.getTemplateId() != null) {
       RuleDto templateRule = result.getTemplateRulesByRuleId().get(ruleDto.getTemplateId());
       if (templateRule != null) {
         ruleResponse.setTemplateKey(templateRule.getKey().toString());
@@ -250,10 +268,6 @@ public class RuleMapper {
     }
   }
 
-  private static boolean shouldReturnField(Set<String> fieldsToReturn, IndexField field) {
-    return fieldsToReturn.isEmpty() || fieldsToReturn.contains(field.field());
-  }
-
   private static boolean shouldReturnField(Set<String> fieldsToReturn, String fieldName) {
     return fieldsToReturn.isEmpty() || fieldsToReturn.contains(fieldName);
   }
diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapping.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapping.java
deleted file mode 100644 (file)
index ada259a..0000000
+++ /dev/null
@@ -1,348 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.rule.ws;
-
-import com.google.common.base.Function;
-import java.util.Collections;
-import java.util.Set;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import org.sonar.api.resources.Language;
-import org.sonar.api.resources.Languages;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.server.debt.DebtRemediationFunction;
-import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.markdown.Markdown;
-import org.sonar.server.rule.Rule;
-import org.sonar.server.rule.RuleParam;
-import org.sonar.server.rule.index.RuleDoc;
-import org.sonar.server.rule.index.RuleNormalizer;
-import org.sonar.server.search.IndexField;
-import org.sonar.server.search.QueryContext;
-import org.sonar.server.search.ws.BaseMapping;
-import org.sonar.server.text.MacroInterpreter;
-import org.sonarqube.ws.Common;
-import org.sonarqube.ws.Rules;
-
-import static com.google.common.collect.FluentIterable.from;
-import static org.sonar.api.utils.DateUtils.formatDateTime;
-
-/**
- * Conversion of {@link org.sonar.server.rule.index.RuleDoc} to WS JSON document
- */
-public class RuleMapping extends BaseMapping<RuleDoc, RuleMappingContext> {
-
-  private final Languages languages;
-  private final MacroInterpreter macroInterpreter;
-
-  public RuleMapping(final Languages languages, final MacroInterpreter macroInterpreter) {
-    super();
-    this.languages = languages;
-    this.macroInterpreter = macroInterpreter;
-
-    mapBasicFields();
-    mapDescriptionFields();
-    mapDebtFields();
-    mapParamFields();
-  }
-
-  private void mapBasicFields() {
-    map("repo", RuleNormalizer.RuleField.REPOSITORY.field());
-    map("name", RuleNormalizer.RuleField.NAME.field());
-    mapDateTime("createdAt", RuleNormalizer.RuleField.CREATED_AT.field());
-    map("severity", RuleNormalizer.RuleField.SEVERITY.field());
-    map("status", RuleNormalizer.RuleField.STATUS.field());
-    map("internalKey", RuleNormalizer.RuleField.INTERNAL_KEY.field());
-    mapBoolean("isTemplate", RuleNormalizer.RuleField.IS_TEMPLATE.field());
-    map("templateKey", RuleNormalizer.RuleField.TEMPLATE_KEY.field());
-    mapArray("tags", RuleNormalizer.RuleField.TAGS.field());
-    mapArray("sysTags", RuleNormalizer.RuleField.SYSTEM_TAGS.field());
-    map("lang", RuleNormalizer.RuleField.LANGUAGE.field());
-    map("langName", RuleNormalizer.RuleField.LANGUAGE.field());
-  }
-
-  private void mapDescriptionFields() {
-    map("htmlDesc", RuleNormalizer.RuleField.HTML_DESCRIPTION.field());
-    map("mdDesc", RuleNormalizer.RuleField.MARKDOWN_DESCRIPTION.field());
-    map("noteLogin", RuleNormalizer.RuleField.NOTE_LOGIN.field());
-    map("mdNote", RuleNormalizer.RuleField.NOTE.field());
-    map("htmlNote", RuleNormalizer.RuleField.NOTE.field());
-  }
-
-  private void mapDebtFields() {
-    map("defaultDebtChar", new IndexStringMapper("defaultDebtChar", RuleNormalizer.RuleField.DEFAULT_CHARACTERISTIC.field()));
-    map("defaultDebtSubChar", new IndexStringMapper("defaultDebtSubChar", RuleNormalizer.RuleField.DEFAULT_SUB_CHARACTERISTIC.field()));
-    map("debtChar", RuleNormalizer.RuleField.CHARACTERISTIC.field());
-    map("debtSubChar", RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field());
-
-    map("debtCharName", RuleNormalizer.RuleField.CHARACTERISTIC.field());
-    map("debtSubCharName", RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field());
-
-    map("defaultDebtRemFn", new IndexStringMapper("defaultDebtRemFnType", RuleNormalizer.RuleField.DEFAULT_DEBT_FUNCTION_TYPE.field()));
-    map("defaultDebtRemFn", new IndexStringMapper("defaultDebtRemFnCoeff", RuleNormalizer.RuleField.DEFAULT_DEBT_FUNCTION_COEFFICIENT.field()));
-    map("defaultDebtRemFn", new IndexStringMapper("defaultDebtRemFnOffset", RuleNormalizer.RuleField.DEFAULT_DEBT_FUNCTION_OFFSET.field()));
-    map("effortToFixDescription", RuleNormalizer.RuleField.FIX_DESCRIPTION.field());
-    map("debtOverloaded", new SimpleMapper(
-      RuleNormalizer.RuleField.DEBT_FUNCTION_TYPE_OVERLOADED.field()));
-
-    map("debtRemFn", new IndexStringMapper("debtRemFnType", RuleNormalizer.RuleField.DEBT_FUNCTION_TYPE.field()));
-    map("debtRemFn", new IndexStringMapper("debtRemFnCoeff", RuleNormalizer.RuleField.DEBT_FUNCTION_COEFFICIENT.field()));
-    map("debtRemFn", new IndexStringMapper("debtRemFnOffset", RuleNormalizer.RuleField.DEBT_FUNCTION_OFFSET.field()));
-  }
-
-  private void mapParamFields() {
-    map("params", RuleNormalizer.RuleField.PARAMS.field());
-  }
-
-  public Rules.Rule buildRuleResponse(Rule ruleDoc, @Nullable QueryContext queryContext) {
-    Rules.Rule.Builder ruleResponse = Rules.Rule.newBuilder();
-    Set<String> fieldsToReturn = fieldsToReturn(queryContext);
-
-    ruleResponse.setKey(ruleDoc.key().toString());
-    setRepository(ruleResponse, ruleDoc, fieldsToReturn);
-    setName(ruleResponse, ruleDoc, fieldsToReturn);
-    setStatus(ruleResponse, ruleDoc, fieldsToReturn);
-    setTags(ruleResponse, ruleDoc, fieldsToReturn);
-    setSysTags(ruleResponse, ruleDoc, fieldsToReturn);
-    setParams(ruleResponse, ruleDoc, fieldsToReturn);
-    setCreatedAt(ruleResponse, ruleDoc, fieldsToReturn);
-    setDescriptionFields(ruleResponse, ruleDoc, fieldsToReturn);
-    setNotesFields(ruleResponse, ruleDoc, fieldsToReturn);
-    setSeverity(ruleResponse, ruleDoc, fieldsToReturn);
-    setInternalKey(ruleResponse, ruleDoc, fieldsToReturn);
-    setLanguage(ruleResponse, ruleDoc, fieldsToReturn);
-    setLanguageName(ruleResponse, ruleDoc, fieldsToReturn);
-    setIsTemplate(ruleResponse, ruleDoc, fieldsToReturn);
-    setTemplateKey(ruleResponse, ruleDoc, fieldsToReturn);
-    setDebtRemediationFunctionFields(ruleResponse, ruleDoc, fieldsToReturn);
-    setDefaultDebtRemediationFunctionFields(ruleResponse, ruleDoc, fieldsToReturn);
-    setIsDebtOverloaded(ruleResponse, ruleDoc, fieldsToReturn);
-    setEffortToFixDescription(ruleResponse, ruleDoc, fieldsToReturn);
-
-    return ruleResponse.build();
-  }
-
-  private static void setRepository(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.REPOSITORY)) {
-      ruleResponse.setRepo(ruleDoc.key().repository());
-    }
-  }
-
-  private static void setEffortToFixDescription(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.FIX_DESCRIPTION) && ruleDoc.effortToFixDescription() != null) {
-      ruleResponse.setEffortToFixDescription(ruleDoc.effortToFixDescription());
-    }
-  }
-
-  private static void setIsDebtOverloaded(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, "debtOverloaded")) {
-      ruleResponse.setDebtOverloaded(ruleToOverloaded(ruleDoc));
-    }
-  }
-
-  private static void setDefaultDebtRemediationFunctionFields(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, "defaultDebtRemFn")) {
-      DebtRemediationFunction defaultDebtRemediationFunction = ruleDoc.defaultDebtRemediationFunction();
-      if (defaultDebtRemediationFunction != null) {
-        if (defaultDebtRemediationFunction.coefficient() != null) {
-          ruleResponse.setDefaultDebtRemFnCoeff(defaultDebtRemediationFunction.coefficient());
-        }
-        if (defaultDebtRemediationFunction.offset() != null) {
-          ruleResponse.setDefaultDebtRemFnOffset(defaultDebtRemediationFunction.offset());
-        }
-        if (defaultDebtRemediationFunction.type() != null) {
-          ruleResponse.setDefaultDebtRemFnType(defaultDebtRemediationFunction.type().name());
-        }
-      }
-    }
-  }
-
-  private static void setDebtRemediationFunctionFields(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, "debtRemFn")) {
-      DebtRemediationFunction debtRemediationFunction = ruleDoc.debtRemediationFunction();
-      if (debtRemediationFunction != null) {
-        if (debtRemediationFunction.type() != null) {
-          ruleResponse.setDebtRemFnType(debtRemediationFunction.type().name());
-        }
-        if (debtRemediationFunction.coefficient() != null) {
-          ruleResponse.setDebtRemFnCoeff(debtRemediationFunction.coefficient());
-        }
-        if (debtRemediationFunction.offset() != null) {
-          ruleResponse.setDebtRemFnOffset(debtRemediationFunction.offset());
-        }
-      }
-    }
-  }
-
-  private static Set<String> fieldsToReturn(@Nullable QueryContext queryContext) {
-    return queryContext == null ? Collections.<String>emptySet() : queryContext.getFieldsToReturn();
-  }
-
-  private static void setName(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.NAME) && ruleDoc.name() != null) {
-      ruleResponse.setName(ruleDoc.name());
-    }
-  }
-
-  private static void setStatus(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.STATUS) && ruleDoc.status() != null) {
-      ruleResponse.setStatus(Common.RuleStatus.valueOf(ruleDoc.status().toString()));
-    }
-  }
-
-  private static void setTags(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.TAGS)) {
-      ruleResponse.getTagsBuilder().addAllTags(ruleDoc.tags());
-    }
-  }
-
-  private static void setSysTags(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.SYSTEM_TAGS)) {
-      ruleResponse.getSysTagsBuilder().addAllSysTags(ruleDoc.systemTags());
-    }
-  }
-
-  private static void setParams(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.PARAMS)) {
-      ruleResponse.getParamsBuilder().addAllParams(from(ruleDoc.params())
-        .transform(RuleParamToResponseRuleParam.INSTANCE)
-        .toList());
-    }
-  }
-
-  private static void setCreatedAt(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.CREATED_AT) && ruleDoc.createdAt() != null) {
-      ruleResponse.setCreatedAt(formatDateTime(ruleDoc.createdAt()));
-    }
-  }
-
-  private void setDescriptionFields(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.HTML_DESCRIPTION)) {
-      if (ruleDoc.markdownDescription() != null) {
-        ruleResponse.setHtmlDesc(macroInterpreter.interpret(Markdown.convertToHtml(ruleDoc.markdownDescription())));
-      } else if (ruleDoc.htmlDescription() != null) {
-        ruleResponse.setHtmlDesc(macroInterpreter.interpret(ruleDoc.htmlDescription()));
-      }
-    }
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.MARKDOWN_DESCRIPTION) && ruleDoc.markdownDescription() != null) {
-      ruleResponse.setMdDesc(ruleDoc.markdownDescription());
-    }
-  }
-
-  private void setNotesFields(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, "htmlNote") && ruleDoc.markdownNote() != null) {
-      ruleResponse.setHtmlNote(macroInterpreter.interpret(Markdown.convertToHtml(ruleDoc.markdownNote())));
-    }
-    if (shouldReturnField(fieldsToReturn, "mdNote") && ruleDoc.markdownNote() != null) {
-      ruleResponse.setMdNote(ruleDoc.markdownNote());
-    }
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.NOTE_LOGIN) && ruleDoc.noteLogin() != null) {
-      ruleResponse.setNoteLogin(ruleDoc.noteLogin());
-    }
-  }
-
-  private static void setSeverity(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.SEVERITY) && ruleDoc.severity() != null) {
-      ruleResponse.setSeverity(ruleDoc.severity());
-    }
-  }
-
-  private static void setInternalKey(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.INTERNAL_KEY) && ruleDoc.internalKey() != null) {
-      ruleResponse.setInternalKey(ruleDoc.internalKey());
-    }
-  }
-
-  private static void setLanguage(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.LANGUAGE) && ruleDoc.language() != null) {
-      ruleResponse.setLang(ruleDoc.language());
-    }
-  }
-
-  private void setLanguageName(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, "langName") && ruleDoc.language() != null) {
-      String languageKey = ruleDoc.language();
-      Language language = languages.get(languageKey);
-      ruleResponse.setLangName(language == null ? languageKey : language.getName());
-    }
-  }
-
-  private static void setIsTemplate(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.IS_TEMPLATE)) {
-      ruleResponse.setIsTemplate(ruleDoc.isTemplate());
-    }
-  }
-
-  private static void setTemplateKey(Rules.Rule.Builder ruleResponse, Rule ruleDoc, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.TEMPLATE_KEY) && ruleDoc.templateKey() != null) {
-      RuleKey templateKey = ruleDoc.templateKey();
-      if (templateKey != null) {
-        ruleResponse.setTemplateKey(templateKey.toString());
-      }
-    }
-  }
-
-  private static boolean shouldReturnField(Set<String> fieldsToReturn, IndexField field) {
-    return fieldsToReturn.isEmpty() || fieldsToReturn.contains(field.field());
-  }
-
-  private static boolean shouldReturnField(Set<String> fieldsToReturn, String fieldName) {
-    return fieldsToReturn.isEmpty() || fieldsToReturn.contains(fieldName);
-  }
-
-  private static boolean ruleToOverloaded(Rule rule) {
-    return rule.debtOverloaded();
-  }
-
-  private static class SimpleMapper extends IndexMapper<RuleDoc, RuleMappingContext> {
-    private SimpleMapper(String... fields) {
-      super(fields);
-    }
-
-    @Override
-    public void write(JsonWriter json, RuleDoc doc, RuleMappingContext context) {
-      // do not do anything
-    }
-  }
-
-  private enum RuleParamToResponseRuleParam implements Function<RuleParam, Rules.Rule.Param> {
-    INSTANCE;
-
-    @Override
-    public Rules.Rule.Param apply(@Nonnull RuleParam param) {
-      Rules.Rule.Param.Builder paramResponse = Rules.Rule.Param.newBuilder();
-      paramResponse.setKey(param.key());
-      if (param.description() != null) {
-        paramResponse.setHtmlDesc(Markdown.convertToHtml(param.description()));
-      }
-      if (param.defaultValue() != null) {
-        paramResponse.setDefaultValue(param.defaultValue());
-      }
-      if (param.type() != null) {
-        paramResponse.setType(param.type().type());
-      }
-
-      return paramResponse.build();
-    }
-  }
-}
-
-class RuleMappingContext {
-}
index 15638cd310dbe09bde1a6eeeb46d167638967179..91251371d10d484c24f774cd3db9da5b182d1c7a 100644 (file)
@@ -23,7 +23,6 @@ import com.google.common.base.Function;
 import com.google.common.base.Predicates;
 import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableList.Builder;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.ListMultimap;
 import com.google.common.collect.Lists;
@@ -60,7 +59,6 @@ import org.sonar.server.rule.Rule;
 import org.sonar.server.rule.index.RuleIndex;
 import org.sonar.server.rule.index.RuleIndexDefinition;
 import org.sonar.server.rule.index.RuleQuery;
-import org.sonar.server.search.ws.SearchOptions;
 import org.sonarqube.ws.Common;
 import org.sonarqube.ws.Rules.SearchResponse;
 
@@ -74,6 +72,22 @@ import static org.sonar.server.rule.index.RuleIndex.FACET_SEVERITIES;
 import static org.sonar.server.rule.index.RuleIndex.FACET_STATUSES;
 import static org.sonar.server.rule.index.RuleIndex.FACET_TAGS;
 import static org.sonar.server.ws.WsUtils.writeProtobuf;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.OPTIONAL_FIELDS;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_ACTIVATION;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_ACTIVE_SEVERITIES;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_AVAILABLE_SINCE;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_DEBT_CHARACTERISTICS;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_HAS_DEBT_CHARACTERISTIC;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_INHERITANCE;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_IS_TEMPLATE;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_KEY;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_LANGUAGES;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_QPROFILE;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_REPOSITORIES;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_SEVERITIES;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_STATUSES;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_TAGS;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_TEMPLATE_KEY;
 
 /**
  * @since 4.4
@@ -81,34 +95,16 @@ import static org.sonar.server.ws.WsUtils.writeProtobuf;
 public class SearchAction implements RulesWsAction {
   public static final String ACTION = "search";
 
-  public static final String PARAM_REPOSITORIES = "repositories";
-  public static final String PARAM_KEY = "rule_key";
-  public static final String PARAM_ACTIVATION = "activation";
-  public static final String PARAM_QPROFILE = "qprofile";
-  public static final String PARAM_SEVERITIES = "severities";
-  public static final String PARAM_AVAILABLE_SINCE = "available_since";
-  public static final String PARAM_STATUSES = "statuses";
-  public static final String PARAM_LANGUAGES = "languages";
-  public static final String PARAM_DEBT_CHARACTERISTICS = "debt_characteristics";
-  public static final String PARAM_HAS_DEBT_CHARACTERISTIC = "has_debt_characteristic";
-  public static final String PARAM_TAGS = "tags";
-  public static final String PARAM_INHERITANCE = "inheritance";
-  public static final String PARAM_ACTIVE_SEVERITIES = "active_severities";
-  public static final String PARAM_IS_TEMPLATE = "is_template";
-  public static final String PARAM_TEMPLATE_KEY = "template_key";
-
   private static final Collection<String> DEFAULT_FACETS = ImmutableSet.of(PARAM_LANGUAGES, PARAM_REPOSITORIES, "tags");
 
   private final DbClient dbClient;
   private final RuleIndex ruleIndex;
   private final ActiveRuleCompleter activeRuleCompleter;
-  private final RuleMapping mapping;
   private final RuleMapper mapper;
 
-  public SearchAction(RuleIndex ruleIndex, ActiveRuleCompleter activeRuleCompleter, RuleMapping mapping, DbClient dbClient, RuleMapper mapper) {
+  public SearchAction(RuleIndex ruleIndex, ActiveRuleCompleter activeRuleCompleter, DbClient dbClient, RuleMapper mapper) {
     this.ruleIndex = ruleIndex;
     this.activeRuleCompleter = activeRuleCompleter;
-    this.mapping = mapping;
     this.dbClient = dbClient;
     this.mapper = mapper;
   }
@@ -128,16 +124,13 @@ public class SearchAction implements RulesWsAction {
       paramFacets.setExampleValue(String.format("%s,%s", it.next(), it.next()));
     }
 
-    Collection<String> possibleFields = possibleFields();
     WebService.NewParam paramFields = action.createParam(Param.FIELDS)
       .setDescription("Comma-separated list of the fields to be returned in response. All the fields are returned by default, except actives.")
-      .setPossibleValues(possibleFields);
-    if (possibleFields != null && possibleFields.size() > 1) {
-      Iterator<String> it = possibleFields.iterator();
-      paramFields.setExampleValue(String.format("%s,%s", it.next(), it.next()));
-    }
+      .setPossibleValues(OPTIONAL_FIELDS);
+    Iterator<String> it = OPTIONAL_FIELDS.iterator();
+    paramFields.setExampleValue(String.format("%s,%s", it.next(), it.next()));
 
-    this.doDefinition(action);
+    doDefinition(action);
   }
 
   @Override
@@ -189,8 +182,7 @@ public class SearchAction implements RulesWsAction {
       FACET_SEVERITIES,
       FACET_ACTIVE_SEVERITIES,
       FACET_STATUSES,
-      FACET_OLD_DEFAULT
-      );
+      FACET_OLD_DEFAULT);
   }
 
   /**
@@ -333,7 +325,7 @@ public class SearchAction implements RulesWsAction {
   protected org.sonar.server.es.SearchOptions getQueryContext(Request request) {
     // TODO Get rid of this horrible hack: fields on request are not the same as fields for ES search ! 1/2
     org.sonar.server.es.SearchOptions context = loadCommonContext(request);
-    org.sonar.server.es.SearchOptions searchQueryContext = mapping.newQueryOptions(SearchOptions.create(request))
+    org.sonar.server.es.SearchOptions searchQueryContext = new org.sonar.server.es.SearchOptions()
       .setLimit(context.getLimit())
       .setOffset(context.getOffset());
     if (context.getFacets().contains(RuleIndex.FACET_OLD_DEFAULT)) {
@@ -416,12 +408,6 @@ public class SearchAction implements RulesWsAction {
     }
   }
 
-  protected Collection<String> possibleFields() {
-    Builder<String> builder = ImmutableList.builder();
-    builder.addAll(mapping.supportedFields());
-    return builder.add("actives").build();
-  }
-
   protected void writeFacets(SearchResponse.Builder response, Request request, org.sonar.server.es.SearchOptions context, SearchResult results) {
     addMandatoryFacetValues(results, FACET_LANGUAGES, request.paramAsStrings(PARAM_LANGUAGES));
     addMandatoryFacetValues(results, FACET_REPOSITORIES, request.paramAsStrings(PARAM_REPOSITORIES));
index a6acba4bc82ca5f07b53db8a0958a6183eef6c60..be75b06e49fd23643957d44f5f6c674c4458dde6 100644 (file)
@@ -42,6 +42,19 @@ public class SearchOptions {
   private int page;
   private List<String> fields;
 
+  public static SearchOptions create(Request request) {
+    SearchOptions options = new SearchOptions();
+
+    // both parameters have default values
+    options.setPage(request.mandatoryParamAsInt(WebService.Param.PAGE));
+    options.setPageSize(request.mandatoryParamAsInt(WebService.Param.PAGE_SIZE));
+
+    // optional field
+    options.setFields(request.paramAsStrings(WebService.Param.FIELDS));
+
+    return options;
+  }
+
   public int pageSize() {
     return pageSize;
   }
@@ -86,19 +99,6 @@ public class SearchOptions {
     return this;
   }
 
-  public static SearchOptions create(Request request) {
-    SearchOptions options = new SearchOptions();
-
-    // both parameters have default values
-    options.setPage(request.mandatoryParamAsInt(WebService.Param.PAGE));
-    options.setPageSize(request.mandatoryParamAsInt(WebService.Param.PAGE_SIZE));
-
-    // optional field
-    options.setFields(request.paramAsStrings(WebService.Param.FIELDS));
-
-    return options;
-  }
-
   public static void defineFieldsParam(WebService.NewAction action, @Nullable Collection<String> possibleFields) {
     WebService.NewParam newParam = action
       .createParam(WebService.Param.FIELDS)
index 919d00838966f2ab3e4d7ca00a2d49b37761b3b3..54599516283007c921c48370855656a734ccf6a4 100644 (file)
@@ -48,13 +48,13 @@ import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
 import org.sonar.server.rule.index.RuleIndex;
 import org.sonar.server.rule.index.RuleIndexer;
 import org.sonar.server.rule.index.RuleQuery;
-import org.sonar.server.rule.ws.SearchAction;
 import org.sonar.server.tester.ServerTester;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsTester;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.fail;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_LANGUAGES;
 
 public class QProfilesWsMediumTest {
 
@@ -281,7 +281,7 @@ public class QProfilesWsMediumTest {
     // 1. Activate Rule
     WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_ACTIVATE_ACTION);
     request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey());
-    request.setParam(SearchAction.PARAM_LANGUAGES, "java");
+    request.setParam(PARAM_LANGUAGES, "java");
     WsTester.Result result = request.execute();
     session.clearCache();
 
@@ -306,7 +306,7 @@ public class QProfilesWsMediumTest {
     // 1. Activate Rule
     WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_ACTIVATE_ACTION);
     request.setParam(RuleActivationActions.PROFILE_KEY, php.getKey());
-    request.setParam(SearchAction.PARAM_LANGUAGES, "php");
+    request.setParam(PARAM_LANGUAGES, "php");
     WsTester.Result result = request.execute();
     session.clearCache();
 
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleMappingTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleMappingTest.java
deleted file mode 100644 (file)
index 314833d..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.rule.ws;
-
-import org.junit.Test;
-import org.sonar.api.resources.Languages;
-import org.sonar.api.server.ws.WebService.Param;
-import org.sonar.api.server.ws.internal.SimpleGetRequest;
-import org.sonar.server.rule.index.RuleNormalizer;
-import org.sonar.server.search.ws.SearchOptions;
-import org.sonar.server.text.MacroInterpreter;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-public class RuleMappingTest {
-
-  Languages languages = new Languages();
-  MacroInterpreter macroInterpreter = mock(MacroInterpreter.class);
-
-  @Test
-  public void toQueryOptions_load_all_fields() {
-    RuleMapping mapping = new RuleMapping(languages, macroInterpreter);
-    SimpleGetRequest request = new SimpleGetRequest();
-    request.setParam(Param.PAGE, "1");
-    request.setParam(Param.PAGE_SIZE, "10");
-    org.sonar.server.es.SearchOptions queryContext = mapping.newQueryOptions(SearchOptions.create(request));
-
-    assertThat(queryContext.getFields()).isEmpty();
-  }
-
-  @Test
-  public void toQueryOptions_load_only_few_simple_fields() {
-    RuleMapping mapping = new RuleMapping(languages, macroInterpreter);
-    SimpleGetRequest request = new SimpleGetRequest();
-    request.setParam(Param.PAGE, "1");
-    request.setParam(Param.PAGE_SIZE, "10");
-    request.setParam(Param.FIELDS, "repo,name,lang");
-    org.sonar.server.es.SearchOptions queryContext = mapping.newQueryOptions(SearchOptions.create(request));
-
-    assertThat(queryContext.getFields()).containsOnly(
-      RuleNormalizer.RuleField.REPOSITORY.field(),
-      RuleNormalizer.RuleField.NAME.field(),
-      RuleNormalizer.RuleField.LANGUAGE.field());
-  }
-
-  @Test
-  public void toQueryOptions_langName_requires_lang() {
-    RuleMapping mapping = new RuleMapping(languages, macroInterpreter);
-    SimpleGetRequest request = new SimpleGetRequest();
-    request.setParam(Param.PAGE, "1");
-    request.setParam(Param.PAGE_SIZE, "10");
-    request.setParam(Param.FIELDS, "langName");
-    org.sonar.server.es.SearchOptions queryContext = mapping.newQueryOptions(SearchOptions.create(request));
-
-    assertThat(queryContext.getFields()).containsOnly(RuleNormalizer.RuleField.LANGUAGE.field());
-  }
-
-  @Test
-  public void toQueryOptions_debt_requires_group_of_fields() {
-    RuleMapping mapping = new RuleMapping(languages, macroInterpreter);
-    SimpleGetRequest request = new SimpleGetRequest();
-    request.setParam(Param.PAGE, "1");
-    request.setParam(Param.PAGE_SIZE, "10");
-    request.setParam(Param.FIELDS, "debtRemFn");
-    org.sonar.server.es.SearchOptions queryContext = mapping.newQueryOptions(SearchOptions.create(request));
-
-    assertThat(queryContext.getFields()).containsOnly(
-      RuleNormalizer.RuleField.DEBT_FUNCTION_COEFFICIENT.field(),
-      RuleNormalizer.RuleField.DEBT_FUNCTION_OFFSET.field(),
-      RuleNormalizer.RuleField.DEBT_FUNCTION_TYPE.field());
-  }
-
-  @Test
-  public void toQueryOptions_html_note_requires_markdown_note() {
-    RuleMapping mapping = new RuleMapping(languages, macroInterpreter);
-    SimpleGetRequest request = new SimpleGetRequest();
-    request.setParam(Param.PAGE, "1");
-    request.setParam(Param.PAGE_SIZE, "10");
-    request.setParam(Param.FIELDS, "htmlNote");
-    org.sonar.server.es.SearchOptions queryContext = mapping.newQueryOptions(SearchOptions.create(request));
-
-    assertThat(queryContext.getFields()).containsOnly(RuleNormalizer.RuleField.NOTE.field());
-  }
-
-  @Test
-  public void toQueryOptions_remediation_function_overloaded() {
-    RuleMapping mapping = new RuleMapping(languages, macroInterpreter);
-    SimpleGetRequest request = new SimpleGetRequest();
-    request.setParam(Param.PAGE, "1");
-    request.setParam(Param.PAGE_SIZE, "10");
-    request.setParam(Param.FIELDS, "debtOverloaded");
-    org.sonar.server.es.SearchOptions queryContext = mapping.newQueryOptions(SearchOptions.create(request));
-
-    assertThat(queryContext.getFields()).containsOnly(
-      RuleNormalizer.RuleField.DEBT_FUNCTION_TYPE_OVERLOADED.field());
-  }
-}
index 79bd12c564b8619ece7b88aadb324a2b6d38f34e..02fba900fafdf1c11a1bbf2b6adcc2ba6d4696f5 100644 (file)
@@ -54,6 +54,14 @@ import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsTester;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_ACTIVATION;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_AVAILABLE_SINCE;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_IS_TEMPLATE;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_KEY;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_QPROFILE;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_STATUSES;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_TAGS;
+import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_TEMPLATE_KEY;
 
 public class SearchActionMediumTest {
 
@@ -107,13 +115,13 @@ public class SearchActionMediumTest {
     ruleIndexer.index();
 
     WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
-    request.setParam(SearchAction.PARAM_KEY, RuleTesting.XOO_X1.toString());
+    request.setParam(PARAM_KEY, RuleTesting.XOO_X1.toString());
     request.setParam(WebService.Param.FIELDS, "actives");
     WsTester.Result result = request.execute();
     result.assertJson("{\"total\":1,\"p\":1,\"ps\":100,\"rules\":[{\"key\":\"xoo:x1\"}]}");
 
     request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
-    request.setParam(SearchAction.PARAM_KEY, RuleKey.of("xoo", "unknown").toString());
+    request.setParam(PARAM_KEY, RuleKey.of("xoo", "unknown").toString());
     request.setParam(WebService.Param.FIELDS, "actives");
     result = request.execute();
     result.assertJson("{\"total\":0,\"p\":1,\"ps\":100,\"rules\":[],\"actives\":{}}");
@@ -254,7 +262,7 @@ public class SearchActionMediumTest {
 
     WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
     request.setParam(WebService.Param.FIELDS, "isTemplate");
-    request.setParam(SearchAction.PARAM_IS_TEMPLATE, "true");
+    request.setParam(PARAM_IS_TEMPLATE, "true");
     WsTester.Result result = request.execute();
     result.assertJson(this.getClass(), "search_template_rules.json");
   }
@@ -269,7 +277,7 @@ public class SearchActionMediumTest {
 
     WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
     request.setParam(WebService.Param.FIELDS, "templateKey");
-    request.setParam(SearchAction.PARAM_TEMPLATE_KEY, "xoo:x1");
+    request.setParam(PARAM_TEMPLATE_KEY, "xoo:x1");
     WsTester.Result result = request.execute();
     result.assertJson(this.getClass(), "search_rules_from_template_key.json");
   }
@@ -291,7 +299,7 @@ public class SearchActionMediumTest {
 
     WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
     request.setParam(WebService.Param.TEXT_QUERY, "x1");
-    request.setParam(SearchAction.PARAM_ACTIVATION, "true");
+    request.setParam(PARAM_ACTIVATION, "true");
     request.setParam(WebService.Param.FIELDS, "");
     WsTester.Result result = request.execute();
 
@@ -356,15 +364,15 @@ public class SearchActionMediumTest {
 
     WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
     request.setParam(WebService.Param.TEXT_QUERY, "x1");
-    request.setParam(SearchAction.PARAM_ACTIVATION, "true");
-    request.setParam(SearchAction.PARAM_QPROFILE, profile2.getKey());
+    request.setParam(PARAM_ACTIVATION, "true");
+    request.setParam(PARAM_QPROFILE, profile2.getKey());
     request.setParam(WebService.Param.FIELDS, "actives");
     WsTester.Result result = request.execute();
     result.assertJson(this.getClass(), "search_profile_active_rules.json");
 
     tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD)
-      .setParam(SearchAction.PARAM_ACTIVATION, "true")
-      .setParam(SearchAction.PARAM_QPROFILE, "unknown_profile")
+      .setParam(PARAM_ACTIVATION, "true")
+      .setParam(PARAM_QPROFILE, "unknown_profile")
       .setParam(WebService.Param.FIELDS, "actives")
       .execute()
       .assertJson(this.getClass(), "search_no_rules.json");
@@ -394,8 +402,8 @@ public class SearchActionMediumTest {
 
     WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
     request.setParam(WebService.Param.TEXT_QUERY, "x1");
-    request.setParam(SearchAction.PARAM_ACTIVATION, "true");
-    request.setParam(SearchAction.PARAM_QPROFILE, profile2.getKey());
+    request.setParam(PARAM_ACTIVATION, "true");
+    request.setParam(PARAM_QPROFILE, profile2.getKey());
     request.setParam(WebService.Param.FIELDS, "actives");
     WsTester.Result result = request.execute();
     result.assertJson(this.getClass(), "search_profile_active_rules_inheritance.json");
@@ -440,7 +448,7 @@ public class SearchActionMediumTest {
 
     WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
     request.setParam(WebService.Param.TEXT_QUERY, "x1");
-    request.setParam(SearchAction.PARAM_ACTIVATION, "true");
+    request.setParam(PARAM_ACTIVATION, "true");
     request.setParam(WebService.Param.FIELDS, "params");
     WsTester.Result result = request.execute();
 
@@ -478,7 +486,7 @@ public class SearchActionMediumTest {
     activeRuleIndexer.index();
 
     WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
-    request.setParam(SearchAction.PARAM_TAGS, "tag1");
+    request.setParam(PARAM_TAGS, "tag1");
     request.setParam(WebService.Param.FIELDS, "sysTags, tags");
     request.setParam(WebService.Param.FACETS, "tags");
     WsTester.Result result = request.execute();
@@ -509,7 +517,7 @@ public class SearchActionMediumTest {
     ruleIndexer.index();
 
     WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
-    request.setParam(SearchAction.PARAM_STATUSES, "DEPRECATED");
+    request.setParam(PARAM_STATUSES, "DEPRECATED");
     request.setParam(WebService.Param.FACETS, "statuses");
     request.execute().assertJson(this.getClass(), "statuses_facet_sticky.json");
   }
@@ -560,7 +568,7 @@ public class SearchActionMediumTest {
     // 1. find today's rules
     WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
     request.setParam(WebService.Param.FIELDS, "");
-    request.setParam(SearchAction.PARAM_AVAILABLE_SINCE, DateUtils.formatDate(since));
+    request.setParam(PARAM_AVAILABLE_SINCE, DateUtils.formatDate(since));
     request.setParam(WebService.Param.SORT, RuleIndexDefinition.FIELD_RULE_KEY);
     WsTester.Result result = request.execute();
     result.assertJson("{\"total\":2,\"p\":1,\"ps\":100,\"rules\":[{\"key\":\"xoo:x1\"},{\"key\":\"xoo:x2\"}]}");
@@ -568,7 +576,7 @@ public class SearchActionMediumTest {
     // 2. no rules since tomorrow
     request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
     request.setParam(WebService.Param.FIELDS, "");
-    request.setParam(SearchAction.PARAM_AVAILABLE_SINCE, DateUtils.formatDate(DateUtils.addDays(since, 1)));
+    request.setParam(PARAM_AVAILABLE_SINCE, DateUtils.formatDate(DateUtils.addDays(since, 1)));
     result = request.execute();
     result.assertJson("{\"total\":0,\"p\":1,\"ps\":100,\"rules\":[]}");
   }
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/rule/RulesWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/rule/RulesWsParameters.java
new file mode 100644 (file)
index 0000000..384423b
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonarqube.ws.client.rule;
+
+import com.google.common.collect.ImmutableSet;
+import java.util.Set;
+
+public class RulesWsParameters {
+  public static final String PARAM_REPOSITORIES = "repositories";
+  public static final String PARAM_KEY = "rule_key";
+  public static final String PARAM_ACTIVATION = "activation";
+  public static final String PARAM_QPROFILE = "qprofile";
+  public static final String PARAM_SEVERITIES = "severities";
+  public static final String PARAM_AVAILABLE_SINCE = "available_since";
+  public static final String PARAM_STATUSES = "statuses";
+  public static final String PARAM_LANGUAGES = "languages";
+  public static final String PARAM_DEBT_CHARACTERISTICS = "debt_characteristics";
+  public static final String PARAM_HAS_DEBT_CHARACTERISTIC = "has_debt_characteristic";
+  public static final String PARAM_TAGS = "tags";
+  public static final String PARAM_INHERITANCE = "inheritance";
+  public static final String PARAM_ACTIVE_SEVERITIES = "active_severities";
+  public static final String PARAM_IS_TEMPLATE = "is_template";
+  public static final String PARAM_TEMPLATE_KEY = "template_key";
+
+  public static final String FIELD_REPO = "repo";
+  public static final String FIELD_NAME = "name";
+  public static final String FIELD_CREATED_AT = "createdAt";
+  public static final String FIELD_SEVERITY = "severity";
+  public static final String FIELD_STATUS = "status";
+  public static final String FIELD_INTERNAL_KEY = "internalKey";
+  public static final String FIELD_IS_TEMPLATE = "isTemplate";
+  public static final String FIELD_TEMPLATE_KEY = "templateKey";
+  public static final String FIELD_TAGS = "tags";
+  public static final String FIELD_SYSTEM_TAGS = "sysTags";
+  public static final String FIELD_LANGUAGE = "lang";
+  public static final String FIELD_LANGUAGE_NAME = "langName";
+  public static final String FIELD_HTML_DESCRIPTION = "htmlDesc";
+  public static final String FIELD_MARKDOWN_DESCRIPTION = "mdDesc";
+  public static final String FIELD_NOTE_LOGIN = "noteLogin";
+  public static final String FIELD_MARKDOWN_NOTE = "mdNote";
+  public static final String FIELD_HTML_NOTE = "htmlNote";
+  public static final String FIELD_DEFAULT_DEBT_CHAR = "defaultDebtChar";
+  public static final String FIELD_DEFAULT_DEBT_SUB_CHAR = "defaultDebtSubChar";
+  public static final String FIELD_DEBT_CHAR = "debtChar";
+  public static final String FIELD_DEBT_SUB_CHAR = "debtSubChar";
+  public static final String FIELD_DEBT_CHAR_NAME = "debtCharName";
+  public static final String FIELD_DEBT_SUB_CHAR_NAME = "debtSubCharName";
+  public static final String FIELD_DEFAULT_DEBT_REM_FUNCTION = "defaultDebtRemFn";
+  public static final String FIELD_EFFORT_TO_FIX_DESCRIPTION = "effortToFixDescription";
+  public static final String FIELD_DEBT_OVERLOADED = "debtOverloaded";
+  public static final String FIELD_DEBT_REM_FUNCTION = "debtRemFn";
+  public static final String FIELD_PARAMS = "params";
+  public static final String FIELD_ACTIVES = "actives";
+
+  public static final Set<String> OPTIONAL_FIELDS = ImmutableSet.of(FIELD_REPO, FIELD_NAME, FIELD_CREATED_AT, FIELD_SEVERITY, FIELD_STATUS, FIELD_INTERNAL_KEY, FIELD_IS_TEMPLATE,
+    FIELD_TEMPLATE_KEY, FIELD_TAGS, FIELD_SYSTEM_TAGS, FIELD_LANGUAGE, FIELD_LANGUAGE_NAME, FIELD_HTML_DESCRIPTION, FIELD_MARKDOWN_DESCRIPTION, FIELD_NOTE_LOGIN,
+    FIELD_MARKDOWN_NOTE, FIELD_HTML_NOTE, FIELD_DEFAULT_DEBT_CHAR, FIELD_DEFAULT_DEBT_SUB_CHAR, FIELD_DEBT_CHAR, FIELD_DEBT_SUB_CHAR, FIELD_DEBT_CHAR_NAME,
+    FIELD_DEBT_SUB_CHAR_NAME, FIELD_DEFAULT_DEBT_REM_FUNCTION, FIELD_EFFORT_TO_FIX_DESCRIPTION, FIELD_DEBT_OVERLOADED, FIELD_DEBT_REM_FUNCTION, FIELD_PARAMS, FIELD_ACTIVES);
+
+  private RulesWsParameters() {
+    // prevent instantiation
+  }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/rule/package-info.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/rule/package-info.java
new file mode 100644 (file)
index 0000000..1560fa7
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonarqube.ws.client.rule;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+