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.

UserNewValue.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 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.db.audit.model;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. import java.util.Objects;
  24. import javax.annotation.CheckForNull;
  25. import javax.annotation.Nullable;
  26. import org.sonar.api.utils.DateUtils;
  27. import org.sonar.db.user.UserDto;
  28. import static java.util.Objects.requireNonNull;
  29. public class UserNewValue extends NewValue {
  30. /**
  31. * @deprecated The uuids in the audit logs are not product requirement anymore and will be removed in 11.x
  32. */
  33. @Deprecated(since = "10.2")
  34. private String userUuid;
  35. private String userLogin;
  36. @Nullable
  37. private String name;
  38. @Nullable
  39. private String email;
  40. @Nullable
  41. private Boolean isActive;
  42. private List<String> scmAccounts = new ArrayList<>();
  43. @Nullable
  44. private String externalId;
  45. @Nullable
  46. private String externalLogin;
  47. @Nullable
  48. private String externalIdentityProvider;
  49. @Nullable
  50. private Boolean local;
  51. @Nullable
  52. private Long lastConnectionDate;
  53. public UserNewValue(String userUuid, String userLogin) {
  54. this.userUuid = requireNonNull(userUuid);
  55. this.userLogin = requireNonNull(userLogin);
  56. }
  57. public UserNewValue(UserDto userDto) {
  58. this.userUuid = userDto.getUuid();
  59. this.userLogin = userDto.getLogin();
  60. this.name = userDto.getName();
  61. this.email = userDto.getEmail();
  62. this.isActive = userDto.isActive();
  63. this.scmAccounts = userDto.getSortedScmAccounts();
  64. this.externalId = userDto.getExternalId();
  65. this.externalLogin = userDto.getExternalLogin();
  66. this.externalIdentityProvider = userDto.getExternalIdentityProvider();
  67. this.local = userDto.isLocal();
  68. this.lastConnectionDate = userDto.getLastConnectionDate();
  69. }
  70. /**
  71. * @deprecated The uuids in the audit logs are not product requirement anymore and will be removed in 11.x
  72. */
  73. @Deprecated(since = "10.2")
  74. public String getUserUuid() {
  75. return this.userUuid;
  76. }
  77. public String getUserLogin() {
  78. return this.userLogin;
  79. }
  80. @CheckForNull
  81. public String getName() {
  82. return this.name;
  83. }
  84. @CheckForNull
  85. public String getEmail() {
  86. return this.email;
  87. }
  88. @CheckForNull
  89. public Boolean isActive() {
  90. return this.isActive;
  91. }
  92. public List<String> getScmAccounts() {
  93. return this.scmAccounts;
  94. }
  95. @CheckForNull
  96. public String getExternalId() {
  97. return this.externalId;
  98. }
  99. @CheckForNull
  100. public String getExternalLogin() {
  101. return this.externalLogin;
  102. }
  103. @CheckForNull
  104. public String getExternalIdentityProvider() {
  105. return this.externalIdentityProvider;
  106. }
  107. @CheckForNull
  108. public Boolean isLocal() {
  109. return this.local;
  110. }
  111. @CheckForNull
  112. public Long getLastConnectionDate() {
  113. return this.lastConnectionDate;
  114. }
  115. @Override
  116. public String toString() {
  117. StringBuilder sb = new StringBuilder("{");
  118. addField(sb, "\"userUuid\": ", this.userUuid, true);
  119. addField(sb, "\"userLogin\": ", this.userLogin, true);
  120. addField(sb, "\"name\": ", this.name, true);
  121. addField(sb, "\"email\": ", this.email, true);
  122. addField(sb, "\"isActive\": ", Objects.toString(this.isActive, ""), false);
  123. addField(sb, "\"scmAccounts\": ", String.join(",", scmAccounts), true);
  124. addField(sb, "\"externalId\": ", this.externalId, true);
  125. addField(sb, "\"externalLogin\": ", this.externalLogin, true);
  126. addField(sb, "\"externalIdentityProvider\": ", this.externalIdentityProvider, true);
  127. addField(sb, "\"local\": ", Objects.toString(this.local, ""), false);
  128. addField(sb, "\"lastConnectionDate\": ", this.lastConnectionDate == null ?
  129. "" : DateUtils.formatDateTime(this.lastConnectionDate), true);
  130. endString(sb);
  131. return sb.toString();
  132. }
  133. }