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 3.4 024 */ 025 public class ResourceSearchQuery extends Query<ResourceSearchResult> { 026 027 private int page = -1; 028 private int pageSize = -1; 029 private String[] qualifiers = null; 030 private String text; 031 032 private ResourceSearchQuery() { 033 } 034 035 public static ResourceSearchQuery create(String text) { 036 return new ResourceSearchQuery().setText(text); 037 } 038 039 public int getPage() { 040 return page; 041 } 042 043 public ResourceSearchQuery setPage(int page) { 044 this.page = page; 045 return this; 046 } 047 048 public int getPageSize() { 049 return pageSize; 050 } 051 052 public ResourceSearchQuery setPageSize(int pageSize) { 053 this.pageSize = pageSize; 054 return this; 055 } 056 057 public String[] getQualifiers() { 058 return qualifiers; 059 } 060 061 public ResourceSearchQuery setQualifiers(String... qualifiers) { 062 this.qualifiers = qualifiers; 063 return this; 064 } 065 066 public String getText() { 067 return text; 068 } 069 070 public ResourceSearchQuery setText(String text) { 071 this.text = text; 072 return this; 073 } 074 075 @Override 076 public String getUrl() { 077 StringBuilder url = new StringBuilder(); 078 url.append("/api/resources/search?"); 079 appendUrlParameter(url, "s", text); 080 if (page > 0) { 081 appendUrlParameter(url, "p", page); 082 } 083 if (pageSize > 0) { 084 appendUrlParameter(url, "ps", pageSize); 085 } 086 appendUrlParameter(url, "q", qualifiers); 087 return url.toString(); 088 } 089 090 @Override 091 public Class<ResourceSearchResult> getModelClass() { 092 return ResourceSearchResult.class; 093 } 094 }