Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

=== Bug fixes


- 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.


=== New Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
*******************************************************************************/
package org.eclipse.sirius.web.application.project.services;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -75,18 +72,14 @@
import org.eclipse.sirius.components.diagrams.events.appearance.label.LabelVisibilityAppearanceChange;
import org.eclipse.sirius.components.diagrams.layoutdata.DiagramLayoutData;
import org.eclipse.sirius.components.diagrams.layoutdata.EdgeLayoutData;
import org.eclipse.sirius.components.diagrams.layoutdata.HandleLayoutData;
import org.eclipse.sirius.components.diagrams.layoutdata.LabelLayoutData;
import org.eclipse.sirius.components.diagrams.layoutdata.NodeLayoutData;
import org.eclipse.sirius.components.diagrams.renderer.LabelAppearanceHandler;
import org.eclipse.sirius.components.events.ICause;
import org.eclipse.sirius.web.application.UUIDParser;
import org.eclipse.sirius.web.application.project.services.api.IDiagramImporterNodeStyleAppearanceChangeHandler;
import org.eclipse.sirius.web.application.project.services.api.IRepresentationImporterUpdateService;
import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.RepresentationMetadata;
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.SemanticData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.jdbc.core.mapping.AggregateReference;
import org.springframework.stereotype.Service;

/**
Expand All @@ -99,8 +92,6 @@ public class DiagramImporterUpdateService implements IRepresentationImporterUpda

private final IEditingContextSearchService editingContextSearchService;

private final ObjectMapper objectMapper;

private final IRepresentationSearchService representationSearchService;

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

private final IRepresentationPersistenceService representationPersistenceService;

private final Logger logger = LoggerFactory.getLogger(DiagramImporterUpdateService.class);

public DiagramImporterUpdateService(IEditingContextSearchService editingContextSearchService, ObjectMapper objectMapper, IRepresentationSearchService representationSearchService, IRepresentationDescriptionSearchService representationDescriptionSearchService, DiagramCreationService diagramCreationService, List<IDiagramImporterNodeStyleAppearanceChangeHandler> diagramImporterNodeStyleAppearanceChangeHandlers,
public DiagramImporterUpdateService(IEditingContextSearchService editingContextSearchService, IRepresentationSearchService representationSearchService, IRepresentationDescriptionSearchService representationDescriptionSearchService, DiagramCreationService diagramCreationService, List<IDiagramImporterNodeStyleAppearanceChangeHandler> diagramImporterNodeStyleAppearanceChangeHandlers,
IRepresentationPersistenceService representationPersistenceService) {
this.editingContextSearchService = Objects.requireNonNull(editingContextSearchService);
this.objectMapper = Objects.requireNonNull(objectMapper);
this.representationSearchService = Objects.requireNonNull(representationSearchService);
this.representationDescriptionSearchService = Objects.requireNonNull(representationDescriptionSearchService);
this.diagramCreationService = Objects.requireNonNull(diagramCreationService);
Expand Down Expand Up @@ -171,18 +159,11 @@ public void handle(Map<String, String> semanticElementsIdMappings, ICause cause,
var optionalRepresentationMetadataId = new UUIDParser().parse(newRepresentationId);

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

var laidOutDiagram = Diagram.newDiagram(updatedDiagram.get())
.layoutData(newLayoutData)
.build();
try {
String json = this.objectMapper.writeValueAsString(laidOutDiagram);
this.representationPersistenceService.save(cause, editingContext.get(), laidOutDiagram);
} catch (JsonProcessingException exception) {
this.logger.warn(exception.getMessage(), exception);
}
this.representationPersistenceService.save(cause, editingContext.get(), laidOutDiagram);
}
}
}
Expand Down Expand Up @@ -222,8 +203,10 @@ private void handleLayout(DiagramLayoutData newLayoutData, DiagramLayoutData old
}
if (newNodeLayoutId != null) {
var oldLayoutNodeData = oldNodeLayoutData.get(key);
var newHandleLayoutData = oldLayoutNodeData.handleLayoutData().stream().map(handleLayoutData -> new HandleLayoutData(edgeElementOldNewIds.get(handleLayoutData.edgeId()),
handleLayoutData.position(), handleLayoutData.handlePosition(), handleLayoutData.type())).toList();
var newNodeLayoutData = new NodeLayoutData(newNodeLayoutId, oldLayoutNodeData.position(), oldLayoutNodeData.size(), oldLayoutNodeData.resizedByUser(),
oldLayoutNodeData.movedByUser(), oldLayoutNodeData.handleLayoutData(), oldLayoutNodeData.minComputedSize());
oldLayoutNodeData.movedByUser(), newHandleLayoutData, oldLayoutNodeData.minComputedSize());
newLayoutData.nodeLayoutData().put(newNodeLayoutId, newNodeLayoutData);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.eclipse.sirius.components.collaborative.api.IRepresentationSearchService;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.diagrams.Diagram;
import org.eclipse.sirius.components.diagrams.Edge;
import org.eclipse.sirius.components.graphql.controllers.GraphQLPayload;
import org.eclipse.sirius.emfjson.resource.JsonResourceFactoryImpl;
import org.eclipse.sirius.web.AbstractIntegrationTests;
Expand Down Expand Up @@ -192,6 +193,12 @@ public String getId() {
assertThat(diagram.getLayoutData().edgeLayoutData().size()).isEqualTo(1);
assertThat(diagram.getLayoutData().edgeLayoutData().values().stream().map(edgeLayoutData -> edgeLayoutData.bendingPoints().size())).allMatch(size -> size == 4);
assertThat(diagram.getLayoutData().nodeLayoutData().size()).isEqualTo(3);
var nodeLayoutData = diagram.getLayoutData().nodeLayoutData().values();
assertThat(nodeLayoutData).anySatisfy(layoutData -> assertThat(layoutData.handleLayoutData()).anySatisfy(handleLayoutData -> {
assertThat(diagram.getEdges().stream().map(Edge::getId)).contains(handleLayoutData.edgeId());
assertThat(handleLayoutData.position().x()).isEqualTo(72);
assertThat(handleLayoutData.position().y()).isEqualTo(-6);
}));
assertThat(diagram.getLayoutData().labelLayoutData().size()).isEqualTo(3);
var edge = diagram.getEdges().get(0);
assertThat(edge.getCustomizedStyleProperties().size()).isEqualTo(4);
Expand Down Expand Up @@ -255,7 +262,9 @@ private String manifest() {
"ff02f72f-6be4-43bb-b581-aa9dd6a7b9d2": {
"descriptionURI": "siriusComponents://representationDescription?kind=diagramDescription&sourceKind=view&sourceId=942b5891-9b51-3fba-90ab-f5e49ccf345e&sourceElementId=bce2748b-a1e5-39e6-ad86-a29323589b38",
"type": "siriusComponents://representation?type=Diagram",
"targetObjectURI": "sirius:///f03b8538-17f9-4df3-82b1-d378b6ce4e4e#9a543523-e43b-436b-a642-5ee5dcee0a95"
"targetObjectURI": "sirius:///f03b8538-17f9-4df3-82b1-d378b6ce4e4e#9a543523-e43b-436b-a642-5ee5dcee0a95",
"migrationVersion": "2025.4.0-202504011650",
"latestMigrationPerformed": "DiagramHandleLayoutDataMigrationParticipant"
}
}
}
Expand Down
Loading