選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

SearchRequest.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 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.projectanalysis.ws;
  21. import javax.annotation.CheckForNull;
  22. import javax.annotation.Nullable;
  23. import static com.google.common.base.Preconditions.checkArgument;
  24. import static java.util.Objects.requireNonNull;
  25. class SearchRequest {
  26. static final int DEFAULT_PAGE_SIZE = 100;
  27. static final int MAX_SIZE = 500;
  28. private final String project;
  29. private final String branch;
  30. private final String pullRequest;
  31. private final EventCategory category;
  32. private final int page;
  33. private final int pageSize;
  34. private final String from;
  35. private final String to;
  36. private SearchRequest(Builder builder) {
  37. this.project = builder.project;
  38. this.branch = builder.branch;
  39. this.pullRequest = builder.pullRequest;
  40. this.category = builder.category;
  41. this.page = builder.page;
  42. this.pageSize = builder.pageSize;
  43. this.from = builder.from;
  44. this.to = builder.to;
  45. }
  46. public String getProject() {
  47. return project;
  48. }
  49. @CheckForNull
  50. public String getBranch() {
  51. return branch;
  52. }
  53. @CheckForNull
  54. public String getPullRequest() {
  55. return pullRequest;
  56. }
  57. @CheckForNull
  58. public EventCategory getCategory() {
  59. return category;
  60. }
  61. public int getPage() {
  62. return page;
  63. }
  64. public int getPageSize() {
  65. return pageSize;
  66. }
  67. @CheckForNull
  68. public String getFrom() {
  69. return from;
  70. }
  71. @CheckForNull
  72. public String getTo() {
  73. return to;
  74. }
  75. public static Builder builder() {
  76. return new Builder();
  77. }
  78. public static class Builder {
  79. private String project;
  80. private String branch;
  81. private String pullRequest;
  82. private EventCategory category;
  83. private int page = 1;
  84. private int pageSize = DEFAULT_PAGE_SIZE;
  85. private String from;
  86. private String to;
  87. private Builder() {
  88. // enforce static factory method
  89. }
  90. public Builder setProject(String project) {
  91. this.project = project;
  92. return this;
  93. }
  94. public Builder setBranch(@Nullable String branch) {
  95. this.branch = branch;
  96. return this;
  97. }
  98. public Builder setPullRequest(@Nullable String pullRequest) {
  99. this.pullRequest = pullRequest;
  100. return this;
  101. }
  102. public Builder setCategory(@Nullable EventCategory category) {
  103. this.category = category;
  104. return this;
  105. }
  106. public Builder setPage(int page) {
  107. this.page = page;
  108. return this;
  109. }
  110. public Builder setPageSize(int pageSize) {
  111. this.pageSize = pageSize;
  112. return this;
  113. }
  114. public Builder setFrom(@Nullable String from) {
  115. this.from = from;
  116. return this;
  117. }
  118. public Builder setTo(@Nullable String to) {
  119. this.to = to;
  120. return this;
  121. }
  122. public SearchRequest build() {
  123. requireNonNull(project, "Project is required");
  124. checkArgument(pageSize <= MAX_SIZE, "Page size must be lower than or equal to " + MAX_SIZE);
  125. return new SearchRequest(this);
  126. }
  127. }
  128. }