From 69b830fa3161c2438e9044a7dac917f9602c7ded Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 22 Nov 2017 15:51:24 +0100 Subject: [PATCH] SONAR-10087 Replace 'default' by 'isDefault' in api/qualitygates/list - 'default' at root level is deprecated - 'isDefault' is added on quality gate level --- .../server/qualitygate/ws/ListAction.java | 22 ++++++++++++++----- .../qualitygate/ws/QualityGatesWsTest.java | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ListAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ListAction.java index 7ded7a9d04e..74d8a64c695 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ListAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ListAction.java @@ -20,6 +20,7 @@ package org.sonar.server.qualitygate.ws; import com.google.common.io.Resources; +import org.sonar.api.server.ws.Change; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; @@ -27,6 +28,9 @@ import org.sonar.api.utils.text.JsonWriter; import org.sonar.db.qualitygate.QualityGateDto; import org.sonar.server.qualitygate.QualityGates; +import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_ID; +import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_NAME; + public class ListAction implements QualityGatesWsAction { private final QualityGates qualityGates; @@ -41,20 +45,28 @@ public class ListAction implements QualityGatesWsAction { .setDescription("Get a list of quality gates") .setSince("4.3") .setResponseExample(Resources.getResource(this.getClass(), "example-list.json")) + .setChangelog( + new Change("7.0", "'isDefault' field is added on quality gate level"), + new Change("7.0", "'default' field on root level is deprecated")) .setHandler(this); } @Override public void handle(Request request, Response response) { try (JsonWriter writer = response.newJsonWriter()) { + QualityGateDto defaultQgate = qualityGates.getDefault(); + Long defaultQgateId = defaultQgate == null ? null : defaultQgate.getId(); writer.beginObject().name("qualitygates").beginArray(); - for (QualityGateDto qgate : qualityGates.list()) { - QualityGatesWs.writeQualityGate(qgate, writer); + for (QualityGateDto qualityGate : qualityGates.list()) { + writer.beginObject() + .prop(PARAM_ID, qualityGate.getId()) + .prop(PARAM_NAME, qualityGate.getName()) + .prop("isDefault", qualityGate.getId().equals(defaultQgateId)) + .endObject(); } writer.endArray(); - QualityGateDto defaultQgate = qualityGates.getDefault(); - if (defaultQgate != null) { - writer.prop("default", defaultQgate.getId()); + if (defaultQgateId != null) { + writer.prop("default", defaultQgateId); } writer.endObject().close(); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QualityGatesWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QualityGatesWsTest.java index 9b2de4b6e55..f6779e98aa9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QualityGatesWsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QualityGatesWsTest.java @@ -245,7 +245,7 @@ public class QualityGatesWsTest { new QualityGateDto().setId(666L).setName("Ninth"))); when(qGates.getDefault()).thenReturn(defaultQgate); tester.newGetRequest("api/qualitygates", "list").execute().assertJson( - "{\"qualitygates\":[{\"id\":42,\"name\":\"Golden\"},{\"id\":43,\"name\":\"Star\"},{\"id\":666,\"name\":\"Ninth\"}],\"default\":42}"); + "{\"qualitygates\":[{\"id\":42,\"name\":\"Golden\",\"isDefault\":true},{\"id\":43,\"name\":\"Star\",\"isDefault\":false},{\"id\":666,\"name\":\"Ninth\",\"isDefault\":false}],\"default\":42}"); } @Test -- 2.39.5