diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-03-06 13:47:26 +0100 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-03-07 08:42:46 +0100 |
commit | efe0e18c136dbea99c50eb855966ff1f4d93fdc3 (patch) | |
tree | 61ee88a7c1762eca07cd4bd29ac9b174325171fb /sonar-ws-client/src/main/java/org/sonar | |
parent | bda11470599553a0bf92fbfa7840e728554a9186 (diff) | |
download | sonarqube-efe0e18c136dbea99c50eb855966ff1f4d93fdc3.tar.gz sonarqube-efe0e18c136dbea99c50eb855966ff1f4d93fdc3.zip |
SONAR-5094 Update Quality Gate show WS and its associated client for easier loading of config from batch
Diffstat (limited to 'sonar-ws-client/src/main/java/org/sonar')
4 files changed, 92 insertions, 8 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 9f5563f1cd4..073cae9a868 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,7 +19,6 @@ */ package org.sonar.wsclient.qualitygate; -import java.util.Collection; /** * @since 4.3 @@ -32,7 +31,9 @@ public interface QualityGateClient { QualityGate rename(long qGateId, String qGateName); - Collection<QualityGateCondition> conditions(long qGateId); + QualityGateDetails show(long qGateId); + + QualityGateDetails show(String qGateName); void destroy(long qGateId); diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/QualityGateDetails.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/QualityGateDetails.java new file mode 100644 index 00000000000..69b3e8e5581 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/QualityGateDetails.java @@ -0,0 +1,30 @@ +/* + * 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; + +import java.util.Collection; + +/** + * @since 4.3 + */ +public interface QualityGateDetails extends QualityGate { + + Collection<QualityGateCondition> conditions(); +} 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 1b95997bb75..601acbaf2eb 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 @@ -21,10 +21,7 @@ package org.sonar.wsclient.qualitygate.internal; 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 org.sonar.wsclient.qualitygate.*; import java.util.*; @@ -67,9 +64,15 @@ public class DefaultQualityGateClient implements QualityGateClient { } @Override - public Collection<QualityGateCondition> conditions(long qGateId) { + public QualityGateDetails show(long qGateId) { String json = requestFactory.get(SHOW_URL, Collections.singletonMap("id", (Object) qGateId)); - return jsonToConditions(json); + return jsonToDetails(json); + } + + @Override + public QualityGateDetails show(String qGateName) { + String json = requestFactory.get(SHOW_URL, Collections.singletonMap("name", (Object) qGateName)); + return jsonToDetails(json); } @Override @@ -100,6 +103,12 @@ public class DefaultQualityGateClient implements QualityGateClient { } @SuppressWarnings({"rawtypes", "unchecked"}) + private QualityGateDetails jsonToDetails(String json) { + Map jsonRoot = (Map) JSONValue.parse(json); + return new DefaultQualityGateDetails((Map) jsonRoot, jsonToConditions(json)); + } + + @SuppressWarnings({"rawtypes", "unchecked"}) private Collection<QualityGateCondition> jsonToConditions(String json) { Map jsonRoot = (Map) JSONValue.parse(json); Collection<Map> conditionArray = (Collection<Map>) jsonRoot.get("conditions"); @@ -109,4 +118,6 @@ public class DefaultQualityGateClient implements QualityGateClient { } return conditions; } + + } diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateDetails.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateDetails.java new file mode 100644 index 00000000000..5f5c796e371 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateDetails.java @@ -0,0 +1,42 @@ +/* + * 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.qualitygate.QualityGateDetails; + +import java.util.Collection; +import java.util.Map; + +public class DefaultQualityGateDetails extends DefaultQualityGate implements QualityGateDetails { + + private final Collection<QualityGateCondition> conditions; + + DefaultQualityGateDetails(Map<String, String> json, Collection<QualityGateCondition> conditions) { + super(json); + this.conditions = conditions; + } + + @Override + public Collection<QualityGateCondition> conditions() { + return conditions; + } + +} |