Skip to content

Commit

Permalink
[3614] Add the ability to contribute additional payloads to represent…
Browse files Browse the repository at this point in the history
…ation subscriptions

Bug: #3614
Signed-off-by: Michaël Charfadi <[email protected]>
  • Loading branch information
mcharfadi authored and sbegaudeau committed Jun 16, 2024
1 parent baf25fa commit 2e8207b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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<IPayload> customize(String editingContextId, IRepresentationConfiguration configuration, IInput input, IRepresentationEventProcessor representationEventProcessor, Flux<IPayload> outputEvents);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,6 +72,12 @@
})
public class SiriusWebStarterConfiguration {

private final List<IRepresentationEventProcessorFluxCustomizer> representationEventProcessorFluxCustomizers;

public SiriusWebStarterConfiguration(List<IRepresentationEventProcessorFluxCustomizer> representationEventProcessorFluxCustomizers) {
this.representationEventProcessorFluxCustomizers = Objects.requireNonNull(representationEventProcessorFluxCustomizers);
}

@Bean
@ConditionalOnMissingBean(IEditingContextEventProcessorExecutorServiceProvider.class)
public IEditingContextEventProcessorExecutorServiceProvider editingContextEventProcessorExecutorServiceProvider() {
Expand Down Expand Up @@ -123,12 +133,22 @@ public IEventProcessorSubscriptionProvider eventProcessorSubscriptionProvider(IE
public Flux<IPayload> 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<IPayload> customizeFlux(String editingContextId, IRepresentationConfiguration representationConfiguration, IInput input, IRepresentationEventProcessor representationEventProcessor) {
Flux<IPayload> 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) {
Expand Down

0 comments on commit 2e8207b

Please sign in to comment.