Skip to content

Commit

Permalink
[3597] Remove representationEventProcessorClass from IRepresentationE…
Browse files Browse the repository at this point in the history
…ventProcessorFactory

Bug: #3597
Signed-off-by: Michaël Charfadi <[email protected]>
  • Loading branch information
mcharfadi committed Jun 11, 2024
1 parent 3cbb5fd commit c47ce4f
Show file tree
Hide file tree
Showing 40 changed files with 125 additions and 216 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

- https://github.com/eclipse-sirius/sirius-web/issues/3562[#3562] [sirius-web] Update displayed default model creation action.
+ Projects that have a nature and need the action to create an empty model will need to register the empty model action like it is done in `StudioEditingContextActionProvider`.
- https://github.com/eclipse-sirius/sirius-web/issues/3597[#3597] [core] `IRepresentationEventProcessorFactory`, `IRepresentationEventProcessor` and `IEditingContextEventProcessor` change to the signature of the methods in order to create RepresentationEventProcessor without the need of `Class<T> representationEventProcessorClass` to :
* `boolean canHandle(IRepresentationConfiguration configuration)`;
* `Optional<IRepresentationEventProcessor> createRepresentationEventProcessor(IRepresentationConfiguration configuration, IEditingContext editingContext)`;
* `public Optional<IRepresentationEventProcessor> acquireRepresentationEventProcessor(IRepresentationConfiguration configuration, IInput input)`;
* `Flux<IPayload> getSubscription(String editingContextId, IRepresentationConfiguration representationConfiguration, IInput input);`

=== Dependency update

Expand Down Expand Up @@ -70,6 +75,7 @@
- https://github.com/eclipse-sirius/sirius-web/issues/3558[#3558] [core] Avoid all representation migration overhead when not needed
- https://github.com/eclipse-sirius/sirius-web/issues/3595[#3595] [core] Avoid re-rendering the workbench when the selection does not really change
- https://github.com/eclipse-sirius/sirius-web/issues/3601[#3601] [sirius-web] Extract test helper classes to sirius-web-tests
- https://github.com/eclipse-sirius/sirius-web/issues/3597[#3597] [core] Improve the creation of `RepresentationEventProcessor`

== v2024.5.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,22 @@ public HierarchyEventProcessorFactory(IRepresentationSearchService representatio
}

@Override
public <T extends IRepresentationEventProcessor> boolean canHandle(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration) {
return IHierarchyEventProcessor.class.isAssignableFrom(representationEventProcessorClass) && configuration instanceof HierarchyConfiguration;
public boolean canHandle(IRepresentationConfiguration configuration) {
return configuration instanceof HierarchyConfiguration;
}

@Override
public <T extends IRepresentationEventProcessor> Optional<T> createRepresentationEventProcessor(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration,
IEditingContext editingContext) {
if (IHierarchyEventProcessor.class.isAssignableFrom(representationEventProcessorClass) && configuration instanceof HierarchyConfiguration) {
HierarchyConfiguration hierarchyConfiguration = (HierarchyConfiguration) configuration;
public Optional<IRepresentationEventProcessor> createRepresentationEventProcessor(IRepresentationConfiguration configuration, IEditingContext editingContext) {
if (configuration instanceof HierarchyConfiguration hierarchyConfiguration) {
var optionalHierarchy = this.representationSearchService.findById(editingContext, hierarchyConfiguration.getId(), Hierarchy.class);
if (optionalHierarchy.isPresent()) {
Hierarchy hierarchy = optionalHierarchy.get();

// @formatter:off
HierarchyContext hierarchyContext = new HierarchyContext(hierarchy);
IRepresentationEventProcessor hierarchyEventProcessor = new HierarchyEventProcessor(editingContext, hierarchyContext,
this.subscriptionManagerFactory.create(), this.hierarchyCreationService, this.representationSearchService);

return Optional.of(hierarchyEventProcessor)
.filter(representationEventProcessorClass::isInstance)
.map(representationEventProcessorClass::cast);
// @formatter:on
return Optional.of(hierarchyEventProcessor);
}
}
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2021 Obeo.
* Copyright (c) 2019, 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
Expand Down Expand Up @@ -29,7 +29,7 @@
public interface IEditingContextEventProcessor extends IDisposablePublisher {
String getEditingContextId();

<T extends IRepresentationEventProcessor> Optional<T> acquireRepresentationEventProcessor(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration, IInput input);
Optional<IRepresentationEventProcessor> acquireRepresentationEventProcessor(IRepresentationConfiguration configuration, IInput input);

List<IRepresentationEventProcessor> getRepresentationEventProcessors();

Expand Down Expand Up @@ -59,8 +59,7 @@ public String getEditingContextId() {
}

@Override
public <T extends IRepresentationEventProcessor> Optional<T> acquireRepresentationEventProcessor(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration,
IInput input) {
public Optional<IRepresentationEventProcessor> acquireRepresentationEventProcessor(IRepresentationConfiguration configuration, IInput input) {
return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Obeo.
* Copyright (c) 2019, 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
Expand All @@ -22,6 +22,5 @@
* @author sbegaudeau
*/
public interface IRepresentationEventProcessorComposedFactory {
<T extends IRepresentationEventProcessor> Optional<T> createRepresentationEventProcessor(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration,
IEditingContext editingContext);
Optional<IRepresentationEventProcessor> createRepresentationEventProcessor(IRepresentationConfiguration configuration, IEditingContext editingContext);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Obeo.
* Copyright (c) 2019, 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
Expand All @@ -22,8 +22,7 @@
* @author sbegaudeau
*/
public interface IRepresentationEventProcessorFactory {
<T extends IRepresentationEventProcessor> boolean canHandle(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration);
boolean canHandle(IRepresentationConfiguration configuration);

<T extends IRepresentationEventProcessor> Optional<T> createRepresentationEventProcessor(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration,
IEditingContext editingContext);
Optional<IRepresentationEventProcessor> createRepresentationEventProcessor(IRepresentationConfiguration configuration, IEditingContext editingContext);
}
Original file line number Diff line number Diff line change
Expand Up @@ -351,18 +351,14 @@ private void handleRepresentationInput(One<IPayload> payloadSink, IRepresentatio
}

@Override
public <T extends IRepresentationEventProcessor> Optional<T> acquireRepresentationEventProcessor(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration,
IInput input) {
public Optional<IRepresentationEventProcessor> acquireRepresentationEventProcessor(IRepresentationConfiguration configuration, IInput input) {
var getRepresentationEventProcessorSample = Timer.start(this.meterRegistry);

var optionalRepresentationEventProcessor = Optional.ofNullable(this.representationEventProcessors.get(configuration.getId()))
.map(RepresentationEventProcessorEntry::getRepresentationEventProcessor)
.filter(representationEventProcessorClass::isInstance)
.map(representationEventProcessorClass::cast);
.map(RepresentationEventProcessorEntry::getRepresentationEventProcessor);

if (!optionalRepresentationEventProcessor.isPresent()) {
optionalRepresentationEventProcessor = this.representationEventProcessorComposedFactory.createRepresentationEventProcessor(representationEventProcessorClass, configuration,
this.editingContext);
optionalRepresentationEventProcessor = this.representationEventProcessorComposedFactory.createRepresentationEventProcessor(configuration, this.editingContext);
if (optionalRepresentationEventProcessor.isPresent()) {
var representationEventProcessor = optionalRepresentationEventProcessor.get();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Obeo.
* Copyright (c) 2019, 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
Expand Down Expand Up @@ -42,14 +42,11 @@ public RepresentationEventProcessorComposedFactory(List<IRepresentationEventProc
}

@Override
public <T extends IRepresentationEventProcessor> Optional<T> createRepresentationEventProcessor(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration,
IEditingContext editingContext) {
// @formatter:off
public Optional<IRepresentationEventProcessor> createRepresentationEventProcessor(IRepresentationConfiguration configuration, IEditingContext editingContext) {
return this.factories.stream()
.filter(factory -> factory.canHandle(representationEventProcessorClass, configuration))
.filter(factory -> factory.canHandle(configuration))
.findFirst()
.flatMap(factory -> factory.createRepresentationEventProcessor(representationEventProcessorClass, configuration, editingContext));
// @formatter:on
.flatMap(factory -> factory.createRepresentationEventProcessor(configuration, editingContext));
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 Obeo.
* Copyright (c) 2022, 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
Expand All @@ -13,7 +13,6 @@
package org.eclipse.sirius.components.graphql.api;

import org.eclipse.sirius.components.collaborative.api.IRepresentationConfiguration;
import org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessor;
import org.eclipse.sirius.components.core.api.IInput;
import org.eclipse.sirius.components.core.api.IPayload;

Expand All @@ -25,8 +24,7 @@
* @author sbegaudeau
*/
public interface IEventProcessorSubscriptionProvider {
<T extends IRepresentationEventProcessor> Flux<IPayload> getSubscription(String editingContextId, Class<T> representationEventProcessorClass,
IRepresentationConfiguration representationConfiguration, IInput input);
Flux<IPayload> getSubscription(String editingContextId, IRepresentationConfiguration representationConfiguration, IInput input);

/**
* Implementation which does nothing, used for mocks in unit tests.
Expand All @@ -36,8 +34,7 @@ <T extends IRepresentationEventProcessor> Flux<IPayload> getSubscription(String
class NoOp implements IEventProcessorSubscriptionProvider {

@Override
public <T extends IRepresentationEventProcessor> Flux<IPayload> getSubscription(String editingContextId, Class<T> representationEventProcessorClass,
IRepresentationConfiguration representationConfiguration, IInput input) {
public Flux<IPayload> getSubscription(String editingContextId, IRepresentationConfiguration representationConfiguration, IInput input) {
return Flux.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.eclipse.sirius.components.collaborative.api.IRepresentationSearchService;
import org.eclipse.sirius.components.collaborative.api.ISubscriptionManagerFactory;
import org.eclipse.sirius.components.collaborative.deck.api.IDeckEventHandler;
import org.eclipse.sirius.components.collaborative.deck.api.IDeckEventProcessor;
import org.eclipse.sirius.components.collaborative.deck.service.DeckCreationService;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.deck.Deck;
Expand Down Expand Up @@ -57,14 +56,14 @@ public DeckEventProcessorFactory(IRepresentationSearchService representationSear
}

@Override
public <T extends IRepresentationEventProcessor> boolean canHandle(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration) {
return IDeckEventProcessor.class.isAssignableFrom(representationEventProcessorClass) && configuration instanceof DeckConfiguration;
public boolean canHandle(IRepresentationConfiguration configuration) {
return configuration instanceof DeckConfiguration;
}

@Override
public <T extends IRepresentationEventProcessor> Optional<T> createRepresentationEventProcessor(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration,
public Optional<IRepresentationEventProcessor> createRepresentationEventProcessor(IRepresentationConfiguration configuration,
IEditingContext editingContext) {
if (IDeckEventProcessor.class.isAssignableFrom(representationEventProcessorClass) && configuration instanceof DeckConfiguration deckConfiguration) {
if (configuration instanceof DeckConfiguration deckConfiguration) {
var optionalDeck = this.representationSearchService.findById(editingContext, deckConfiguration.getId(), Deck.class);
if (optionalDeck.isPresent()) {
Deck deck = optionalDeck.get();
Expand All @@ -73,7 +72,7 @@ public <T extends IRepresentationEventProcessor> Optional<T> createRepresentatio
IRepresentationEventProcessor deckEventProcessor = new DeckEventProcessor(editingContext, this.subscriptionManagerFactory.create(), this.deckCreationService, this.deckEventHandlers,
deckContext, this.representationPersistenceService, this.representationSearchService);

return Optional.of(deckEventProcessor).map(representationEventProcessorClass::cast);
return Optional.of(deckEventProcessor);
}
}
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023 Obeo.
* Copyright (c) 2023, 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
Expand All @@ -20,7 +20,6 @@

import org.eclipse.sirius.components.annotations.spring.graphql.SubscriptionDataFetcher;
import org.eclipse.sirius.components.collaborative.deck.DeckConfiguration;
import org.eclipse.sirius.components.collaborative.deck.api.IDeckEventProcessor;
import org.eclipse.sirius.components.collaborative.deck.dto.input.DeckEventInput;
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates;
Expand Down Expand Up @@ -64,7 +63,7 @@ public Publisher<DataFetcherResult<IPayload>> get(DataFetchingEnvironment enviro
localContext.put(LocalContextConstants.EDITING_CONTEXT_ID, input.editingContextId());
localContext.put(LocalContextConstants.REPRESENTATION_ID, input.deckId());

return this.exceptionWrapper.wrapFlux(() -> this.eventProcessorSubscriptionProvider.getSubscription(input.editingContextId(), IDeckEventProcessor.class, deckConfiguration, input), input)
return this.exceptionWrapper.wrapFlux(() -> this.eventProcessorSubscriptionProvider.getSubscription(input.editingContextId(), deckConfiguration, input), input)
.map(payload -> DataFetcherResult.<IPayload>newResult()
.data(payload)
.localContext(localContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.eclipse.sirius.components.collaborative.diagrams.api.DiagramConfiguration;
import org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramCreationService;
import org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramEventHandler;
import org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramEventProcessor;
import org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramInputReferencePositionProvider;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService;
Expand Down Expand Up @@ -71,14 +70,13 @@ public DiagramEventProcessorFactory(RepresentationEventProcessorFactoryConfigura
}

@Override
public <T extends IRepresentationEventProcessor> boolean canHandle(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration) {
return IDiagramEventProcessor.class.isAssignableFrom(representationEventProcessorClass) && configuration instanceof DiagramConfiguration;
public boolean canHandle(IRepresentationConfiguration configuration) {
return configuration instanceof DiagramConfiguration;
}

@Override
public <T extends IRepresentationEventProcessor> Optional<T> createRepresentationEventProcessor(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration,
IEditingContext editingContext) {
if (IDiagramEventProcessor.class.isAssignableFrom(representationEventProcessorClass) && configuration instanceof DiagramConfiguration diagramConfiguration) {
public Optional<IRepresentationEventProcessor> createRepresentationEventProcessor(IRepresentationConfiguration configuration, IEditingContext editingContext) {
if (configuration instanceof DiagramConfiguration diagramConfiguration) {
var optionalDiagram = this.representationSearchService.findById(editingContext, diagramConfiguration.getId(), Diagram.class);
if (optionalDiagram.isPresent()) {
Diagram diagram = optionalDiagram.get();
Expand All @@ -99,9 +97,7 @@ public <T extends IRepresentationEventProcessor> Optional<T> createRepresentatio

IRepresentationEventProcessor diagramEventProcessor = new DiagramEventProcessor(parameters);

return Optional.of(diagramEventProcessor)
.filter(representationEventProcessorClass::isInstance)
.map(representationEventProcessorClass::cast);
return Optional.of(diagramEventProcessor);
}
}
return Optional.empty();
Expand Down
Loading

0 comments on commit c47ce4f

Please sign in to comment.