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.

OrganizationValidation.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2018 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.organization;
  21. import javax.annotation.CheckForNull;
  22. import javax.annotation.Nullable;
  23. public interface OrganizationValidation {
  24. int KEY_MIN_LENGTH = 1;
  25. int KEY_MAX_LENGTH = 255;
  26. int NAME_MIN_LENGTH = 1;
  27. int NAME_MAX_LENGTH = 255;
  28. int DESCRIPTION_MAX_LENGTH = 256;
  29. int URL_MAX_LENGTH = 256;
  30. /**
  31. * Ensures the specified argument is a valid key by failing with an exception if it is not so.
  32. * <p>
  33. * A valid key is non null and its length is between {@link #KEY_MIN_LENGTH} and {@link #KEY_MAX_LENGTH}.
  34. * </p>
  35. *
  36. * @return the argument
  37. *
  38. * @throws NullPointerException if argument is {@code null}.
  39. * @throws IllegalArgumentException if argument is not a valid key.
  40. */
  41. String checkKey(String keyCandidate);
  42. /**
  43. * Ensures the specified argument is a valid name by failing with an exception if it is not so.
  44. * <p>
  45. * A valid name is non null and its length is between {@link #NAME_MIN_LENGTH} and {@link #NAME_MAX_LENGTH}.
  46. * </p>
  47. *
  48. * @return the argument
  49. *
  50. * @throws NullPointerException if argument is {@code null}.
  51. * @throws IllegalArgumentException if argument is not a valid name.
  52. */
  53. String checkName(String nameCandidate);
  54. /**
  55. * Ensures the specified argument is either {@code null}, empty or a valid description by failing with an exception
  56. * if it is not so.
  57. * <p>
  58. * The length of a valid url can't be more than {@link #DESCRIPTION_MAX_LENGTH 256}.
  59. * </p>
  60. *
  61. * @return the argument
  62. *
  63. * @throws IllegalArgumentException if argument is not a valid description.
  64. */
  65. @CheckForNull
  66. String checkDescription(@Nullable String descriptionCandidate);
  67. /**
  68. * Ensures the specified argument is either {@code null}, empty or a valid URL by failing with an exception if it is
  69. * not so.
  70. * <p>
  71. * The length of a valid URL can't be more than {@link #URL_MAX_LENGTH 256}.
  72. * </p>
  73. *
  74. * @return the argument
  75. *
  76. * @throws IllegalArgumentException if argument is not a valid url.
  77. */
  78. @CheckForNull
  79. String checkUrl(@Nullable String urlCandidate);
  80. /**
  81. * Ensures the specified argument is either {@code null}, empty or a valid avatar URL by failing with an exception if
  82. * it is not so.
  83. * <p>
  84. * The length of a valid avatar URL can't be more than {@link #URL_MAX_LENGTH 256}.
  85. * </p>
  86. *
  87. * @return the argument
  88. *
  89. * @throws IllegalArgumentException if argument is not a valid avatar url.
  90. */
  91. @CheckForNull
  92. String checkAvatar(@Nullable String avatarCandidate);
  93. /**
  94. * Transforms the specified string into a valid key.
  95. *
  96. * @see #checkKey(String)
  97. */
  98. String generateKeyFrom(String source);
  99. }