You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SearchRequest.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.server.project.ws;
  21. import java.util.List;
  22. import javax.annotation.CheckForNull;
  23. import javax.annotation.Nullable;
  24. import org.sonar.api.resources.Qualifiers;
  25. import static com.google.common.base.Preconditions.checkArgument;
  26. import static java.util.Collections.singletonList;
  27. import static java.util.Objects.requireNonNull;
  28. import static org.sonarqube.ws.client.project.ProjectsWsParameters.MAX_PAGE_SIZE;
  29. class SearchRequest {
  30. private final String query;
  31. private final List<String> qualifiers;
  32. private final String visibility;
  33. private final Integer page;
  34. private final Integer pageSize;
  35. private final String analyzedBefore;
  36. private final boolean onProvisionedOnly;
  37. private final List<String> projects;
  38. public SearchRequest(Builder builder) {
  39. this.query = builder.query;
  40. this.qualifiers = builder.qualifiers;
  41. this.visibility = builder.visibility;
  42. this.page = builder.page;
  43. this.pageSize = builder.pageSize;
  44. this.analyzedBefore = builder.analyzedBefore;
  45. this.onProvisionedOnly = builder.onProvisionedOnly;
  46. this.projects = builder.projects;
  47. }
  48. public List<String> getQualifiers() {
  49. return qualifiers;
  50. }
  51. @CheckForNull
  52. public Integer getPage() {
  53. return page;
  54. }
  55. @CheckForNull
  56. public Integer getPageSize() {
  57. return pageSize;
  58. }
  59. @CheckForNull
  60. public String getQuery() {
  61. return query;
  62. }
  63. @CheckForNull
  64. public String getVisibility() {
  65. return visibility;
  66. }
  67. @CheckForNull
  68. public String getAnalyzedBefore() {
  69. return analyzedBefore;
  70. }
  71. public boolean isOnProvisionedOnly() {
  72. return onProvisionedOnly;
  73. }
  74. @CheckForNull
  75. public List<String> getProjects() {
  76. return projects;
  77. }
  78. public static Builder builder() {
  79. return new Builder();
  80. }
  81. public static class Builder {
  82. private List<String> qualifiers = singletonList(Qualifiers.PROJECT);
  83. private Integer page;
  84. private Integer pageSize;
  85. private String query;
  86. private String visibility;
  87. private String analyzedBefore;
  88. private boolean onProvisionedOnly = false;
  89. private List<String> projects;
  90. public Builder setQualifiers(List<String> qualifiers) {
  91. this.qualifiers = requireNonNull(qualifiers, "Qualifiers cannot be null");
  92. return this;
  93. }
  94. public Builder setPage(@Nullable Integer page) {
  95. this.page = page;
  96. return this;
  97. }
  98. public Builder setPageSize(@Nullable Integer pageSize) {
  99. this.pageSize = pageSize;
  100. return this;
  101. }
  102. public Builder setQuery(@Nullable String query) {
  103. this.query = query;
  104. return this;
  105. }
  106. public Builder setVisibility(@Nullable String visibility) {
  107. this.visibility = visibility;
  108. return this;
  109. }
  110. public Builder setAnalyzedBefore(@Nullable String lastAnalysisBefore) {
  111. this.analyzedBefore = lastAnalysisBefore;
  112. return this;
  113. }
  114. public Builder setOnProvisionedOnly(boolean onProvisionedOnly) {
  115. this.onProvisionedOnly = onProvisionedOnly;
  116. return this;
  117. }
  118. public Builder setProjects(@Nullable List<String> projects) {
  119. this.projects = projects;
  120. return this;
  121. }
  122. public SearchRequest build() {
  123. checkArgument(projects == null || !projects.isEmpty(), "Project key list must not be empty");
  124. checkArgument(pageSize == null || pageSize <= MAX_PAGE_SIZE, "Page size must not be greater than %s", MAX_PAGE_SIZE);
  125. return new SearchRequest(this);
  126. }
  127. }
  128. }