aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client/src/main/java
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-03-05 14:24:58 +0100
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-03-05 14:25:05 +0100
commit742c7405acb3f05ceb16992395a9ee3439d405a2 (patch)
treeac9c26e49f338fb1ebd1e72569eccc7574e398f9 /sonar-ws-client/src/main/java
parent10ec32151f15d675dfd886b9845b0c1e66998bdb (diff)
downloadsonarqube-742c7405acb3f05ceb16992395a9ee3439d405a2.tar.gz
sonarqube-742c7405acb3f05ceb16992395a9ee3439d405a2.zip
SONAR-5094 Add method in WS client to get conditions for a QG
Diffstat (limited to 'sonar-ws-client/src/main/java')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/QualityGateClient.java4
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/QualityGateCondition.java38
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClient.java22
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateCondition.java65
4 files changed, 126 insertions, 3 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/QualityGateClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/QualityGateClient.java
index 17a1fe99410..9f5563f1cd4 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/QualityGateClient.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/QualityGateClient.java
@@ -19,6 +19,8 @@
*/
package org.sonar.wsclient.qualitygate;
+import java.util.Collection;
+
/**
* @since 4.3
*/
@@ -30,6 +32,8 @@ public interface QualityGateClient {
QualityGate rename(long qGateId, String qGateName);
+ Collection<QualityGateCondition> conditions(long qGateId);
+
void destroy(long qGateId);
void setDefault(long qGateId);
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/QualityGateCondition.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/QualityGateCondition.java
new file mode 100644
index 00000000000..1443ba5b1d1
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/QualityGateCondition.java
@@ -0,0 +1,38 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.wsclient.qualitygate;
+
+/**
+ * @since 4.3
+ */
+public interface QualityGateCondition {
+
+ Long id();
+
+ String metricKey();
+
+ String operator();
+
+ String warningThreshold();
+
+ String errorThreshold();
+
+ Integer period();
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClient.java
index ac920a88c5e..1b95997bb75 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClient.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClient.java
@@ -23,16 +23,16 @@ import org.json.simple.JSONValue;
import org.sonar.wsclient.internal.HttpRequestFactory;
import org.sonar.wsclient.qualitygate.QualityGate;
import org.sonar.wsclient.qualitygate.QualityGateClient;
+import org.sonar.wsclient.qualitygate.QualityGateCondition;
import org.sonar.wsclient.qualitygate.QualityGates;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
public class DefaultQualityGateClient implements QualityGateClient {
private static final String ROOT_URL = "/api/qualitygates";
private static final String LIST_URL = ROOT_URL + "/list";
+ private static final String SHOW_URL = ROOT_URL + "/show";
private static final String CREATE_URL = ROOT_URL + "/create";
private static final String RENAME_URL = ROOT_URL + "/rename";
private static final String DESTROY_URL = ROOT_URL + "/destroy";
@@ -67,6 +67,12 @@ public class DefaultQualityGateClient implements QualityGateClient {
}
@Override
+ public Collection<QualityGateCondition> conditions(long qGateId) {
+ String json = requestFactory.get(SHOW_URL, Collections.singletonMap("id", (Object) qGateId));
+ return jsonToConditions(json);
+ }
+
+ @Override
public void destroy(long qGateId) {
requestFactory.post(DESTROY_URL, Collections.singletonMap("id", (Object) qGateId));
}
@@ -93,4 +99,14 @@ public class DefaultQualityGateClient implements QualityGateClient {
return new DefaultQualityGates((Map) jsonRoot);
}
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ private Collection<QualityGateCondition> jsonToConditions(String json) {
+ Map jsonRoot = (Map) JSONValue.parse(json);
+ Collection<Map> conditionArray = (Collection<Map>) jsonRoot.get("conditions");
+ Collection<QualityGateCondition> conditions = new ArrayList<QualityGateCondition>();
+ for (Map conditionJson: conditionArray) {
+ conditions.add(new DefaultQualityGateCondition(conditionJson));
+ }
+ return conditions;
+ }
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateCondition.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateCondition.java
new file mode 100644
index 00000000000..d6604c48bb3
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateCondition.java
@@ -0,0 +1,65 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.wsclient.qualitygate.internal;
+
+import org.sonar.wsclient.qualitygate.QualityGateCondition;
+import org.sonar.wsclient.unmarshallers.JsonUtils;
+
+import java.util.Map;
+
+public class DefaultQualityGateCondition implements QualityGateCondition {
+
+ private Map<String, String> json;
+
+ public DefaultQualityGateCondition(Map<String, String> json) {
+ this.json = json;
+ }
+
+ @Override
+ public Long id() {
+ return JsonUtils.getLong(json, "id");
+ }
+
+ @Override
+ public String metricKey() {
+ return JsonUtils.getString(json, "metric");
+ }
+
+ @Override
+ public String operator() {
+ return JsonUtils.getString(json, "op");
+ }
+
+ @Override
+ public String warningThreshold() {
+ return JsonUtils.getString(json, "warning");
+ }
+
+ @Override
+ public String errorThreshold() {
+ return JsonUtils.getString(json, "error");
+ }
+
+ @Override
+ public Integer period() {
+ return JsonUtils.getInteger(json, "period");
+ }
+
+}