PageRenderTime 68ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/legacy-stub/src/main/java/com/atlassian/webhooks/api/register/WebHookPluginRegistration.java

https://bitbucket.org/atlassian/atlassian-webhooks-plugin
Java | 115 lines | 91 code | 17 blank | 7 comment | 0 complexity | 872547c649e7d06919c1ef0f7d50c0c6 MD5 | raw file
  1. package com.atlassian.webhooks.api.register;
  2. import com.atlassian.webhooks.spi.*;
  3. import com.google.common.base.Function;
  4. import com.google.common.collect.ImmutableList;
  5. import com.google.common.collect.ImmutableMap;
  6. import com.google.common.collect.ImmutableSet;
  7. import io.atlassian.fugue.Option;
  8. import javax.annotation.concurrent.Immutable;
  9. import java.util.List;
  10. import java.util.Map;
  11. import java.util.Set;
  12. import static com.google.common.collect.Iterables.concat;
  13. import static com.google.common.collect.Iterables.transform;
  14. /**
  15. * This class represent a self-sufficient set of webhook functionality
  16. * (events, serializers, variables providers...) registered by a plug-in.
  17. * <p>
  18. * Most webhook related stuff is registered by creating these objects, with a few exceptions
  19. * like {@link com.atlassian.webhooks.spi.RequestSigner} or {@link com.atlassian.webhooks.spi.WebHookListenerAccessVoter}
  20. */
  21. @Deprecated
  22. @Immutable
  23. public class WebHookPluginRegistration {
  24. private final Map<Class, UriVariablesProvider> uriVariablesProviders;
  25. private final Map<Class, EventSerializer> eventSerializers;
  26. private final Option<WebHookPluginRegistrationFactory.CloudCondition> cloudCondition;
  27. private final List<WebHookEventSection> sections;
  28. private final List<WebHooksHtmlPanel> panels;
  29. private final Set<RequestSigner> requestSigners;
  30. private final Set<WebHookListenerActionValidator> validators;
  31. private final Set<RequestSigner2> requestSigners2;
  32. private final Set<QueryParamsProvider> queryParamsProviders;
  33. WebHookPluginRegistration(Map<Class, UriVariablesProvider> uriVariablesProviders,
  34. Map<Class, EventSerializer> serializers,
  35. Option<WebHookPluginRegistrationFactory.CloudCondition> cloudCondition,
  36. Iterable<WebHookEventSection> sections,
  37. List<WebHooksHtmlPanel> panels,
  38. Set<RequestSigner> requestSigners,
  39. Set<RequestSigner2> requestSigners2,
  40. Set<WebHookListenerActionValidator> validators,
  41. Set<QueryParamsProvider> queryParamsProviders) {
  42. this.requestSigners2 = requestSigners2;
  43. this.queryParamsProviders = queryParamsProviders;
  44. this.requestSigners = ImmutableSet.copyOf(requestSigners);
  45. this.validators = ImmutableSet.copyOf(validators);
  46. this.sections = ImmutableList.copyOf(sections);
  47. this.panels = ImmutableList.copyOf(panels);
  48. this.uriVariablesProviders = ImmutableMap.copyOf(uriVariablesProviders);
  49. this.cloudCondition = cloudCondition;
  50. this.eventSerializers = ImmutableMap.copyOf(serializers);
  51. }
  52. public static WebHookPluginRegistrationBuilder builder() {
  53. return new WebHookPluginRegistrationBuilder();
  54. }
  55. public Map<Class, UriVariablesProvider> getUriVariablesProviders() {
  56. return uriVariablesProviders;
  57. }
  58. public Map<Class, EventSerializer> getEventSerializers() {
  59. return eventSerializers;
  60. }
  61. public Option<WebHookPluginRegistrationFactory.CloudCondition> getCloudCondition() {
  62. return cloudCondition;
  63. }
  64. public List<WebHookEventSection> getSections() {
  65. return sections;
  66. }
  67. private Iterable<WebHookEventGroup> getGroups() {
  68. return concat(transform(sections, new Function<WebHookEventSection, Set<WebHookEventGroup>>() {
  69. @Override
  70. public Set<WebHookEventGroup> apply(final WebHookEventSection section) {
  71. return section.getGroups();
  72. }
  73. }));
  74. }
  75. public Iterable<RegisteredWebHookEvent> getRegistrations() {
  76. return concat(transform(getGroups(), new Function<WebHookEventGroup, Iterable<RegisteredWebHookEvent>>() {
  77. @Override
  78. public Iterable<RegisteredWebHookEvent> apply(final WebHookEventGroup group) {
  79. return group.getEvents();
  80. }
  81. }));
  82. }
  83. public List<WebHooksHtmlPanel> getPanels() {
  84. return panels;
  85. }
  86. public Set<WebHookListenerActionValidator> getValidators() {
  87. return validators;
  88. }
  89. public Set<RequestSigner> getRequestSigners() {
  90. return requestSigners;
  91. }
  92. public Set<RequestSigner2> getRequestSigners2() {
  93. return requestSigners2;
  94. }
  95. public Set<QueryParamsProvider> getQueryParamsProviders() {
  96. return queryParamsProviders;
  97. }
  98. }