From 2e8207b81c95188b058ac6e1a8ce2478e628ab8e Mon Sep 17 00:00:00 2001 From: Michael Charfadi Date: Wed, 12 Jun 2024 09:38:47 +0200 Subject: [PATCH] [3614] Add the ability to contribute additional payloads to representation subscriptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: https://github.com/eclipse-sirius/sirius-web/issues/3614 Signed-off-by: Michaƫl Charfadi --- CHANGELOG.adoc | 2 +- ...sentationEventProcessorFluxCustomizer.java | 31 +++++++++++++++++++ .../SiriusWebStarterConfiguration.java | 22 ++++++++++++- 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 packages/core/backend/sirius-components-collaborative/src/main/java/org/eclipse/sirius/components/collaborative/api/IRepresentationEventProcessorFluxCustomizer.java diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 0973d172d77..e09935a9576 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -68,7 +68,7 @@ More existing APIs will be migrated to this new common pattern. - https://github.com/eclipse-sirius/sirius-web/issues/3344[#3344] [core] Add support for reloading representations from the database - https://github.com/eclipse-sirius/sirius-web/issues/3553[#3553] [core] Add RepresentationFactory extension point - https://github.com/eclipse-sirius/sirius-web/issues/3587[#3587] [sirius-web] Add an extension point to contribute new project cards - +- https://github.com/eclipse-sirius/sirius-web/issues/3614[#3614] [core] Add the ability to contribute additional payloads to representation subscriptions === Improvements diff --git a/packages/core/backend/sirius-components-collaborative/src/main/java/org/eclipse/sirius/components/collaborative/api/IRepresentationEventProcessorFluxCustomizer.java b/packages/core/backend/sirius-components-collaborative/src/main/java/org/eclipse/sirius/components/collaborative/api/IRepresentationEventProcessorFluxCustomizer.java new file mode 100644 index 00000000000..73c99962de8 --- /dev/null +++ b/packages/core/backend/sirius-components-collaborative/src/main/java/org/eclipse/sirius/components/collaborative/api/IRepresentationEventProcessorFluxCustomizer.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2024 Obeo. + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.components.collaborative.api; + +import org.eclipse.sirius.components.core.api.IInput; +import org.eclipse.sirius.components.core.api.IPayload; + +import reactor.core.publisher.Flux; + +/** + * Can be used to customize outputEvents of IRepresentationEventProcessor. + * + * @author mcharfadi + */ +public interface IRepresentationEventProcessorFluxCustomizer { + + boolean canHandle(String editingContextId, IRepresentationConfiguration configuration, IInput input, IRepresentationEventProcessor representationEventProcessor); + + Flux customize(String editingContextId, IRepresentationConfiguration configuration, IInput input, IRepresentationEventProcessor representationEventProcessor, Flux outputEvents); + +} diff --git a/packages/sirius-web/backend/sirius-web-starter/src/main/java/org/eclipse/sirius/web/starter/SiriusWebStarterConfiguration.java b/packages/sirius-web/backend/sirius-web-starter/src/main/java/org/eclipse/sirius/web/starter/SiriusWebStarterConfiguration.java index d47025ad4d3..456ad7af546 100644 --- a/packages/sirius-web/backend/sirius-web-starter/src/main/java/org/eclipse/sirius/web/starter/SiriusWebStarterConfiguration.java +++ b/packages/sirius-web/backend/sirius-web-starter/src/main/java/org/eclipse/sirius/web/starter/SiriusWebStarterConfiguration.java @@ -12,10 +12,14 @@ *******************************************************************************/ package org.eclipse.sirius.web.starter; +import java.util.List; +import java.util.Objects; import java.util.concurrent.Executors; import org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessorRegistry; import org.eclipse.sirius.components.collaborative.api.IRepresentationConfiguration; +import org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessor; +import org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessorFluxCustomizer; import org.eclipse.sirius.components.collaborative.api.ISubscriptionManagerFactory; import org.eclipse.sirius.components.collaborative.editingcontext.api.IEditingContextEventProcessorExecutorServiceProvider; import org.eclipse.sirius.components.collaborative.representations.SubscriptionManager; @@ -68,6 +72,12 @@ }) public class SiriusWebStarterConfiguration { + private final List representationEventProcessorFluxCustomizers; + + public SiriusWebStarterConfiguration(List representationEventProcessorFluxCustomizers) { + this.representationEventProcessorFluxCustomizers = Objects.requireNonNull(representationEventProcessorFluxCustomizers); + } + @Bean @ConditionalOnMissingBean(IEditingContextEventProcessorExecutorServiceProvider.class) public IEditingContextEventProcessorExecutorServiceProvider editingContextEventProcessorExecutorServiceProvider() { @@ -123,12 +133,22 @@ public IEventProcessorSubscriptionProvider eventProcessorSubscriptionProvider(IE public Flux getSubscription(String editingContextId, IRepresentationConfiguration representationConfiguration, IInput input) { return editingContextEventProcessorRegistry.getOrCreateEditingContextEventProcessor(editingContextId) .flatMap(processor -> processor.acquireRepresentationEventProcessor(representationConfiguration, input)) - .map(representationEventProcessor -> representationEventProcessor.getOutputEvents(input)) + .map(representationEventProcessor -> customizeFlux(editingContextId, representationConfiguration, input, representationEventProcessor)) .orElse(Flux.empty()); } }; } + private Flux customizeFlux(String editingContextId, IRepresentationConfiguration representationConfiguration, IInput input, IRepresentationEventProcessor representationEventProcessor) { + Flux flux = representationEventProcessor.getOutputEvents(input); + for (IRepresentationEventProcessorFluxCustomizer representationEventProcessorFluxCustomizer : this.representationEventProcessorFluxCustomizers) { + if (representationEventProcessorFluxCustomizer.canHandle(editingContextId, representationConfiguration, input, representationEventProcessor)) { + flux = representationEventProcessorFluxCustomizer.customize(editingContextId, representationConfiguration, input, representationEventProcessor, flux); + } + } + return flux; + } + @Bean @ConditionalOnMissingBean public IEditingContextDispatcher editingContextDispatcher(IEditingContextEventProcessorRegistry editingContextEventProcessorRegistry, IMessageService messageService) {