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.

CreationMethod.java 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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.project;
  21. import java.util.Arrays;
  22. public enum CreationMethod {
  23. UNKNOWN(Category.UNKNOWN, false, true),
  24. LOCAL_API(Category.LOCAL, false, true),
  25. LOCAL_BROWSER(Category.LOCAL, true, true),
  26. ALM_IMPORT_API(Category.ALM_IMPORT, false, false),
  27. ALM_IMPORT_BROWSER(Category.ALM_IMPORT, true, false),
  28. ALM_IMPORT_MONOREPO_API(Category.ALM_IMPORT_MONOREPO, false, false),
  29. ALM_IMPORT_MONOREPO_BROWSER(Category.ALM_IMPORT_MONOREPO, true, false),
  30. SCANNER_API(Category.SCANNER, false, true),
  31. SCANNER_API_DEVOPS_AUTO_CONFIG(Category.SCANNER, false, false);
  32. private final Category category;
  33. private final boolean isCreatedViaBrowser;
  34. private final boolean isLocal;
  35. CreationMethod(Category category, boolean isCreatedViaBrowser, boolean isLocal) {
  36. this.isCreatedViaBrowser = isCreatedViaBrowser;
  37. this.category = category;
  38. this.isLocal = isLocal;
  39. }
  40. public static CreationMethod getCreationMethod(Category category, boolean isBrowserCall) {
  41. return Arrays.stream(CreationMethod.values())
  42. .filter(creationMethod -> creationMethod.getCategory().equals(category))
  43. .filter(creationMethod -> creationMethod.isCreatedViaBrowser() == isBrowserCall)
  44. .findAny()
  45. .orElse(UNKNOWN);
  46. }
  47. private boolean isCreatedViaBrowser() {
  48. return isCreatedViaBrowser;
  49. }
  50. private Category getCategory() {
  51. return category;
  52. }
  53. public boolean isLocal() {
  54. return isLocal;
  55. }
  56. public enum Category {
  57. UNKNOWN, LOCAL, ALM_IMPORT, ALM_IMPORT_MONOREPO, SCANNER
  58. }
  59. }