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 */
020package org.sonar.wsclient.services;
021
022/**
023 * @since 2.10
024 */
025public final class ManualMeasureCreateQuery extends CreateQuery<ManualMeasure> {
026
027  private String resourceKey;
028  private String metricKey;
029  private Integer intValue;
030  private Double value;
031  private String textValue;
032  private String description;
033
034  private ManualMeasureCreateQuery(String resourceKey, String metricKey) {
035    this.resourceKey = resourceKey;
036    this.metricKey = metricKey;
037  }
038
039  public String getResourceKey() {
040    return resourceKey;
041  }
042
043  public String getMetricKey() {
044    return metricKey;
045  }
046
047  public Double getValue() {
048    return value;
049  }
050
051  public ManualMeasureCreateQuery setValue(Double value) {
052    this.value = value;
053    return this;
054  }
055
056  public Integer getIntValue() {
057    return intValue;
058  }
059
060  public ManualMeasureCreateQuery setIntValue(Integer intValue) {
061    this.intValue = intValue;
062    return this;
063  }
064
065  public String getTextValue() {
066    return textValue;
067  }
068
069  public ManualMeasureCreateQuery setTextValue(String textValue) {
070    this.textValue = textValue;
071    return this;
072  }
073
074  public String getDescription() {
075    return description;
076  }
077
078  public ManualMeasureCreateQuery setDescription(String description) {
079    this.description = description;
080    return this;
081  }
082
083  @Override
084  public String getUrl() {
085    StringBuilder url = new StringBuilder();
086    url.append(ManualMeasureQuery.BASE_URL);
087    appendUrlParameter(url, "resource", resourceKey);
088    appendUrlParameter(url, "metric", metricKey);
089    if (value != null) {
090      appendUrlParameter(url, "val", value);
091    } else if (intValue != null) {
092      appendUrlParameter(url, "val", intValue);
093    }
094
095    // limitations : POST body is not used, so the complete URL size is limited
096    appendUrlParameter(url, "text", textValue);
097    appendUrlParameter(url, "desc", description);
098    return url.toString();
099  }
100
101  @Override
102  public Class<ManualMeasure> getModelClass() {
103    return ManualMeasure.class;
104  }
105
106  public static ManualMeasureCreateQuery create(String resourceKey, String metricKey) {
107    return new ManualMeasureCreateQuery(resourceKey, metricKey);
108  }
109}