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 022public class PropertyQuery extends Query<Property> { 023 public static final String BASE_URL = "/api/properties"; 024 025 private String key = null; 026 private String resourceKeyOrId = null; 027 028 public String getKey() { 029 return key; 030 } 031 032 public PropertyQuery setKey(String key) { 033 this.key = key; 034 return this; 035 } 036 037 public String getResourceKeyOrId() { 038 return resourceKeyOrId; 039 } 040 041 public PropertyQuery setResourceKeyOrId(String resourceKeyOrId) { 042 this.resourceKeyOrId = resourceKeyOrId; 043 return this; 044 } 045 046 @Override 047 public String getUrl() { 048 StringBuilder url = new StringBuilder(BASE_URL); 049 if (key != null) { 050 url.append("/").append(encode(key)); 051 } 052 url.append('?'); 053 appendUrlParameter(url, "resource", resourceKeyOrId); 054 return url.toString(); 055 } 056 057 @Override 058 public Class<Property> getModelClass() { 059 return Property.class; 060 } 061 062 public static PropertyQuery createForAll() { 063 return new PropertyQuery(); 064 } 065 066 public static PropertyQuery createForKey(String key) { 067 return new PropertyQuery().setKey(key); 068 } 069 070 public static PropertyQuery createForResource(String key, String resourceKeyOrId) { 071 return new PropertyQuery().setKey(key).setResourceKeyOrId(resourceKeyOrId); 072 } 073}