001 /*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2014 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * SonarQube is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * SonarQube is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
019 */
020 package org.sonar.batch.qualitygate;
021
022 import javax.annotation.CheckForNull;
023
024 import com.google.gson.JsonObject;
025 import org.sonar.api.measures.Metric;
026
027 public class ResolvedCondition {
028
029 private static final String ATTRIBUTE_PERIOD = "period";
030
031 private static final String ATTRIBUTE_ERROR = "error";
032
033 private static final String ATTRIBUTE_WARNING = "warning";
034
035 private JsonObject json;
036
037 private Metric metric;
038
039 public ResolvedCondition(JsonObject jsonObject, Metric metric) {
040 this.json = jsonObject;
041 this.metric = metric;
042 }
043
044 public Long id() {
045 return json.get("id").getAsLong();
046 }
047
048 public String metricKey() {
049 return json.get("metric").getAsString();
050 }
051
052 public Metric metric() {
053 return metric;
054 }
055
056 public String operator() {
057 return json.get("op").getAsString();
058 }
059
060 @CheckForNull
061 public String warningThreshold() {
062 return json.has(ATTRIBUTE_WARNING) ? json.get(ATTRIBUTE_WARNING).getAsString() : null;
063 }
064
065 @CheckForNull
066 public String errorThreshold() {
067 return json.has(ATTRIBUTE_ERROR) ? json.get(ATTRIBUTE_ERROR).getAsString() : null;
068 }
069
070 @CheckForNull
071 public Integer period() {
072 return json.has(ATTRIBUTE_PERIOD) ? json.get(ATTRIBUTE_PERIOD).getAsInt() : null;
073 }
074 }