Skip to content

Commit 0d70fbd

Browse files
committed
[5436] Prevent custom handles from being lost after importing a project with a diagram representation
Bug: #5436 Signed-off-by: Florian ROUËNÉ <florian.rouene@obeosoft.com>
1 parent 523f186 commit 0d70fbd

File tree

3 files changed

+17
-25
lines changed

3 files changed

+17
-25
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
=== Bug fixes
3131

32-
32+
- https://github.com/eclipse-sirius/sirius-web/issues/5436[#5436] [diagram] Prevent custom handles from being lost after importing a project with a diagram representation.
3333

3434

3535
=== New Features

packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/project/services/DiagramImporterUpdateService.java

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
*******************************************************************************/
1313
package org.eclipse.sirius.web.application.project.services;
1414

15-
import com.fasterxml.jackson.core.JsonProcessingException;
16-
import com.fasterxml.jackson.databind.ObjectMapper;
17-
1815
import java.util.ArrayList;
1916
import java.util.Collections;
2017
import java.util.HashMap;
@@ -75,18 +72,14 @@
7572
import org.eclipse.sirius.components.diagrams.events.appearance.label.LabelVisibilityAppearanceChange;
7673
import org.eclipse.sirius.components.diagrams.layoutdata.DiagramLayoutData;
7774
import org.eclipse.sirius.components.diagrams.layoutdata.EdgeLayoutData;
75+
import org.eclipse.sirius.components.diagrams.layoutdata.HandleLayoutData;
7876
import org.eclipse.sirius.components.diagrams.layoutdata.LabelLayoutData;
7977
import org.eclipse.sirius.components.diagrams.layoutdata.NodeLayoutData;
8078
import org.eclipse.sirius.components.diagrams.renderer.LabelAppearanceHandler;
8179
import org.eclipse.sirius.components.events.ICause;
8280
import org.eclipse.sirius.web.application.UUIDParser;
8381
import org.eclipse.sirius.web.application.project.services.api.IDiagramImporterNodeStyleAppearanceChangeHandler;
8482
import org.eclipse.sirius.web.application.project.services.api.IRepresentationImporterUpdateService;
85-
import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.RepresentationMetadata;
86-
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.SemanticData;
87-
import org.slf4j.Logger;
88-
import org.slf4j.LoggerFactory;
89-
import org.springframework.data.jdbc.core.mapping.AggregateReference;
9083
import org.springframework.stereotype.Service;
9184

9285
/**
@@ -99,8 +92,6 @@ public class DiagramImporterUpdateService implements IRepresentationImporterUpda
9992

10093
private final IEditingContextSearchService editingContextSearchService;
10194

102-
private final ObjectMapper objectMapper;
103-
10495
private final IRepresentationSearchService representationSearchService;
10596

10697
private final IRepresentationDescriptionSearchService representationDescriptionSearchService;
@@ -111,12 +102,9 @@ public class DiagramImporterUpdateService implements IRepresentationImporterUpda
111102

112103
private final IRepresentationPersistenceService representationPersistenceService;
113104

114-
private final Logger logger = LoggerFactory.getLogger(DiagramImporterUpdateService.class);
115-
116-
public DiagramImporterUpdateService(IEditingContextSearchService editingContextSearchService, ObjectMapper objectMapper, IRepresentationSearchService representationSearchService, IRepresentationDescriptionSearchService representationDescriptionSearchService, DiagramCreationService diagramCreationService, List<IDiagramImporterNodeStyleAppearanceChangeHandler> diagramImporterNodeStyleAppearanceChangeHandlers,
105+
public DiagramImporterUpdateService(IEditingContextSearchService editingContextSearchService, IRepresentationSearchService representationSearchService, IRepresentationDescriptionSearchService representationDescriptionSearchService, DiagramCreationService diagramCreationService, List<IDiagramImporterNodeStyleAppearanceChangeHandler> diagramImporterNodeStyleAppearanceChangeHandlers,
117106
IRepresentationPersistenceService representationPersistenceService) {
118107
this.editingContextSearchService = Objects.requireNonNull(editingContextSearchService);
119-
this.objectMapper = Objects.requireNonNull(objectMapper);
120108
this.representationSearchService = Objects.requireNonNull(representationSearchService);
121109
this.representationDescriptionSearchService = Objects.requireNonNull(representationDescriptionSearchService);
122110
this.diagramCreationService = Objects.requireNonNull(diagramCreationService);
@@ -171,18 +159,11 @@ public void handle(Map<String, String> semanticElementsIdMappings, ICause cause,
171159
var optionalRepresentationMetadataId = new UUIDParser().parse(newRepresentationId);
172160

173161
if (optionalSemanticDataId.isPresent() && optionalRepresentationMetadataId.isPresent() && updatedDiagram.isPresent()) {
174-
var semanticData = AggregateReference.<SemanticData, UUID>to(optionalSemanticDataId.get());
175-
var representationMetadata = AggregateReference.<RepresentationMetadata, UUID>to(optionalRepresentationMetadataId.get());
176162

177163
var laidOutDiagram = Diagram.newDiagram(updatedDiagram.get())
178164
.layoutData(newLayoutData)
179165
.build();
180-
try {
181-
String json = this.objectMapper.writeValueAsString(laidOutDiagram);
182-
this.representationPersistenceService.save(cause, editingContext.get(), laidOutDiagram);
183-
} catch (JsonProcessingException exception) {
184-
this.logger.warn(exception.getMessage(), exception);
185-
}
166+
this.representationPersistenceService.save(cause, editingContext.get(), laidOutDiagram);
186167
}
187168
}
188169
}
@@ -222,8 +203,10 @@ private void handleLayout(DiagramLayoutData newLayoutData, DiagramLayoutData old
222203
}
223204
if (newNodeLayoutId != null) {
224205
var oldLayoutNodeData = oldNodeLayoutData.get(key);
206+
var newHandleLayoutData = oldLayoutNodeData.handleLayoutData().stream().map(handleLayoutData -> new HandleLayoutData(edgeElementOldNewIds.get(handleLayoutData.edgeId()),
207+
handleLayoutData.position(), handleLayoutData.handlePosition(), handleLayoutData.type())).toList();
225208
var newNodeLayoutData = new NodeLayoutData(newNodeLayoutId, oldLayoutNodeData.position(), oldLayoutNodeData.size(), oldLayoutNodeData.resizedByUser(),
226-
oldLayoutNodeData.movedByUser(), oldLayoutNodeData.handleLayoutData(), oldLayoutNodeData.minComputedSize());
209+
oldLayoutNodeData.movedByUser(), newHandleLayoutData, oldLayoutNodeData.minComputedSize());
227210
newLayoutData.nodeLayoutData().put(newNodeLayoutId, newNodeLayoutData);
228211
}
229212
});

packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/application/controllers/diagrams/DiagramRepresentationUploadControllerTests.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.eclipse.sirius.components.collaborative.api.IRepresentationSearchService;
3232
import org.eclipse.sirius.components.core.api.IEditingContext;
3333
import org.eclipse.sirius.components.diagrams.Diagram;
34+
import org.eclipse.sirius.components.diagrams.Edge;
3435
import org.eclipse.sirius.components.graphql.controllers.GraphQLPayload;
3536
import org.eclipse.sirius.emfjson.resource.JsonResourceFactoryImpl;
3637
import org.eclipse.sirius.web.AbstractIntegrationTests;
@@ -192,6 +193,12 @@ public String getId() {
192193
assertThat(diagram.getLayoutData().edgeLayoutData().size()).isEqualTo(1);
193194
assertThat(diagram.getLayoutData().edgeLayoutData().values().stream().map(edgeLayoutData -> edgeLayoutData.bendingPoints().size())).allMatch(size -> size == 4);
194195
assertThat(diagram.getLayoutData().nodeLayoutData().size()).isEqualTo(3);
196+
var nodeLayoutData = diagram.getLayoutData().nodeLayoutData().values();
197+
assertThat(nodeLayoutData).anySatisfy(layoutData -> assertThat(layoutData.handleLayoutData()).anySatisfy(handleLayoutData -> {
198+
assertThat(diagram.getEdges().stream().map(Edge::getId)).contains(handleLayoutData.edgeId());
199+
assertThat(handleLayoutData.position().x()).isEqualTo(72);
200+
assertThat(handleLayoutData.position().y()).isEqualTo(-6);
201+
}));
195202
assertThat(diagram.getLayoutData().labelLayoutData().size()).isEqualTo(3);
196203
var edge = diagram.getEdges().get(0);
197204
assertThat(edge.getCustomizedStyleProperties().size()).isEqualTo(4);
@@ -255,7 +262,9 @@ private String manifest() {
255262
"ff02f72f-6be4-43bb-b581-aa9dd6a7b9d2": {
256263
"descriptionURI": "siriusComponents://representationDescription?kind=diagramDescription&sourceKind=view&sourceId=942b5891-9b51-3fba-90ab-f5e49ccf345e&sourceElementId=bce2748b-a1e5-39e6-ad86-a29323589b38",
257264
"type": "siriusComponents://representation?type=Diagram",
258-
"targetObjectURI": "sirius:///f03b8538-17f9-4df3-82b1-d378b6ce4e4e#9a543523-e43b-436b-a642-5ee5dcee0a95"
265+
"targetObjectURI": "sirius:///f03b8538-17f9-4df3-82b1-d378b6ce4e4e#9a543523-e43b-436b-a642-5ee5dcee0a95",
266+
"migrationVersion": "2025.4.0-202504011650",
267+
"latestMigrationPerformed": "DiagramHandleLayoutDataMigrationParticipant"
259268
}
260269
}
261270
}

0 commit comments

Comments
 (0)