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

ProjectWsRef.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 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.permission.ws;
  21. import java.util.Optional;
  22. import javax.annotation.CheckForNull;
  23. import javax.annotation.Nullable;
  24. import static org.sonar.server.exceptions.BadRequestException.checkRequest;
  25. /**
  26. * Reference to a project <b>as defined by web service callers</b>. It allows to reference a project
  27. * by its (functional) key or by its (technical) uuid.
  28. *
  29. * <p>Factory methods guarantee that the project id and project key are not provided at the same time.</p>
  30. */
  31. public class ProjectWsRef {
  32. private static final String MSG_ID_OR_KEY_MUST_BE_PROVIDED = "Project id or project key can be provided, not both.";
  33. private final String uuid;
  34. private final String key;
  35. private ProjectWsRef(@Nullable String uuid, @Nullable String key) {
  36. this.uuid = uuid;
  37. this.key = key;
  38. checkRequest(this.uuid != null ^ this.key != null, MSG_ID_OR_KEY_MUST_BE_PROVIDED);
  39. }
  40. public static Optional<ProjectWsRef> newOptionalWsProjectRef(@Nullable String uuid, @Nullable String key) {
  41. if (uuid == null && key == null) {
  42. return Optional.empty();
  43. }
  44. return Optional.of(new ProjectWsRef(uuid, key));
  45. }
  46. public static ProjectWsRef newWsProjectRef(@Nullable String uuid, @Nullable String key) {
  47. return new ProjectWsRef(uuid, key);
  48. }
  49. @CheckForNull
  50. public String uuid() {
  51. return this.uuid;
  52. }
  53. @CheckForNull
  54. public String key() {
  55. return this.key;
  56. }
  57. }