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.

NewComponent.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.component;
  21. import javax.annotation.concurrent.Immutable;
  22. import static java.util.Objects.requireNonNull;
  23. import static org.sonar.api.resources.Qualifiers.PROJECT;
  24. import static org.sonar.db.component.ComponentValidator.checkComponentKey;
  25. import static org.sonar.db.component.ComponentValidator.checkComponentName;
  26. import static org.sonar.db.component.ComponentValidator.checkComponentQualifier;
  27. @Immutable
  28. public class NewComponent {
  29. private final String organizationUuid;
  30. private final String key;
  31. private final String qualifier;
  32. private final String name;
  33. private final boolean isPrivate;
  34. private NewComponent(NewComponent.Builder builder) {
  35. this.organizationUuid = builder.organizationUuid;
  36. this.key = builder.key;
  37. this.qualifier = builder.qualifier;
  38. this.name = builder.name;
  39. this.isPrivate = builder.isPrivate;
  40. }
  41. public static Builder newComponentBuilder() {
  42. return new Builder();
  43. }
  44. public String getOrganizationUuid() {
  45. return organizationUuid;
  46. }
  47. public String key() {
  48. return key;
  49. }
  50. public String name() {
  51. return name;
  52. }
  53. public String qualifier() {
  54. return qualifier;
  55. }
  56. public boolean isPrivate() {
  57. return isPrivate;
  58. }
  59. public static class Builder {
  60. private String organizationUuid;
  61. private String key;
  62. private String qualifier = PROJECT;
  63. private String name;
  64. private boolean isPrivate = false;
  65. private Builder() {
  66. // use static factory method newComponentBuilder()
  67. }
  68. public Builder setOrganizationUuid(String organizationUuid) {
  69. this.organizationUuid = organizationUuid;
  70. return this;
  71. }
  72. public Builder setKey(String key) {
  73. this.key = key;
  74. return this;
  75. }
  76. public Builder setQualifier(String qualifier) {
  77. this.qualifier = qualifier;
  78. return this;
  79. }
  80. public Builder setName(String name) {
  81. this.name = name;
  82. return this;
  83. }
  84. public Builder setPrivate(boolean isPrivate) {
  85. this.isPrivate = isPrivate;
  86. return this;
  87. }
  88. public NewComponent build() {
  89. requireNonNull(organizationUuid, "organization uuid can't be null");
  90. checkComponentKey(key);
  91. checkComponentName(name);
  92. checkComponentQualifier(qualifier);
  93. return new NewComponent(this);
  94. }
  95. }
  96. }