123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- /*
- * SonarQube
- * Copyright (C) 2009-2021 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
- package org.sonar.server.project.ws;
-
- import java.util.List;
- import javax.annotation.CheckForNull;
- import javax.annotation.Nullable;
- import org.sonar.api.resources.Qualifiers;
-
- import static com.google.common.base.Preconditions.checkArgument;
- import static java.util.Collections.singletonList;
- import static java.util.Objects.requireNonNull;
- import static org.sonarqube.ws.client.project.ProjectsWsParameters.MAX_PAGE_SIZE;
-
- class SearchRequest {
-
- private final String query;
- private final List<String> qualifiers;
- private final String visibility;
- private final Integer page;
- private final Integer pageSize;
- private final String analyzedBefore;
- private final boolean onProvisionedOnly;
- private final List<String> projects;
-
- public SearchRequest(Builder builder) {
- this.query = builder.query;
- this.qualifiers = builder.qualifiers;
- this.visibility = builder.visibility;
- this.page = builder.page;
- this.pageSize = builder.pageSize;
- this.analyzedBefore = builder.analyzedBefore;
- this.onProvisionedOnly = builder.onProvisionedOnly;
- this.projects = builder.projects;
- }
-
- public List<String> getQualifiers() {
- return qualifiers;
- }
-
- @CheckForNull
- public Integer getPage() {
- return page;
- }
-
- @CheckForNull
- public Integer getPageSize() {
- return pageSize;
- }
-
- @CheckForNull
- public String getQuery() {
- return query;
- }
-
- @CheckForNull
- public String getVisibility() {
- return visibility;
- }
-
- @CheckForNull
- public String getAnalyzedBefore() {
- return analyzedBefore;
- }
-
- public boolean isOnProvisionedOnly() {
- return onProvisionedOnly;
- }
-
- @CheckForNull
- public List<String> getProjects() {
- return projects;
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- public static class Builder {
- private List<String> qualifiers = singletonList(Qualifiers.PROJECT);
- private Integer page;
- private Integer pageSize;
- private String query;
- private String visibility;
- private String analyzedBefore;
- private boolean onProvisionedOnly = false;
- private List<String> projects;
-
- public Builder setQualifiers(List<String> qualifiers) {
- this.qualifiers = requireNonNull(qualifiers, "Qualifiers cannot be null");
- return this;
- }
-
- public Builder setPage(@Nullable Integer page) {
- this.page = page;
- return this;
- }
-
- public Builder setPageSize(@Nullable Integer pageSize) {
- this.pageSize = pageSize;
- return this;
- }
-
- public Builder setQuery(@Nullable String query) {
- this.query = query;
- return this;
- }
-
- public Builder setVisibility(@Nullable String visibility) {
- this.visibility = visibility;
- return this;
- }
-
- public Builder setAnalyzedBefore(@Nullable String lastAnalysisBefore) {
- this.analyzedBefore = lastAnalysisBefore;
- return this;
- }
-
- public Builder setOnProvisionedOnly(boolean onProvisionedOnly) {
- this.onProvisionedOnly = onProvisionedOnly;
- return this;
- }
-
- public Builder setProjects(@Nullable List<String> projects) {
- this.projects = projects;
- return this;
- }
-
- public SearchRequest build() {
- checkArgument(projects == null || !projects.isEmpty(), "Project key list must not be empty");
- checkArgument(pageSize == null || pageSize <= MAX_PAGE_SIZE, "Page size must not be greater than %s", MAX_PAGE_SIZE);
- return new SearchRequest(this);
- }
- }
- }
|