private Date updatedAt;
@Transient
- private String defaultCharacteristic;
+ private String defaultCharacteristicKey;
@Transient
- private String defaultSubCharacteristic;
+ private String defaultSubCharacteristicKey;
@Transient
- private String characteristic;
+ private String characteristicKey;
@Transient
- private String subCharacteristic;
+ private String subCharacteristicKey;
private transient String[] tags = DEFAULT_TAGS;
/**
* For internal use only.
*
- * @deprecated since 4.4, use {@link #getCharacteristic()}
+ * @deprecated since 4.4, use {@link #getCharacteristicKey()}
* @since 4.3
*/
@CheckForNull
/**
* For internal use only.
*
- * @deprecated since 4.4, use {@link #setCharacteristic(@Nullable String characteristic)}
+ * @deprecated since 4.4, use {@link #setCharacteristicKey(@Nullable String characteristicKey)}
* @since 4.3
*/
@Deprecated
/**
* For internal use only.
*
- * @deprecated since 4.4, use {@link #getDefaultCharacteristic()}
+ * @deprecated since 4.4, use {@link #getDefaultCharacteristicKey()}
* @since 4.3
*/
@CheckForNull
/**
* For internal use only.
*
- * @deprecated since 4.4, use {@link #setDefaultCharacteristic(@Nullable String defaultCharacteristic)}
+ * @deprecated since 4.4, use {@link #setDefaultCharacteristicKey(@Nullable String defaultCharacteristicKey)}
* @since 4.3
*/
@Deprecated
* @since 4.4
*/
@CheckForNull
- public String getDefaultCharacteristic() {
- return defaultCharacteristic;
+ public String getDefaultCharacteristicKey() {
+ return defaultCharacteristicKey;
}
/**
* @since 4.4
*/
- public Rule setDefaultCharacteristic(@Nullable String defaultCharacteristic) {
- this.defaultCharacteristic = defaultCharacteristic;
+ public Rule setDefaultCharacteristicKey(@Nullable String defaultCharacteristicKey) {
+ this.defaultCharacteristicKey = defaultCharacteristicKey;
return this;
}
* @since 4.4
*/
@CheckForNull
- public String getDefaultSubCharacteristic() {
- return defaultSubCharacteristic;
+ public String getDefaultSubCharacteristicKey() {
+ return defaultSubCharacteristicKey;
}
/**
* @since 4.4
*/
- public Rule setDefaultSubCharacteristic(@Nullable String defaultSubCharacteristic) {
- this.defaultSubCharacteristic = defaultSubCharacteristic;
+ public Rule setDefaultSubCharacteristicKey(@Nullable String defaultSubCharacteristicKey) {
+ this.defaultSubCharacteristicKey = defaultSubCharacteristicKey;
return this;
}
* @since 4.4
*/
@CheckForNull
- public String getCharacteristic() {
- return characteristic;
+ public String getCharacteristicKey() {
+ return characteristicKey;
}
/**
* @since 4.4
*/
- public Rule setCharacteristic(@Nullable String characteristic) {
- this.characteristic = characteristic;
+ public Rule setCharacteristicKey(@Nullable String characteristicKey) {
+ this.characteristicKey = characteristicKey;
return this;
}
* @since 4.4
*/
@CheckForNull
- public String getSubCharacteristic() {
- return subCharacteristic;
+ public String getSubCharacteristicKey() {
+ return subCharacteristicKey;
}
/**
* @since 4.4
*/
- public Rule setSubCharacteristic(@Nullable String subCharacteristic) {
- this.subCharacteristic = subCharacteristic;
+ public Rule setSubCharacteristicKey(@Nullable String subCharacteristicKey) {
+ this.subCharacteristicKey = subCharacteristicKey;
return this;
}
}
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;
}
private void addCharacteristics(IssueQueryResult result, DefaultIssue issue, JsonWriter json) {
- 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();
-
+ String subCharacteristicKey = result.rule(issue).getCharacteristicKey() != null ? result.rule(issue).getCharacteristicKey() : result.rule(issue).getDefaultCharacteristicKey();
+ DebtCharacteristic subCharacteristic = characteristicByKey(subCharacteristicKey);
if (subCharacteristic != null) {
- json.prop("subCharacteristic", subCharacteristic);
- json.prop("characteristic", characteristic != null ? characteristic : null);
+ json.prop("subCharacteristic", subCharacteristic.name());
+ DebtCharacteristic characteristic = characteristicById(((DefaultDebtCharacteristic) subCharacteristic).parentId());
+ json.prop("characteristic", characteristic != null ? characteristic.name() : null);
+ }
+ }
+
+ @CheckForNull
+ private DebtCharacteristic characteristicById(@Nullable Integer id) {
+ if (id != null) {
+ return debtModel.characteristicById(id);
}
+ return null;
+ }
+
+ @CheckForNull
+ private DebtCharacteristic characteristicByKey(@Nullable String key) {
+ if (key != null) {
+ return debtModel.characteristicByKey(key);
+ }
+ return null;
}
}
.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())
+ .setDefaultCharacteristicKey(rule.defaultDebtCharacteristicKey())
+ .setDefaultSubCharacteristicKey(rule.defaultDebtSubCharacteristicKey())
+ .setCharacteristicKey(rule.debtCharacteristicKey())
+ .setSubCharacteristicKey(rule.debtSubCharacteristicKey())
.setTags(rule.tags().toArray(new String[rule.tags().size()]));
List<org.sonar.api.rules.RuleParam> apiParams = newArrayList();
Issue issue = createStandardIssue().setDebt(Duration.create(7260L));
issues.add(issue);
- result.rule(issue).setCharacteristicId(2);
- when(debtModel.characteristicById(1)).thenReturn(new DefaultDebtCharacteristic().setId(1).setName("Maintainability"));
- when(debtModel.characteristicById(2)).thenReturn(new DefaultDebtCharacteristic().setId(2).setName("Readability").setParentId(1));
+ result.rule(issue).setCharacteristicKey("K2");
+ when(debtModel.characteristicById(1)).thenReturn(new DefaultDebtCharacteristic().setKey("K1").setId(1).setName("Maintainability"));
+ when(debtModel.characteristicById(2)).thenReturn(new DefaultDebtCharacteristic().setKey("K2").setId(2).setName("Readability").setParentId(1));
+ when(debtModel.characteristicByKey("K2")).thenReturn(new DefaultDebtCharacteristic().setKey("K2").setId(2).setName("Readability").setParentId(1));
MockUserSession.set();
WsTester.TestRequest request = tester.newGetRequest("api/issues", "show").setParam("key", issue.key());
Issue issue = createStandardIssue().setDebt(Duration.create(7260L));
issues.add(issue);
- result.rule(issue).setDefaultCharacteristicId(2);
- when(debtModel.characteristicById(1)).thenReturn(new DefaultDebtCharacteristic().setId(1).setName("Maintainability"));
- when(debtModel.characteristicById(2)).thenReturn(new DefaultDebtCharacteristic().setId(2).setName("Readability").setParentId(1));
+ result.rule(issue).setDefaultCharacteristicKey("K2");
+ when(debtModel.characteristicById(1)).thenReturn(new DefaultDebtCharacteristic().setKey("K1").setId(1).setName("Maintainability"));
+ when(debtModel.characteristicById(2)).thenReturn(new DefaultDebtCharacteristic().setKey("K2").setId(2).setName("Readability").setParentId(1));
+ when(debtModel.characteristicByKey("K2")).thenReturn(new DefaultDebtCharacteristic().setKey("K2").setId(2).setName("Readability").setParentId(1));
MockUserSession.set();
WsTester.TestRequest request = tester.newGetRequest("api/issues", "show").setParam("key", issue.key());
+ System.out.println("request.execute().outputAsString() = " + request.execute().outputAsString());
request.execute().assertJson(getClass(), "show_issue_with_characteristics.json");
}
Issue issue = createStandardIssue().setDebt(Duration.create(7260L));
issues.add(issue);
- result.rule(issue).setCharacteristicId(2);
- when(debtModel.characteristicById(1)).thenReturn(new DefaultDebtCharacteristic().setId(1).setName("Maintainability"));
- when(debtModel.characteristicById(2)).thenReturn(new DefaultDebtCharacteristic().setId(2).setName("Readability").setParentId(1));
+ result.rule(issue).setCharacteristicKey("K2");
+ when(debtModel.characteristicById(1)).thenReturn(new DefaultDebtCharacteristic().setKey("K1").setId(1).setName("Maintainability"));
+ when(debtModel.characteristicById(2)).thenReturn(new DefaultDebtCharacteristic().setKey("K2").setId(2).setName("Readability").setParentId(1));
+ when(debtModel.characteristicByKey("K2")).thenReturn(new DefaultDebtCharacteristic().setKey("K2").setId(2).setName("Readability").setParentId(1));
- result.rule(issue).setDefaultCharacteristicId(20);
- when(debtModel.characteristicById(10)).thenReturn(new DefaultDebtCharacteristic().setId(10).setName("Default Maintainability"));
- when(debtModel.characteristicById(20)).thenReturn(new DefaultDebtCharacteristic().setId(20).setName("Default Readability").setParentId(10));
+ result.rule(issue).setDefaultCharacteristicKey("K20");
+ when(debtModel.characteristicById(10)).thenReturn(new DefaultDebtCharacteristic().setKey("K10").setId(10).setName("Default Maintainability"));
+ when(debtModel.characteristicById(20)).thenReturn(new DefaultDebtCharacteristic().setKey("K20").setId(20).setName("Default Readability").setParentId(10));
+ when(debtModel.characteristicByKey("K20")).thenReturn(new DefaultDebtCharacteristic().setKey("K20").setId(20).setName("Default Readability").setParentId(10));
MockUserSession.set();
WsTester.TestRequest request = tester.newGetRequest("api/issues", "show").setParam("key", issue.key());