]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5007 - Added char and subChar to api.Rule bean for Issue WS
authorStephane Gamard <stephane.gamard@searchbox.com>
Mon, 30 Jun 2014 12:05:55 +0000 (14:05 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Mon, 30 Jun 2014 12:46:44 +0000 (14:46 +0200)
sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
sonar-server/src/main/java/org/sonar/server/issue/ws/IssueShowAction.java
sonar-server/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java

index 63cb14defffa03a8cfbe36b04b2085bb8a82a4f1..b783ac11844e9a0f7d0a2740fd25738b367960a0 100644 (file)
@@ -34,8 +34,20 @@ import org.sonar.check.Cardinality;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
-import javax.persistence.*;
-
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -138,6 +150,15 @@ public class Rule {
   @Column(name = "updated_at", updatable = true, nullable = true)
   private Date updatedAt;
 
+  @Transient
+  private String defaultCharacteristic;
+  @Transient
+  private String defaultSubCharacteristic;
+  @Transient
+  private String characteristic;
+  @Transient
+  private String subCharacteristic;
+
   private transient String[] tags = DEFAULT_TAGS;
 
   /**
@@ -497,9 +518,11 @@ public class Rule {
   /**
    * For internal use only.
    *
+   * @deprecated since 4.4, use {@link #getCharacteristic()}
    * @since 4.3
    */
   @CheckForNull
+  @Deprecated
   public Integer getCharacteristicId() {
     return characteristicId;
   }
@@ -507,8 +530,10 @@ public class Rule {
   /**
    * For internal use only.
    *
+   * @deprecated since 4.4, use {@link #setCharacteristic(@Nullable String characteristic)}
    * @since 4.3
    */
+  @Deprecated
   public Rule setCharacteristicId(@Nullable Integer characteristicId) {
     this.characteristicId = characteristicId;
     return this;
@@ -517,9 +542,11 @@ public class Rule {
   /**
    * For internal use only.
    *
+   * @deprecated since 4.4, use {@link #getDefaultCharacteristic()}
    * @since 4.3
    */
   @CheckForNull
+  @Deprecated
   public Integer getDefaultCharacteristicId() {
     return defaultCharacteristicId;
   }
@@ -527,8 +554,10 @@ public class Rule {
   /**
    * For internal use only.
    *
+   * @deprecated since 4.4, use {@link #setDefaultCharacteristic(@Nullable String defaultCharacteristic)}
    * @since 4.3
    */
+  @Deprecated
   public Rule setDefaultCharacteristicId(@Nullable Integer defaultCharacteristicId) {
     this.defaultCharacteristicId = defaultCharacteristicId;
     return this;
@@ -609,4 +638,68 @@ public class Rule {
   public RuleKey ruleKey() {
     return RuleKey.of(getRepositoryKey(), getKey());
   }
+
+  /**
+   * @since 4.4
+   */
+  @CheckForNull
+  public String getDefaultCharacteristic() {
+    return defaultCharacteristic;
+  }
+
+  /**
+   * @since 4.4
+   */
+  public Rule setDefaultCharacteristic(@Nullable String defaultCharacteristic) {
+    this.defaultCharacteristic = defaultCharacteristic;
+    return this;
+  }
+
+  /**
+   * @since 4.4
+   */
+  @CheckForNull
+  public String getDefaultSubCharacteristic() {
+    return defaultSubCharacteristic;
+  }
+
+  /**
+   * @since 4.4
+   */
+  public Rule setDefaultSubCharacteristic(@Nullable String defaultSubCharacteristic) {
+    this.defaultSubCharacteristic = defaultSubCharacteristic;
+    return this;
+  }
+
+  /**
+   * @since 4.4
+   */
+  @CheckForNull
+  public String getCharacteristic() {
+    return characteristic;
+  }
+
+  /**
+   * @since 4.4
+   */
+  public Rule setCharacteristic(@Nullable String characteristic) {
+    this.characteristic = characteristic;
+    return this;
+  }
+
+  /**
+   * @since 4.4
+   */
+  @CheckForNull
+  public String getSubCharacteristic() {
+    return subCharacteristic;
+  }
+
+  /**
+   * @since 4.4
+   */
+  public Rule setSubCharacteristic(@Nullable String subCharacteristic) {
+    this.subCharacteristic = subCharacteristic;
+    return this;
+  }
 }
index 8ee532f928a5638e37819e57a0415b03ea85c3fa..3936daf64f810e93e434f64f3e11e50b4d705f72 100644 (file)
@@ -24,11 +24,14 @@ import com.google.common.collect.Iterables;
 import com.google.common.io.Resources;
 import org.sonar.api.component.Component;
 import org.sonar.api.i18n.I18n;
-import org.sonar.api.issue.*;
+import org.sonar.api.issue.ActionPlan;
+import org.sonar.api.issue.Issue;
+import org.sonar.api.issue.IssueComment;
+import org.sonar.api.issue.IssueFinder;
+import org.sonar.api.issue.IssueQuery;
+import org.sonar.api.issue.IssueQueryResult;
 import org.sonar.api.issue.internal.DefaultIssue;
 import org.sonar.api.issue.internal.FieldDiffs;
-import org.sonar.api.server.debt.DebtCharacteristic;
-import org.sonar.api.server.debt.internal.DefaultDebtCharacteristic;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.RequestHandler;
 import org.sonar.api.server.ws.Response;
@@ -49,7 +52,6 @@ import org.sonar.server.user.UserSession;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
-
 import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
@@ -271,20 +273,12 @@ public class IssueShowAction implements RequestHandler {
   }
 
   private void addCharacteristics(IssueQueryResult result, DefaultIssue issue, JsonWriter json) {
-    Integer subCharacteristicId = result.rule(issue).getCharacteristicId() != null ? result.rule(issue).getCharacteristicId() : result.rule(issue).getDefaultCharacteristicId();
-    DebtCharacteristic subCharacteristic = characteristicById(subCharacteristicId);
-    if (subCharacteristic != null) {
-      json.prop("subCharacteristic", subCharacteristic.name());
-      DebtCharacteristic characteristic = characteristicById(((DefaultDebtCharacteristic) subCharacteristic).parentId());
-      json.prop("characteristic", characteristic != null ? characteristic.name() : null);
-    }
-  }
+    String subCharacteristic = result.rule(issue).getSubCharacteristic() != null ? result.rule(issue).getSubCharacteristic() : result.rule(issue).getDefaultSubCharacteristic();
+    String characteristic = result.rule(issue).getCharacteristic() != null ? result.rule(issue).getCharacteristic() : result.rule(issue).getDefaultCharacteristic();
 
-  @CheckForNull
-  private DebtCharacteristic characteristicById(@Nullable Integer id) {
-    if (id != null) {
-      return debtModel.characteristicById(id);
+    if (subCharacteristic != null) {
+      json.prop("subCharacteristic", subCharacteristic);
+      json.prop("characteristic", characteristic != null ? characteristic : null);
     }
-    return null;
   }
 }
index fd9bbd9a64a9c55765062ae4a3d3c97b2420b67b..00fa7a8c72a18070456dfcac344de9e1dedb4d53 100644 (file)
@@ -116,6 +116,10 @@ public class DefaultRuleFinder implements RuleFinder {
       .setRepositoryKey(rule.key().repository())
       .setSeverity(RulePriority.valueOf(rule.severity()))
       .setStatus(rule.status().name())
+      .setDefaultCharacteristic(rule.defaultDebtCharacteristicKey())
+      .setDefaultSubCharacteristic(rule.defaultDebtSubCharacteristicKey())
+      .setCharacteristic(rule.debtCharacteristicKey())
+      .setSubCharacteristic(rule.debtSubCharacteristicKey())
       .setTags(rule.tags().toArray(new String[rule.tags().size()]));
 
     List<org.sonar.api.rules.RuleParam> apiParams = newArrayList();