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.

PropertyNewValue.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2022 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 javax.annotation.CheckForNull;
  22. import javax.annotation.Nullable;
  23. import org.sonar.db.property.PropertyDto;
  24. public class PropertyNewValue extends NewValue {
  25. private String propertyKey;
  26. @Nullable
  27. private String propertyValue;
  28. @Nullable
  29. private String userUuid;
  30. @Nullable
  31. private String userLogin;
  32. @Nullable
  33. private String componentUuid;
  34. @Nullable
  35. private String componentKey;
  36. @Nullable
  37. private String componentName;
  38. @Nullable
  39. private String qualifier;
  40. public PropertyNewValue(PropertyDto propertyDto, @Nullable String userLogin, @Nullable String componentKey, @Nullable String componentName, @Nullable String qualifier) {
  41. this.propertyKey = propertyDto.getKey();
  42. this.userUuid = propertyDto.getUserUuid();
  43. this.userLogin = userLogin;
  44. this.componentUuid = propertyDto.getComponentUuid();
  45. this.componentKey = componentKey;
  46. this.componentName = componentName;
  47. this.qualifier = qualifier;
  48. setValue(propertyKey, propertyDto.getValue());
  49. }
  50. public PropertyNewValue(String propertyKey) {
  51. this.propertyKey = propertyKey;
  52. }
  53. public PropertyNewValue(String propertyKey, @Nullable String userUuid, String userLogin) {
  54. this.propertyKey = propertyKey;
  55. this.userUuid = userUuid;
  56. this.userLogin = userLogin;
  57. }
  58. public PropertyNewValue(String propertyKey, String propertyValue) {
  59. this.propertyKey = propertyKey;
  60. setValue(propertyKey, propertyValue);
  61. }
  62. public PropertyNewValue(String propertyKey, @Nullable String projectUuid, @Nullable String componentKey,
  63. @Nullable String componentName, @Nullable String qualifier, @Nullable String userUuid) {
  64. this.propertyKey = propertyKey;
  65. this.componentUuid = projectUuid;
  66. this.componentKey = componentKey;
  67. this.componentName = componentName;
  68. this.userUuid = userUuid;
  69. this.qualifier = qualifier;
  70. }
  71. public String getPropertyKey() {
  72. return this.propertyKey;
  73. }
  74. @CheckForNull
  75. public String getPropertyValue() {
  76. return this.propertyValue;
  77. }
  78. @CheckForNull
  79. public String getUserUuid() {
  80. return this.userUuid;
  81. }
  82. @CheckForNull
  83. public String getUserLogin() {
  84. return this.userLogin;
  85. }
  86. @CheckForNull
  87. public String getComponentUuid() {
  88. return this.componentUuid;
  89. }
  90. @CheckForNull
  91. public String getComponentKey() {
  92. return this.componentKey;
  93. }
  94. @CheckForNull
  95. public String getComponentName() {
  96. return this.componentName;
  97. }
  98. @CheckForNull
  99. public String getQualifier() {
  100. return this.qualifier;
  101. }
  102. @Override
  103. public String toString() {
  104. StringBuilder sb = new StringBuilder("{");
  105. addField(sb, "\"propertyKey\": ", this.propertyKey, true);
  106. addField(sb, "\"propertyValue\": ", this.propertyValue, true);
  107. addField(sb, "\"userUuid\": ", this.userUuid, true);
  108. addField(sb, "\"userLogin\": ", this.userLogin, true);
  109. addField(sb, "\"componentUuid\": ", this.componentUuid, true);
  110. addField(sb, "\"componentKey\": ", this.componentKey, true);
  111. addField(sb, "\"componentName\": ", this.componentName, true);
  112. addField(sb, "\"qualifier\": ", getQualifier(this.qualifier), true);
  113. endString(sb);
  114. return sb.toString();
  115. }
  116. private void setValue(String propertyKey, String value) {
  117. if (!propertyKey.contains(".secured")) {
  118. this.propertyValue = value;
  119. }
  120. }
  121. }