Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3015] Handle lane selection and editing in Deck
- Make it possible to select a Lane - Make the lane editable once selected (as card) - Handle the title editing mutation Bug: #3015 Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
- Loading branch information
1 parent
ed6a71d
commit 80becb8
Showing
28 changed files
with
724 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
.../src/main/java/org/eclipse/sirius/components/collaborative/deck/api/IDeckLaneService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/******************************************************************************* | ||
* 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.deck.api; | ||
|
||
import org.eclipse.sirius.components.collaborative.deck.dto.input.EditDeckLaneInput; | ||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.components.core.api.IPayload; | ||
import org.eclipse.sirius.components.deck.Deck; | ||
|
||
/** | ||
* Service used to manage deck lane. | ||
* | ||
* @author fbarbin | ||
*/ | ||
public interface IDeckLaneService { | ||
|
||
IPayload editLane(EditDeckLaneInput editDeckLaneInput, IEditingContext editingContext, Deck deck); | ||
|
||
/** | ||
* Implementation which does nothing, used for mocks in unit tests. | ||
* | ||
* @author fbarbin | ||
*/ | ||
class NoOp implements IDeckLaneService { | ||
|
||
@Override | ||
public IPayload editLane(EditDeckLaneInput editDeckLaneInput, IEditingContext editingContext, Deck deck) { | ||
return null; | ||
} | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
...in/java/org/eclipse/sirius/components/collaborative/deck/dto/input/EditDeckLaneInput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/******************************************************************************* | ||
* 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.deck.dto.input; | ||
|
||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.components.collaborative.deck.api.IDeckInput; | ||
|
||
/** | ||
* The input of the "Edit lane" mutation. | ||
* | ||
* @author fbarbin | ||
*/ | ||
public record EditDeckLaneInput(UUID id, String editingContextId, String representationId, String laneId, String newTitle, String newLabel, String newDescription) | ||
implements IDeckInput { | ||
} |
81 changes: 81 additions & 0 deletions
81
.../java/org/eclipse/sirius/components/collaborative/deck/handlers/EditLaneEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/******************************************************************************* | ||
* 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.deck.handlers; | ||
|
||
import java.util.Objects; | ||
|
||
import org.eclipse.sirius.components.collaborative.api.ChangeDescription; | ||
import org.eclipse.sirius.components.collaborative.api.ChangeKind; | ||
import org.eclipse.sirius.components.collaborative.api.Monitoring; | ||
import org.eclipse.sirius.components.collaborative.deck.api.IDeckEventHandler; | ||
import org.eclipse.sirius.components.collaborative.deck.api.IDeckInput; | ||
import org.eclipse.sirius.components.collaborative.deck.api.IDeckLaneService; | ||
import org.eclipse.sirius.components.collaborative.deck.dto.input.EditDeckLaneInput; | ||
import org.eclipse.sirius.components.collaborative.deck.message.ICollaborativeDeckMessageService; | ||
import org.eclipse.sirius.components.core.api.ErrorPayload; | ||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.components.core.api.IPayload; | ||
import org.eclipse.sirius.components.deck.Deck; | ||
import org.springframework.stereotype.Service; | ||
|
||
import io.micrometer.core.instrument.Counter; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import reactor.core.publisher.Sinks.Many; | ||
import reactor.core.publisher.Sinks.One; | ||
|
||
/** | ||
* Handle "Edit Lane" events. | ||
* | ||
* @author fbarbin | ||
*/ | ||
@Service | ||
public class EditLaneEventHandler implements IDeckEventHandler { | ||
|
||
private final IDeckLaneService deckLaneService; | ||
|
||
private final ICollaborativeDeckMessageService messageService; | ||
|
||
private final Counter counter; | ||
|
||
public EditLaneEventHandler(IDeckLaneService deckLaneService, ICollaborativeDeckMessageService messageService, MeterRegistry meterRegistry) { | ||
this.messageService = Objects.requireNonNull(messageService); | ||
this.deckLaneService = Objects.requireNonNull(deckLaneService); | ||
|
||
this.counter = Counter.builder(Monitoring.EVENT_HANDLER) | ||
.tag(Monitoring.NAME, this.getClass().getSimpleName()) | ||
.register(meterRegistry); | ||
} | ||
|
||
@Override | ||
public boolean canHandle(IDeckInput deckInput) { | ||
return deckInput instanceof EditDeckLaneInput; | ||
} | ||
|
||
@Override | ||
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, Deck deck, IDeckInput deckInput) { | ||
this.counter.increment(); | ||
|
||
String message = this.messageService.invalidInput(deckInput.getClass().getSimpleName(), EditDeckLaneInput.class.getSimpleName()); | ||
IPayload payload = new ErrorPayload(deckInput.id(), message); | ||
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, deckInput.representationId(), deckInput); | ||
|
||
if (deckInput instanceof EditDeckLaneInput input) { | ||
payload = this.deckLaneService.editLane(input, editingContext, deck); | ||
|
||
changeDescription = new ChangeDescription(ChangeKind.SEMANTIC_CHANGE, deckInput.representationId(), deckInput); | ||
} | ||
|
||
payloadSink.tryEmitValue(payload); | ||
changeDescriptionSink.tryEmitNext(changeDescription); | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
...c/main/java/org/eclipse/sirius/components/collaborative/deck/service/DeckLaneService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/******************************************************************************* | ||
* 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.deck.service; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.function.Predicate; | ||
|
||
import org.eclipse.sirius.components.collaborative.deck.api.IDeckLaneService; | ||
import org.eclipse.sirius.components.collaborative.deck.dto.input.EditDeckLaneInput; | ||
import org.eclipse.sirius.components.core.api.ErrorPayload; | ||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.components.core.api.IFeedbackMessageService; | ||
import org.eclipse.sirius.components.core.api.IObjectService; | ||
import org.eclipse.sirius.components.core.api.IPayload; | ||
import org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService; | ||
import org.eclipse.sirius.components.core.api.SuccessPayload; | ||
import org.eclipse.sirius.components.deck.Deck; | ||
import org.eclipse.sirius.components.deck.Lane; | ||
import org.eclipse.sirius.components.deck.description.DeckDescription; | ||
import org.eclipse.sirius.components.deck.description.LaneDescription; | ||
import org.eclipse.sirius.components.representations.Message; | ||
import org.eclipse.sirius.components.representations.MessageLevel; | ||
import org.eclipse.sirius.components.representations.VariableManager; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Service used to manage lanes. | ||
* | ||
* @author fbarbin | ||
*/ | ||
@Service | ||
public class DeckLaneService implements IDeckLaneService { | ||
|
||
private final IRepresentationDescriptionSearchService representationDescriptionSearchService; | ||
|
||
private final IFeedbackMessageService feedbackMessageService; | ||
|
||
private final IObjectService objectService; | ||
|
||
public DeckLaneService(IRepresentationDescriptionSearchService representationDescriptionSearchService, IFeedbackMessageService feedbackMessageService, IObjectService objectService) { | ||
this.representationDescriptionSearchService = Objects.requireNonNull(representationDescriptionSearchService); | ||
this.feedbackMessageService = Objects.requireNonNull(feedbackMessageService); | ||
this.objectService = Objects.requireNonNull(objectService); | ||
} | ||
|
||
|
||
|
||
@Override | ||
public IPayload editLane(EditDeckLaneInput editDeckLaneInput, IEditingContext editingContext, Deck deck) { | ||
IPayload payload = new ErrorPayload(editDeckLaneInput.id(), "Edit lane failed"); | ||
|
||
Optional<Lane> optionalLane = this.findLane(lane -> Objects.equals(lane.id(), editDeckLaneInput.laneId()), deck); | ||
Optional<LaneDescription> optionalLaneDescription = optionalLane.flatMap(lane -> this.findLaneDescription(lane.descriptionId(), deck, editingContext)); | ||
|
||
if (optionalLane.isPresent() && optionalLaneDescription.isPresent()) { | ||
Optional<Object> optionalTargetObject = this.objectService.getObject(editingContext, optionalLane.get().targetObjectId()); | ||
if (optionalTargetObject.isPresent()) { | ||
VariableManager variableManager = new VariableManager(); | ||
variableManager.put(VariableManager.SELF, optionalTargetObject.get()); | ||
variableManager.put(DeckDescription.NEW_TITLE, editDeckLaneInput.newTitle()); | ||
optionalLaneDescription.get().editLaneProvider().accept(variableManager); | ||
|
||
payload = this.getPayload(editDeckLaneInput.id()); | ||
} | ||
} | ||
|
||
return payload; | ||
} | ||
|
||
private IPayload getPayload(UUID payloadId) { | ||
IPayload payload = null; | ||
List<Message> feedbackMessages = this.feedbackMessageService.getFeedbackMessages(); | ||
Optional<Message> optionalErrorMsg = feedbackMessages.stream().filter(msg -> MessageLevel.ERROR.equals(msg.level())).findFirst(); | ||
if (optionalErrorMsg.isPresent()) { | ||
payload = new ErrorPayload(payloadId, optionalErrorMsg.get().body(), feedbackMessages); | ||
} else { | ||
payload = new SuccessPayload(payloadId, feedbackMessages); | ||
} | ||
return payload; | ||
} | ||
private Optional<Lane> findLane(Predicate<Lane> condition, Deck deck) { | ||
return deck.lanes().stream() | ||
.filter(condition) | ||
.findFirst(); | ||
} | ||
|
||
private Optional<DeckDescription> findDeckDescription(String descriptionId, IEditingContext editingContext) { | ||
return this.representationDescriptionSearchService.findById(editingContext, descriptionId) | ||
.filter(DeckDescription.class::isInstance) | ||
.map(DeckDescription.class::cast); | ||
} | ||
|
||
private Optional<LaneDescription> findLaneDescription(String descriptionId, Deck deck, IEditingContext editingContext) { | ||
return this.findDeckDescription(deck.descriptionId(), editingContext) | ||
.stream() | ||
.map(DeckDescription::laneDescriptions) | ||
.flatMap(Collection::stream) | ||
.filter(laneDesc -> laneDesc.id().equals(descriptionId)) | ||
.findFirst(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...pse/sirius/components/deck/graphql/datafetchers/mutation/MutationEditLaneDataFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/******************************************************************************* | ||
* 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.deck.graphql.datafetchers.mutation; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import java.util.Objects; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.eclipse.sirius.components.annotations.spring.graphql.MutationDataFetcher; | ||
import org.eclipse.sirius.components.collaborative.deck.dto.input.EditDeckLaneInput; | ||
import org.eclipse.sirius.components.core.api.IPayload; | ||
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates; | ||
import org.eclipse.sirius.components.graphql.api.IEditingContextDispatcher; | ||
import org.eclipse.sirius.components.graphql.api.IExceptionWrapper; | ||
|
||
import graphql.schema.DataFetchingEnvironment; | ||
|
||
/** | ||
* The data fetcher used to change a Deck lane. | ||
* | ||
* @author fbarbin | ||
*/ | ||
@MutationDataFetcher(type = "Mutation", field = "editDeckLane") | ||
public class MutationEditLaneDataFetcher implements IDataFetcherWithFieldCoordinates<CompletableFuture<IPayload>> { | ||
|
||
private static final String INPUT_ARGUMENT = "input"; | ||
|
||
private final ObjectMapper objectMapper; | ||
|
||
private final IExceptionWrapper exceptionWrapper; | ||
|
||
private final IEditingContextDispatcher editingContextDispatcher; | ||
|
||
public MutationEditLaneDataFetcher(ObjectMapper objectMapper, IExceptionWrapper exceptionWrapper, IEditingContextDispatcher editingContextDispatcher) { | ||
this.objectMapper = Objects.requireNonNull(objectMapper); | ||
this.exceptionWrapper = Objects.requireNonNull(exceptionWrapper); | ||
this.editingContextDispatcher = Objects.requireNonNull(editingContextDispatcher); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<IPayload> get(DataFetchingEnvironment environment) throws Exception { | ||
Object argument = environment.getArgument(INPUT_ARGUMENT); | ||
var input = this.objectMapper.convertValue(argument, EditDeckLaneInput.class); | ||
|
||
return this.exceptionWrapper.wrapMono(() -> this.editingContextDispatcher.dispatchMutation(input.editingContextId(), input), input).toFuture(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.