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.

ComponentNewValue.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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.Objects;
  22. import javax.annotation.CheckForNull;
  23. import javax.annotation.Nullable;
  24. import org.sonar.db.component.ComponentDto;
  25. import org.sonar.db.project.ProjectDto;
  26. import static java.util.Objects.requireNonNull;
  27. public class ComponentNewValue extends NewValue {
  28. /**
  29. * @deprecated The uuids in the audit logs are not product requirement anymore and will be removed in 11.x
  30. */
  31. @Deprecated(since = "10.2")
  32. private final String componentUuid;
  33. private final String componentKey;
  34. private final String componentName;
  35. private final String description;
  36. private final Boolean isPrivate;
  37. private final String qualifier;
  38. private Boolean isEnabled;
  39. private String path;
  40. public ComponentNewValue(ProjectDto project) {
  41. this(project.getUuid(), project.getName(), project.getKey(), project.isPrivate(), project.getDescription(), project.getQualifier());
  42. }
  43. public ComponentNewValue(ComponentDto component) {
  44. this(component.uuid(), component.name(), component.getKey(), component.isPrivate(), component.description(), component.qualifier());
  45. }
  46. public ComponentNewValue(String componentUuid, String componentName, String componentKey, String qualifier) {
  47. this(componentUuid, componentName, componentKey, null, null, qualifier);
  48. }
  49. public ComponentNewValue(String componentUuid, String componentName, String componentKey, boolean isPrivate, String qualifier) {
  50. this(componentUuid, isPrivate, componentName, componentKey, null, qualifier);
  51. }
  52. public ComponentNewValue(String uuid, String name, String key, boolean enabled, String path, String qualifier) {
  53. this(uuid, name, key, null, null, qualifier);
  54. this.isEnabled = enabled;
  55. this.path = path;
  56. }
  57. public ComponentNewValue(String uuid, @Nullable Boolean isPrivate, String name, String key, @Nullable String description, String qualifier) {
  58. this(uuid, name, key, isPrivate, description, qualifier);
  59. }
  60. private ComponentNewValue(String uuid, String name, String key, @Nullable Boolean isPrivate, @Nullable String description, String qualifier) {
  61. this.componentUuid = requireNonNull(uuid);
  62. this.componentName = name;
  63. this.componentKey = key;
  64. this.isPrivate = isPrivate;
  65. this.description = description;
  66. this.qualifier = qualifier;
  67. }
  68. /**
  69. * @deprecated The uuids in the audit logs are not product requirement anymore and will be removed in 11.x
  70. */
  71. @Deprecated(since = "10.2")
  72. public String getComponentUuid() {
  73. return componentUuid;
  74. }
  75. public String getComponentName() {
  76. return componentName;
  77. }
  78. @CheckForNull
  79. public String getDescription() {
  80. return description;
  81. }
  82. public String getComponentKey() {
  83. return componentKey;
  84. }
  85. @CheckForNull
  86. public Boolean isPrivate() {
  87. return isPrivate;
  88. }
  89. public String getQualifier() {
  90. return qualifier;
  91. }
  92. @Override
  93. public String toString() {
  94. StringBuilder sb = new StringBuilder("{");
  95. addField(sb, "\"componentUuid\": ", this.componentUuid, true);
  96. addField(sb, "\"componentKey\": ", this.componentKey, true);
  97. addField(sb, "\"componentName\": ", this.componentName, true);
  98. addField(sb, "\"qualifier\": ", getQualifier(qualifier), true);
  99. addField(sb, "\"description\": ", this.description, true);
  100. addField(sb, "\"path\": ", this.path, true);
  101. addField(sb, "\"isPrivate\": ", Objects.toString(this.isPrivate, ""), false);
  102. addField(sb, "\"isEnabled\": ", Objects.toString(this.isEnabled, ""), false);
  103. endString(sb);
  104. return sb.toString();
  105. }
  106. }