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.wsclient.services;
021    
022    /**
023     * @since 2.6
024     */
025    public class PropertyCreateQuery extends CreateQuery<Property> {
026    
027      private String key;
028      private String value;
029      private String resourceKeyOrId;
030    
031      public PropertyCreateQuery() {
032      }
033    
034      public PropertyCreateQuery(String key, String value) {
035        this.key = key;
036        this.value = value;
037      }
038    
039      public PropertyCreateQuery(String key, String value, String resourceKeyOrId) {
040        this.key = key;
041        this.value = value;
042        this.resourceKeyOrId = resourceKeyOrId;
043      }
044    
045      public PropertyCreateQuery(Property property) {
046        this.key = property.getKey();
047        this.value = property.getValue();
048      }
049    
050      public String getKey() {
051        return key;
052      }
053    
054      public PropertyCreateQuery setKey(String key) {
055        this.key = key;
056        return this;
057      }
058    
059      public String getValue() {
060        return value;
061      }
062    
063      public PropertyCreateQuery setValue(String value) {
064        this.value = value;
065        return this;
066      }
067    
068      public String getResourceKeyOrId() {
069        return resourceKeyOrId;
070      }
071    
072      public PropertyCreateQuery setResourceKeyOrId(String resourceKeyOrId) {
073        this.resourceKeyOrId = resourceKeyOrId;
074        return this;
075      }
076    
077      @Override
078      public String getUrl() {
079        StringBuilder url = new StringBuilder();
080        url.append(PropertyQuery.BASE_URL);
081        url.append("?id=").append(encode(key)).append("&");
082        appendUrlParameter(url, "value", value);
083        appendUrlParameter(url, "resource", resourceKeyOrId);
084        return url.toString();
085      }
086    
087      /**
088       * Property value is transmitted through request body as content may
089       * exceed URL size allowed by the server.
090       */
091      @Override
092      public String getBody() {
093        return value;
094      }
095    
096      @Override
097      public Class<Property> getModelClass() {
098        return Property.class;
099      }
100    }