]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5007 - Updated JSWritter for null entries from *Doc objects
authorStephane Gamard <stephane.gamard@searchbox.com>
Mon, 19 May 2014 15:05:50 +0000 (17:05 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Mon, 19 May 2014 15:06:04 +0000 (17:06 +0200)
sonar-plugin-api/src/main/java/org/sonar/api/utils/text/JsonWriter.java
sonar-server/src/main/java/org/sonar/server/rule2/Rule.java
sonar-server/src/main/java/org/sonar/server/rule2/RuleService.java
sonar-server/src/main/java/org/sonar/server/rule2/ws/SearchAction.java

index 5450a63e22a21b3ad3fb780121c19603bd92beaa..6387ecc42f009110cdae947a2e9ba783beb063b5 100644 (file)
@@ -324,6 +324,17 @@ public class JsonWriter {
     return name(name).value(value);
   }
 
+  /**
+   * @throws org.sonar.api.utils.text.WriterException on any failure
+   */
+  public JsonWriter prop(String name, @Nullable Object value) {
+    if(value != null) {
+      return name(name).value(value.toString());
+    } else {
+      return this;
+    }
+  }
+
   /**
    * @throws org.sonar.api.utils.text.WriterException on any failure
    */
index 2582e03c57bf8f72f10da392160602adb239d5b3..0da3048e8395112e748b9083cc0f137231f0f137 100644 (file)
@@ -75,6 +75,7 @@ public interface Rule {
   @CheckForNull
   DebtRemediationFunction debtRemediationFunction();
 
+
   Date createdAt();
 
   Date updatedAt();
index 220a985e0b6e8489c634a6d866b12a808506bad2..3a939593d3c70c8a64df3ee77299be65685044ee 100644 (file)
@@ -105,6 +105,7 @@ public class RuleService implements ServerComponent {
   }
 
   public void setTags(RuleKey ruleKey, Set<String> tags) {
+
     checkAdminPermission(UserSession.get());
 
     DbSession dbSession = db.openSession(false);
index 57229830ab03ffcacf1804eda8e208c421afaef5..92644eff91593a32f7626996bcf121f8a9c082d2 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.rule2.ws;
 import com.google.common.base.Function;
 import com.google.common.collect.Collections2;
 import com.google.common.io.Resources;
+import com.google.gson.Gson;
 import org.sonar.api.rule.RuleStatus;
 import org.sonar.api.rule.Severity;
 import org.sonar.api.server.ws.Request;
@@ -217,6 +218,8 @@ public class SearchAction implements RequestHandler {
     json.prop(PARAM_PAGE, request.mandatoryParamAsInt(PARAM_PAGE));
     json.prop(PARAM_PAGE_SIZE, request.mandatoryParamAsInt(PARAM_PAGE_SIZE));
   }
+
+
   private void writeRules(RuleResult result, JsonWriter json) {
 
     json.name("rules").beginArray();
@@ -230,18 +233,16 @@ public class SearchAction implements RequestHandler {
         .prop("lang", rule.language())
         .prop("name", rule.name())
         .prop("htmlDesc", rule.htmlDescription())
-        .prop("status", rule.status().toString())
+        .prop("status", rule.status())
         .prop("template", rule.template())
         .prop("internalKey", rule.internalKey())
         .prop("severity", rule.severity())
         .prop("markdownNote", rule.markdownNote())
         .prop("noteLogin", rule.noteLogin())
         .name("tags").beginArray().values(rule.tags()).endArray()
-        .name("sysTags").beginArray().values(rule.systemTags()).endArray();
-      if(rule.debtSubCharacteristicKey() != null && !rule.debtSubCharacteristicKey().isEmpty()){
-        json
-          .prop("debtSubCharacteristicKey", rule.debtSubCharacteristicKey());
-      }
+        .name("sysTags").beginArray().values(rule.systemTags()).endArray()
+        .prop("debtSubCharacteristicKey", rule.debtSubCharacteristicKey());
+
       if(rule.debtRemediationFunction() != null){
         json
           .prop("debtRemediationFunctionType", rule.debtRemediationFunction().type().name())
@@ -266,11 +267,11 @@ public class SearchAction implements RequestHandler {
       for (ActiveRule activeRule : result.getActiveRules().get(rule.key().toString())) {
         json
           .beginObject()
-          .prop("key",activeRule.key().toString())
-          .prop("inherit", activeRule.inheritance().name())
+          .prop("key",activeRule.key())
+          .prop("inherit", activeRule.inheritance())
           .prop("severity", activeRule.severity());
         if(activeRule.parentKey() != null){
-          json.prop("parent",activeRule.parentKey().toString());
+          json.prop("parent",activeRule.parentKey());
         }
 
         json