Skip to content

Commit a8be1c7

Browse files
committed
[cleanup] Switch DeckContext from a class to a record
Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
1 parent 4d11735 commit a8be1c7

24 files changed

+107
-175
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2024 Obeo.
2+
* Copyright (c) 2024, 2026 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -12,9 +12,9 @@
1212
*******************************************************************************/
1313
package org.eclipse.sirius.components.collaborative.deck;
1414

15+
import java.util.List;
1516
import java.util.Objects;
1617

17-
import org.eclipse.sirius.components.collaborative.deck.api.IDeckContext;
1818
import org.eclipse.sirius.components.deck.Deck;
1919
import org.eclipse.sirius.components.deck.renderer.events.IDeckEvent;
2020

@@ -23,39 +23,9 @@
2323
*
2424
* @author fbarbin
2525
*/
26-
public class DeckContext implements IDeckContext {
27-
28-
private Deck deck;
29-
30-
private IDeckEvent deckEvent;
31-
32-
public DeckContext(Deck initialDeck) {
33-
this.deck = Objects.requireNonNull(initialDeck);
34-
}
35-
36-
@Override
37-
public void update(Deck newDeck) {
38-
this.deck = Objects.requireNonNull(newDeck);
39-
}
40-
41-
@Override
42-
public Deck getDeck() {
43-
return this.deck;
26+
public record DeckContext(Deck deck, List<IDeckEvent> deckEvents) {
27+
public DeckContext {
28+
Objects.requireNonNull(deck);
29+
Objects.requireNonNull(deckEvents);
4430
}
45-
46-
@Override
47-
public void reset() {
48-
this.deckEvent = null;
49-
}
50-
51-
@Override
52-
public IDeckEvent getDeckEvent() {
53-
return this.deckEvent;
54-
}
55-
56-
@Override
57-
public void setDeckEvent(IDeckEvent deckEvent) {
58-
this.deckEvent = Objects.requireNonNull(deckEvent);
59-
}
60-
6131
}

packages/deck/backend/sirius-components-collaborative-deck/src/main/java/org/eclipse/sirius/components/collaborative/deck/DeckEventProcessor.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*******************************************************************************/
1313
package org.eclipse.sirius.components.collaborative.deck;
1414

15+
import java.util.ArrayList;
1516
import java.util.List;
1617
import java.util.Objects;
1718
import java.util.Optional;
@@ -21,7 +22,6 @@
2122
import org.eclipse.sirius.components.collaborative.api.IRepresentationPersistenceStrategy;
2223
import org.eclipse.sirius.components.collaborative.api.IRepresentationSearchService;
2324
import org.eclipse.sirius.components.collaborative.api.ISubscriptionManager;
24-
import org.eclipse.sirius.components.collaborative.deck.api.IDeckContext;
2525
import org.eclipse.sirius.components.collaborative.deck.api.IDeckEventHandler;
2626
import org.eclipse.sirius.components.collaborative.deck.api.IDeckEventProcessor;
2727
import org.eclipse.sirius.components.collaborative.deck.api.IDeckInput;
@@ -63,12 +63,11 @@ public class DeckEventProcessor implements IDeckEventProcessor {
6363

6464
private final List<IDeckEventHandler> deckEventHandlers;
6565

66-
private final IDeckContext deckContext;
66+
private DeckContext deckContext;
6767

6868
public DeckEventProcessor(IEditingContext editingContext, ISubscriptionManager subscriptionManager, DeckCreationService deckCreationService,
69-
List<IDeckEventHandler> deckEventHandlers, IDeckContext deckContext, IRepresentationPersistenceStrategy representationPersistenceStrategy,
69+
List<IDeckEventHandler> deckEventHandlers, DeckContext deckContext, IRepresentationPersistenceStrategy representationPersistenceStrategy,
7070
IRepresentationSearchService representationSearchService) {
71-
7271
this.editingContext = Objects.requireNonNull(editingContext);
7372
this.subscriptionManager = Objects.requireNonNull(subscriptionManager);
7473
this.deckCreationService = Objects.requireNonNull(deckCreationService);
@@ -77,21 +76,21 @@ public DeckEventProcessor(IEditingContext editingContext, ISubscriptionManager s
7776
this.representationPersistenceStrategy = Objects.requireNonNull(representationPersistenceStrategy);
7877
this.representationSearchService = Objects.requireNonNull(representationSearchService);
7978

80-
String id = this.deckContext.getDeck().getId();
79+
String id = this.deckContext.deck().getId();
8180
this.logger.trace("Creating the deck event processor {}", id);
8281

8382
// We automatically refresh the representation before using it since things may have changed since the moment it
8483
// has been saved in the database.
8584
Deck deck = this.deckCreationService.refresh(this.editingContext, deckContext).orElse(null);
86-
this.deckContext.update(deck);
85+
this.deckContext = new DeckContext(deck, deckContext.deckEvents());
8786

8887
this.deckEventFlux = new DeckEventFlux(deck);
8988

9089
}
9190

9291
@Override
9392
public IRepresentation getRepresentation() {
94-
return this.deckContext.getDeck();
93+
return this.deckContext.deck();
9594
}
9695

9796
@Override
@@ -119,18 +118,17 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc
119118
public void refresh(ChangeDescription changeDescription) {
120119
if (this.shouldRefresh(changeDescription)) {
121120
Deck refreshedDeckRepresentation = this.deckCreationService.refresh(this.editingContext, this.deckContext).orElse(null);
122-
this.deckContext.reset();
123-
this.deckContext.update(refreshedDeckRepresentation);
121+
this.deckContext = new DeckContext(refreshedDeckRepresentation, new ArrayList<>());
124122
if (refreshedDeckRepresentation != null) {
125123
this.representationPersistenceStrategy.applyPersistenceStrategy(changeDescription.getInput(), this.editingContext, refreshedDeckRepresentation);
126124
this.logger.trace("Deck refreshed: {}", refreshedDeckRepresentation.getId());
127125
}
128-
this.deckEventFlux.deckRefreshed(changeDescription.getInput(), this.deckContext.getDeck());
129-
} else if (changeDescription.getKind().equals(ChangeKind.RELOAD_REPRESENTATION) && changeDescription.getSourceId().equals(this.deckContext.getDeck().getId())) {
130-
Optional<Deck> reloadedDeck = this.representationSearchService.findById(this.editingContext, this.deckContext.getDeck().getId(), Deck.class);
131-
if (reloadedDeck.isPresent()) {
132-
this.deckContext.update(reloadedDeck.get());
133-
this.deckEventFlux.deckRefreshed(changeDescription.getInput(), this.deckContext.getDeck());
126+
this.deckEventFlux.deckRefreshed(changeDescription.getInput(), this.deckContext.deck());
127+
} else if (changeDescription.getKind().equals(ChangeKind.RELOAD_REPRESENTATION) && changeDescription.getSourceId().equals(this.deckContext.deck().getId())) {
128+
Optional<Deck> optionalReloadedDeck = this.representationSearchService.findById(this.editingContext, this.deckContext.deck().getId(), Deck.class);
129+
if (optionalReloadedDeck.isPresent()) {
130+
this.deckContext = new DeckContext(optionalReloadedDeck.get(), new ArrayList<>());
131+
this.deckEventFlux.deckRefreshed(changeDescription.getInput(), this.deckContext.deck());
134132
}
135133
}
136134
}
@@ -153,7 +151,7 @@ public Flux<IPayload> getOutputEvents(IInput input) {
153151

154152
@Override
155153
public void dispose() {
156-
String id = Optional.ofNullable(this.deckContext.getDeck()).map(Deck::id).orElse(null);
154+
String id = Optional.ofNullable(this.deckContext.deck()).map(Deck::id).orElse(null);
157155
this.logger.trace("Disposing the deck event processor {}", id);
158156
this.subscriptionManager.dispose();
159157
this.deckEventFlux.dispose();

packages/deck/backend/sirius-components-collaborative-deck/src/main/java/org/eclipse/sirius/components/collaborative/deck/DeckEventProcessorFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*******************************************************************************/
1313
package org.eclipse.sirius.components.collaborative.deck;
1414

15+
import java.util.ArrayList;
1516
import java.util.List;
1617
import java.util.Objects;
1718
import java.util.Optional;
@@ -64,7 +65,7 @@ public Optional<IRepresentationEventProcessor> createRepresentationEventProcesso
6465
var optionalDeck = this.representationSearchService.findById(editingContext, representationId, Deck.class);
6566
if (optionalDeck.isPresent()) {
6667
Deck deck = optionalDeck.get();
67-
DeckContext deckContext = new DeckContext(deck);
68+
DeckContext deckContext = new DeckContext(deck, new ArrayList<>());
6869

6970
IRepresentationEventProcessor deckEventProcessor = new DeckEventProcessor(editingContext, this.subscriptionManagerFactory.create(), this.deckCreationService, this.deckEventHandlers,
7071
deckContext, this.representationPersistenceStrategy, this.representationSearchService);

packages/deck/backend/sirius-components-collaborative-deck/src/main/java/org/eclipse/sirius/components/collaborative/deck/api/IDeckCardService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2024 Obeo.
2+
* Copyright (c) 2024, 2026 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -47,7 +47,6 @@ public interface IDeckCardService {
4747
*/
4848
IPayload dropCard(DropDeckCardInput dropDeckCardInput, IEditingContext editingContext, Deck deck);
4949

50-
5150
/**
5251
* Implementation which does nothing, used for mocks in unit tests.
5352
*

packages/deck/backend/sirius-components-collaborative-deck/src/main/java/org/eclipse/sirius/components/collaborative/deck/api/IDeckContext.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

packages/deck/backend/sirius-components-collaborative-deck/src/main/java/org/eclipse/sirius/components/collaborative/deck/api/IDeckCreationService.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2023, 2024 Obeo.
2+
* Copyright (c) 2023, 2026 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -14,6 +14,7 @@
1414

1515
import java.util.Optional;
1616

17+
import org.eclipse.sirius.components.collaborative.deck.DeckContext;
1718
import org.eclipse.sirius.components.core.api.IEditingContext;
1819
import org.eclipse.sirius.components.deck.Deck;
1920
import org.eclipse.sirius.components.deck.description.DeckDescription;
@@ -43,7 +44,7 @@ public interface IDeckCreationService {
4344
*
4445
* <p>
4546
* Refreshing a deck seems to always be possible but it may not be the case. In some situation, the semantic element
46-
* on which the previous deck has been created may not exist anymore and thus we can return an empty optional if we
47+
* on which the previous deck has been created may not exist anymore, and thus we can return an empty optional if we
4748
* are unable to refresh the deck.
4849
* </p>
4950
*
@@ -53,7 +54,7 @@ public interface IDeckCreationService {
5354
* The deck representation context
5455
* @return An updated deck if we have been able to refresh it.
5556
*/
56-
Optional<Deck> refresh(IEditingContext editingContext, IDeckContext deckContext);
57+
Optional<Deck> refresh(IEditingContext editingContext, DeckContext deckContext);
5758

5859
/**
5960
* Implementation which does nothing, used for mocks in unit tests.
@@ -68,7 +69,7 @@ public Deck create(Object targetObject, DeckDescription deckDescription, IEditin
6869
}
6970

7071
@Override
71-
public Optional<Deck> refresh(IEditingContext editingContext, IDeckContext deckContext) {
72+
public Optional<Deck> refresh(IEditingContext editingContext, DeckContext deckContext) {
7273
return Optional.empty();
7374
}
7475
}

packages/deck/backend/sirius-components-collaborative-deck/src/main/java/org/eclipse/sirius/components/collaborative/deck/api/IDeckEventHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2023, 2025 Obeo.
2+
* Copyright (c) 2023, 2026 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -13,6 +13,7 @@
1313
package org.eclipse.sirius.components.collaborative.deck.api;
1414

1515
import org.eclipse.sirius.components.collaborative.api.ChangeDescription;
16+
import org.eclipse.sirius.components.collaborative.deck.DeckContext;
1617
import org.eclipse.sirius.components.core.api.IEditingContext;
1718
import org.eclipse.sirius.components.core.api.IPayload;
1819

@@ -27,5 +28,5 @@
2728
public interface IDeckEventHandler {
2829
boolean canHandle(IEditingContext editingContext, IDeckInput deckInput);
2930

30-
void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IDeckContext deckContext, IDeckInput deckInput);
31+
void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, DeckContext deckContext, IDeckInput deckInput);
3132
}

packages/deck/backend/sirius-components-collaborative-deck/src/main/java/org/eclipse/sirius/components/collaborative/deck/api/IDeckLaneService.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2024 Obeo.
2+
* Copyright (c) 2024, 2026 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -12,6 +12,7 @@
1212
*******************************************************************************/
1313
package org.eclipse.sirius.components.collaborative.deck.api;
1414

15+
import org.eclipse.sirius.components.collaborative.deck.DeckContext;
1516
import org.eclipse.sirius.components.collaborative.deck.dto.input.ChangeCardsVisibilityInput;
1617
import org.eclipse.sirius.components.collaborative.deck.dto.input.ChangeLaneCollapsedStateInput;
1718
import org.eclipse.sirius.components.collaborative.deck.dto.input.DropDeckLaneInput;
@@ -31,9 +32,9 @@ public interface IDeckLaneService {
3132

3233
IPayload dropLane(DropDeckLaneInput dropDeckLaneInput, IEditingContext editingContext, Deck deck);
3334

34-
IPayload changeLaneCollapsedState(ChangeLaneCollapsedStateInput input, IEditingContext editingContext, IDeckContext deckContext);
35+
IPayload changeLaneCollapsedState(ChangeLaneCollapsedStateInput input, IEditingContext editingContext, DeckContext deckContext);
3536

36-
IPayload changeCardsVisibility(ChangeCardsVisibilityInput input, IEditingContext editingContext, IDeckContext deckContext);
37+
IPayload changeCardsVisibility(ChangeCardsVisibilityInput input, IEditingContext editingContext, DeckContext deckContext);
3738

3839
/**
3940
* Implementation which does nothing, used for mocks in unit tests.
@@ -53,12 +54,12 @@ public IPayload dropLane(DropDeckLaneInput dropDeckLaneInput, IEditingContext ed
5354
}
5455

5556
@Override
56-
public IPayload changeLaneCollapsedState(ChangeLaneCollapsedStateInput input, IEditingContext editingContext, IDeckContext deckContext) {
57+
public IPayload changeLaneCollapsedState(ChangeLaneCollapsedStateInput input, IEditingContext editingContext, DeckContext deckContext) {
5758
return null;
5859
}
5960

6061
@Override
61-
public IPayload changeCardsVisibility(ChangeCardsVisibilityInput input, IEditingContext editingContext, IDeckContext deckContext) {
62+
public IPayload changeCardsVisibility(ChangeCardsVisibilityInput input, IEditingContext editingContext, DeckContext deckContext) {
6263
return null;
6364
}
6465
}

packages/deck/backend/sirius-components-collaborative-deck/src/main/java/org/eclipse/sirius/components/collaborative/deck/handlers/ChangeCardsVisibilityEventHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2024, 2025 Obeo.
2+
* Copyright (c) 2024, 2026 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -18,7 +18,7 @@
1818
import org.eclipse.sirius.components.collaborative.api.ChangeKind;
1919
import org.eclipse.sirius.components.collaborative.api.Monitoring;
2020
import org.eclipse.sirius.components.collaborative.deck.DeckChangeKind;
21-
import org.eclipse.sirius.components.collaborative.deck.api.IDeckContext;
21+
import org.eclipse.sirius.components.collaborative.deck.DeckContext;
2222
import org.eclipse.sirius.components.collaborative.deck.api.IDeckEventHandler;
2323
import org.eclipse.sirius.components.collaborative.deck.api.IDeckInput;
2424
import org.eclipse.sirius.components.collaborative.deck.api.IDeckLaneService;
@@ -63,7 +63,7 @@ public boolean canHandle(IEditingContext editingContext, IDeckInput deckInput) {
6363
}
6464

6565
@Override
66-
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IDeckContext deckContext, IDeckInput deckInput) {
66+
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, DeckContext deckContext, IDeckInput deckInput) {
6767
this.counter.increment();
6868

6969
String message = this.messageService.invalidInput(deckInput.getClass().getSimpleName(), ChangeCardsVisibilityInput.class.getSimpleName());

packages/deck/backend/sirius-components-collaborative-deck/src/main/java/org/eclipse/sirius/components/collaborative/deck/handlers/ChangeLaneCollapsedStateEventHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2024, 2025 Obeo.
2+
* Copyright (c) 2024, 2026 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -18,7 +18,7 @@
1818
import org.eclipse.sirius.components.collaborative.api.ChangeKind;
1919
import org.eclipse.sirius.components.collaborative.api.Monitoring;
2020
import org.eclipse.sirius.components.collaborative.deck.DeckChangeKind;
21-
import org.eclipse.sirius.components.collaborative.deck.api.IDeckContext;
21+
import org.eclipse.sirius.components.collaborative.deck.DeckContext;
2222
import org.eclipse.sirius.components.collaborative.deck.api.IDeckEventHandler;
2323
import org.eclipse.sirius.components.collaborative.deck.api.IDeckInput;
2424
import org.eclipse.sirius.components.collaborative.deck.api.IDeckLaneService;
@@ -63,7 +63,7 @@ public boolean canHandle(IEditingContext editingContext, IDeckInput deckInput) {
6363
}
6464

6565
@Override
66-
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IDeckContext deckContext, IDeckInput deckInput) {
66+
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, DeckContext deckContext, IDeckInput deckInput) {
6767
this.counter.increment();
6868

6969
String message = this.messageService.invalidInput(deckInput.getClass().getSimpleName(), ChangeLaneCollapsedStateInput.class.getSimpleName());

0 commit comments

Comments
 (0)