Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

UsersSearchRequest.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2023 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.common.user.service;
  21. import java.time.OffsetDateTime;
  22. import java.util.Optional;
  23. import javax.annotation.CheckForNull;
  24. import javax.annotation.Nullable;
  25. import org.sonar.api.utils.DateUtils;
  26. import org.sonar.api.utils.MessageException;
  27. import org.sonar.server.exceptions.ServerException;
  28. public class UsersSearchRequest {
  29. private final Integer page;
  30. private final Integer pageSize;
  31. private final String query;
  32. private final boolean deactivated;
  33. private final Boolean managed;
  34. private final OffsetDateTime lastConnectionDateFrom;
  35. private final OffsetDateTime lastConnectionDateTo;
  36. private final OffsetDateTime sonarLintLastConnectionDateFrom;
  37. private final OffsetDateTime sonarLintLastConnectionDateTo;
  38. private UsersSearchRequest(Builder builder) {
  39. this.page = builder.page;
  40. this.pageSize = builder.pageSize;
  41. this.query = builder.query;
  42. this.deactivated = builder.deactivated;
  43. this.managed = builder.managed;
  44. try {
  45. this.lastConnectionDateFrom = Optional.ofNullable(builder.lastConnectionDateFrom).map(DateUtils::parseOffsetDateTime).orElse(null);
  46. this.lastConnectionDateTo = Optional.ofNullable(builder.lastConnectionDateTo).map(DateUtils::parseOffsetDateTime).orElse(null);
  47. this.sonarLintLastConnectionDateFrom = Optional.ofNullable(builder.sonarLintLastConnectionDateFrom).map(DateUtils::parseOffsetDateTime).orElse(null);
  48. this.sonarLintLastConnectionDateTo = Optional.ofNullable(builder.sonarLintLastConnectionDateTo).map(DateUtils::parseOffsetDateTime).orElse(null);
  49. } catch (MessageException me) {
  50. throw new ServerException(400, me.getMessage());
  51. }
  52. }
  53. public Integer getPage() {
  54. return page;
  55. }
  56. public Integer getPageSize() {
  57. return pageSize;
  58. }
  59. @CheckForNull
  60. public String getQuery() {
  61. return query;
  62. }
  63. public boolean isDeactivated() {
  64. return deactivated;
  65. }
  66. @CheckForNull
  67. public Boolean isManaged() {
  68. return managed;
  69. }
  70. public Optional<OffsetDateTime> getLastConnectionDateFrom() {
  71. return Optional.ofNullable(lastConnectionDateFrom);
  72. }
  73. public Optional<OffsetDateTime> getLastConnectionDateTo() {
  74. return Optional.ofNullable(lastConnectionDateTo);
  75. }
  76. public Optional<OffsetDateTime> getSonarLintLastConnectionDateFrom() {
  77. return Optional.ofNullable(sonarLintLastConnectionDateFrom);
  78. }
  79. public Optional<OffsetDateTime> getSonarLintLastConnectionDateTo() {
  80. return Optional.ofNullable(sonarLintLastConnectionDateTo);
  81. }
  82. public static Builder builder() {
  83. return new Builder();
  84. }
  85. public static class Builder {
  86. private Integer page;
  87. private Integer pageSize;
  88. private String query;
  89. private boolean deactivated;
  90. private Boolean managed;
  91. private String lastConnectionDateFrom;
  92. private String lastConnectionDateTo;
  93. private String sonarLintLastConnectionDateFrom;
  94. private String sonarLintLastConnectionDateTo;
  95. private Builder() {
  96. // enforce factory method use
  97. }
  98. public Builder setPage(Integer page) {
  99. this.page = page;
  100. return this;
  101. }
  102. public Builder setPageSize(Integer pageSize) {
  103. this.pageSize = pageSize;
  104. return this;
  105. }
  106. public Builder setQuery(@Nullable String query) {
  107. this.query = query;
  108. return this;
  109. }
  110. public Builder setDeactivated(boolean deactivated) {
  111. this.deactivated = deactivated;
  112. return this;
  113. }
  114. public Builder setManaged(@Nullable Boolean managed) {
  115. this.managed = managed;
  116. return this;
  117. }
  118. public Builder setLastConnectionDateFrom(@Nullable String lastConnectionDateFrom) {
  119. this.lastConnectionDateFrom = lastConnectionDateFrom;
  120. return this;
  121. }
  122. public Builder setLastConnectionDateTo(@Nullable String lastConnectionDateTo) {
  123. this.lastConnectionDateTo = lastConnectionDateTo;
  124. return this;
  125. }
  126. public Builder setSonarLintLastConnectionDateFrom(@Nullable String sonarLintLastConnectionDateFrom) {
  127. this.sonarLintLastConnectionDateFrom = sonarLintLastConnectionDateFrom;
  128. return this;
  129. }
  130. public Builder setSonarLintLastConnectionDateTo(@Nullable String sonarLintLastConnectionDateTo) {
  131. this.sonarLintLastConnectionDateTo = sonarLintLastConnectionDateTo;
  132. return this;
  133. }
  134. public UsersSearchRequest build() {
  135. return new UsersSearchRequest(this);
  136. }
  137. }
  138. }