Skip to content

Commit

Permalink
[3681] Use the rename representation event handler to rename represen…
Browse files Browse the repository at this point in the history
…tations

Bug: #3681
Signed-off-by: Guillaume Coutable <[email protected]>
  • Loading branch information
gcoutable committed Oct 11, 2024
1 parent 7b1130f commit 88dcae2
Show file tree
Hide file tree
Showing 48 changed files with 484 additions and 957 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc
String label = representationDescription.getLabelProvider().apply(variableManager);

Hierarchy hierarchy = this.hierarchyCreationService.create(object, representationDescription, editingContext);
var representationMetadata = new RepresentationMetadata(hierarchy.getId(), hierarchy.getKind(), label, hierarchy.getDescriptionId());
var representationMetadata = RepresentationMetadata.newRepresentationMetadata(hierarchy.getId())
.kind(hierarchy.getKind())
.label(label)
.descriptionId(hierarchy.getDescriptionId())
.build();

this.representationMetadataPersistenceService.save(createRepresentationInput, editingContext, representationMetadata, hierarchy.getTargetObjectId());
this.representationPersistenceService.save(createRepresentationInput, editingContext, hierarchy);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 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 @@ -14,12 +14,12 @@

import java.util.UUID;

import org.eclipse.sirius.components.core.api.IRepresentationInput;
import org.eclipse.sirius.components.core.api.IInput;

/**
* The input of the rename representation mutation.
*
* @author arichard
*/
public record RenameRepresentationInput(UUID id, String editingContextId, String representationId, String newLabel) implements IRepresentationInput {
public record RenameRepresentationInput(UUID id, String editingContextId, String representationId, String newLabel) implements IInput {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 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 @@ -15,15 +15,15 @@
import java.util.Objects;
import java.util.UUID;

import org.eclipse.sirius.components.core.RepresentationMetadata;
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.representations.IRepresentation;

/**
* The payload returned by the rename representation mutation.
*
* @author arichard
*/
public record RenameRepresentationSuccessPayload(UUID id, IRepresentation representation) implements IPayload {
public record RenameRepresentationSuccessPayload(UUID id, RepresentationMetadata representation) implements IPayload {
public RenameRepresentationSuccessPayload {
Objects.requireNonNull(id);
Objects.requireNonNull(representation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc
IRepresentationDescription representationDescription = this.representationMetadataProviders.stream()
.flatMap(provider -> provider.getMetadata(getRepresentationDescriptionInput.representationId()).stream())
.findFirst()
.map(RepresentationMetadata::getDescriptionId)
.map(RepresentationMetadata::descriptionId)
.flatMap(representationDescriptionId -> this.representationDescriptionSearchService.findById(editingContext, representationDescriptionId))
.orElse(null);
var payload = new GetRepresentationDescriptionPayload(input.id(), representationDescription);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022, 2023 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 @@ -20,41 +20,77 @@
*
* @author sbegaudeau
*/
public class RepresentationMetadata {
private final String id;

private final String kind;

private final String label;

private final String descriptionId;

public RepresentationMetadata(String id, String kind, String label, String descriptionId) {
this.id = Objects.requireNonNull(id);
this.kind = Objects.requireNonNull(kind);
this.label = Objects.requireNonNull(label);
this.descriptionId = Objects.requireNonNull(descriptionId);
}

public String getId() {
return this.id;
}

public String getKind() {
return this.kind;
public record RepresentationMetadata(String id, String kind, String label, String descriptionId) {
public RepresentationMetadata {
Objects.requireNonNull(id);
Objects.requireNonNull(kind);
Objects.requireNonNull(label);
Objects.requireNonNull(descriptionId);
}

public String getLabel() {
return this.label;
public static Builder newRepresentationMetadata(String id) {
return new Builder(id);
}

public String getDescriptionId() {
return this.descriptionId;
public static Builder newRepresentationMetadata(RepresentationMetadata representationMetadata) {
return new Builder(representationMetadata);
}

@Override
public String toString() {
String pattern = "{0} '{'id: {1}, kind: {2}, label: {3}, descriptionId: {4}'}'";
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.id, this.kind, this.label, this.descriptionId);
}

/**
* The Builder to create a new {@link RepresentationMetadata}.
*
* @author fbarbin
*/
@SuppressWarnings("checkstyle:HiddenField")
public static final class Builder {
private final String id;

private String kind;

private String label;

private String descriptionId;

private Builder(String id) {
this.id = Objects.requireNonNull(id);
}

private Builder(RepresentationMetadata representationMetadata) {
this.id = representationMetadata.id;
this.kind = representationMetadata.kind;
this.label = representationMetadata.label;
this.descriptionId = representationMetadata.descriptionId;
}

public Builder kind(String kind) {
this.kind = Objects.requireNonNull(kind);
return this;
}

public Builder label(String label) {
this.label = Objects.requireNonNull(label);
return this;
}

public Builder descriptionId(String descriptionId) {
this.descriptionId = Objects.requireNonNull(descriptionId);
return this;
}

public RepresentationMetadata build() {
return new RepresentationMetadata(
Objects.requireNonNull(this.id),
Objects.requireNonNull(this.kind),
Objects.requireNonNull(this.label),
Objects.requireNonNull(this.descriptionId)
);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
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.api.IDeckInput;
import org.eclipse.sirius.components.collaborative.deck.dto.input.RenameDeckInput;
import org.eclipse.sirius.components.collaborative.deck.service.DeckCreationService;
import org.eclipse.sirius.components.collaborative.dto.RenameRepresentationInput;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IInput;
import org.eclipse.sirius.components.core.api.IPayload;
Expand Down Expand Up @@ -103,12 +101,7 @@ public ISubscriptionManager getSubscriptionManager() {

@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IRepresentationInput representationInput) {
IRepresentationInput effectiveInput = representationInput;
if (representationInput instanceof RenameRepresentationInput renameRepresentationInput) {
effectiveInput = new RenameDeckInput(renameRepresentationInput.id(), renameRepresentationInput.editingContextId(), renameRepresentationInput.representationId(),
renameRepresentationInput.newLabel());
}
if (effectiveInput instanceof IDeckInput deckInput) {
if (representationInput instanceof IDeckInput deckInput) {
Optional<IDeckEventHandler> optionalDeckEventHandler = this.deckEventHandlers.stream().filter(handler -> handler.canHandle(deckInput)).findFirst();

if (optionalDeckEventHandler.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc
String label = deckDescription.labelProvider().apply(variableManager);

Deck deckDiagram = this.deckCreationService.create(object, deckDescription, editingContext);
var representationMetadata = new RepresentationMetadata(deckDiagram.id(), deckDiagram.getKind(), label, deckDiagram.descriptionId());
var representationMetadata = RepresentationMetadata.newRepresentationMetadata(deckDiagram.id())
.kind(deckDiagram.getKind())
.label(label)
.descriptionId(deckDiagram.getDescriptionId())
.build();

this.representationMetadataPersistenceService.save(createRepresentationInput, editingContext, representationMetadata, deckDiagram.getTargetObjectId());
this.representationPersistenceService.save(createRepresentationInput, editingContext, deckDiagram);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
import org.eclipse.sirius.components.collaborative.diagrams.dto.LayoutDiagramInput;
import org.eclipse.sirius.components.collaborative.diagrams.dto.NodeLayoutDataInput;
import org.eclipse.sirius.components.collaborative.diagrams.dto.ReferencePosition;
import org.eclipse.sirius.components.collaborative.diagrams.dto.RenameDiagramInput;
import org.eclipse.sirius.components.collaborative.dto.RenameRepresentationInput;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IInput;
import org.eclipse.sirius.components.core.api.IPayload;
Expand Down Expand Up @@ -161,12 +159,7 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc
return;
}

IRepresentationInput effectiveInput = representationInput;
if (representationInput instanceof RenameRepresentationInput renameRepresentationInput) {
effectiveInput = new RenameDiagramInput(renameRepresentationInput.id(), renameRepresentationInput.editingContextId(), renameRepresentationInput.representationId(),
renameRepresentationInput.newLabel());
}
if (effectiveInput instanceof IDiagramInput diagramInput) {
if (representationInput instanceof IDiagramInput diagramInput) {
Optional<IDiagramEventHandler> optionalDiagramEventHandler = this.diagramEventHandlers.stream().filter(handler -> handler.canHandle(diagramInput)).findFirst();

if (optionalDiagramEventHandler.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc
String label = diagramDescription.getLabelProvider().apply(variableManager);

Diagram diagram = this.diagramCreationService.create(object, diagramDescription, editingContext);
var representationMetadata = new RepresentationMetadata(diagram.getId(), diagram.getKind(), label, diagram.getDescriptionId());
var representationMetadata = RepresentationMetadata.newRepresentationMetadata(diagram.getId())
.kind(diagram.getKind())
.label(label)
.descriptionId(diagram.getDescriptionId())
.build();

this.representationMetadataPersistenceService.save(createRepresentationInput, editingContext, representationMetadata, diagram.getTargetObjectId());
this.representationPersistenceService.save(createRepresentationInput, editingContext, diagram);

Expand Down
Loading

0 comments on commit 88dcae2

Please sign in to comment.