From ca8c9774fff137ef883c0ba01106039fd15c3c98 Mon Sep 17 00:00:00 2001 From: Axel RICHARD Date: Wed, 25 Jun 2025 11:19:45 +0200 Subject: [PATCH] [1398] Fix exposed Element update while d'n'd Element on General View Bug: https://github.com/eclipse-syson/syson/issues/1398 Signed-off-by: Axel RICHARD --- CHANGELOG.adoc | 1 + .../general/view/GVDropFromExplorerTests.java | 33 ++++++++++++------- ...iewAddExistingElementsTestProjectData.java | 2 ++ .../handlers/DropTreeItemHandlerTest.java | 11 ++++--- .../common/view/services/ViewToolService.java | 1 - .../pages/release-notes/2025.8.0.adoc | 3 +- 6 files changed, 33 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 6f7864da5..cf2509e3b 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -23,6 +23,7 @@ === Bug fixes - https://github.com/eclipse-syson/syson/issues/893[#893] [explorer] Fix _Expand All_ tool in SysON _Explorer_ view +- https://github.com/eclipse-syson/syson/issues/1398[#1398] [explorer] Fix an issue where a d'n'd of an `Element` in a diagram exposed the `Element` twice in the `ViewUsage` associated to the diagram. === Improvements diff --git a/backend/application/syson-application/src/test/java/org/eclipse/syson/application/controllers/diagrams/general/view/GVDropFromExplorerTests.java b/backend/application/syson-application/src/test/java/org/eclipse/syson/application/controllers/diagrams/general/view/GVDropFromExplorerTests.java index a0b73e654..1b6b177a9 100644 --- a/backend/application/syson-application/src/test/java/org/eclipse/syson/application/controllers/diagrams/general/view/GVDropFromExplorerTests.java +++ b/backend/application/syson-application/src/test/java/org/eclipse/syson/application/controllers/diagrams/general/view/GVDropFromExplorerTests.java @@ -51,6 +51,7 @@ import org.eclipse.syson.sysml.Element; import org.eclipse.syson.sysml.Package; import org.eclipse.syson.sysml.SysmlPackage; +import org.eclipse.syson.sysml.ViewUsage; import org.eclipse.syson.util.IDescriptionNameGenerator; import org.eclipse.syson.util.SysONRepresentationDescriptionIdentifiers; import org.junit.jupiter.api.AfterEach; @@ -136,7 +137,8 @@ public void tearDown() { } } - @Sql(scripts = { GeneralViewAddExistingElementsTestProjectData.SCRIPT_PATH }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) + @Sql(scripts = { GeneralViewAddExistingElementsTestProjectData.SCRIPT_PATH }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, + config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED)) @Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED)) @Test public void dropFromExplorerOnEmptyDiagram() { @@ -156,9 +158,7 @@ public void dropFromExplorerOnEmptyDiagram() { String emptyDiagramNodeDescriptionId = this.diagramDescriptionIdProvider.getNodeDescriptionId(GeneralViewEmptyDiagramNodeDescriptionProvider.NAME); // Ensure the existing node is the "empty diagram" one. assertThat(emptyDiagramNode).hasDescriptionId(emptyDiagramNodeDescriptionId); - this.dropFromExplorerTester.dropFromExplorerOnDiagram(GeneralViewAddExistingElementsTestProjectData.EDITING_CONTEXT_ID, - this.diagram, - semanticElementId.get()); + this.dropFromExplorerTester.dropFromExplorerOnDiagram(GeneralViewAddExistingElementsTestProjectData.EDITING_CONTEXT_ID, this.diagram, semanticElementId.get()); }); Consumer updatedDiagramConsumer = payload -> Optional.of(payload) @@ -177,9 +177,24 @@ public void dropFromExplorerOnEmptyDiagram() { }, () -> fail("Missing diagram")); this.verifier.consumeNextWith(updatedDiagramConsumer); + + Runnable exposedElementsChecker = this.semanticRunnableFactory.createRunnable(GeneralViewAddExistingElementsTestProjectData.EDITING_CONTEXT_ID, + (editingContext, executeEditingContextFunctionInput) -> { + ViewUsage generalViewViewUsage = this.objectSearchService.getObject(editingContext, GeneralViewAddExistingElementsTestProjectData.SemanticIds.GENERAL_VIEW_VIEW_USAGE_ID) + .filter(ViewUsage.class::isInstance) + .map(ViewUsage.class::cast) + .orElse(null); + assertThat(generalViewViewUsage).isNotNull(); + assertThat(generalViewViewUsage.getExposedElement()).hasSize(1); + return new ExecuteEditingContextFunctionSuccessPayload(executeEditingContextFunctionInput.id(), true); + }); + + this.verifier.then(exposedElementsChecker); + } - @Sql(scripts = { GeneralViewAddExistingElementsTestProjectData.SCRIPT_PATH }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) + @Sql(scripts = { GeneralViewAddExistingElementsTestProjectData.SCRIPT_PATH }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, + config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED)) @Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED)) @Test public void dropFromExplorerOnEmptyDiagramNode() { @@ -199,10 +214,7 @@ public void dropFromExplorerOnEmptyDiagramNode() { String emptyDiagramNodeDescriptionId = this.diagramDescriptionIdProvider.getNodeDescriptionId(GeneralViewEmptyDiagramNodeDescriptionProvider.NAME); // Ensure the existing node is the "empty diagram" one. assertThat(emptyDiagramNode).hasDescriptionId(emptyDiagramNodeDescriptionId); - this.dropFromExplorerTester.dropFromExplorer(GeneralViewAddExistingElementsTestProjectData.EDITING_CONTEXT_ID, - this.diagram, - emptyDiagramNode.getId(), - semanticElementId.get()); + this.dropFromExplorerTester.dropFromExplorer(GeneralViewAddExistingElementsTestProjectData.EDITING_CONTEXT_ID, this.diagram, emptyDiagramNode.getId(), semanticElementId.get()); }); Consumer updatedDiagramConsumer = payload -> Optional.of(payload) @@ -224,8 +236,7 @@ public void dropFromExplorerOnEmptyDiagramNode() { } private String getSemanticElementWithTargetObjectLabel(IEditingContext editingContext, String targetObjectLabel) { - Object semanticRootObject = this.objectSearchService.getObject(editingContext, - GeneralViewAddExistingElementsTestProjectData.SemanticIds.PACKAGE_1_ID).orElse(null); + Object semanticRootObject = this.objectSearchService.getObject(editingContext, GeneralViewAddExistingElementsTestProjectData.SemanticIds.PACKAGE_1_ID).orElse(null); assertThat(semanticRootObject).isInstanceOf(Package.class); Package rootPackage = (Package) semanticRootObject; Optional optPartUsage = rootPackage.getOwnedMember().stream().filter(m -> Objects.equals(m.getName(), targetObjectLabel)).findFirst(); diff --git a/backend/application/syson-application/src/test/java/org/eclipse/syson/application/data/GeneralViewAddExistingElementsTestProjectData.java b/backend/application/syson-application/src/test/java/org/eclipse/syson/application/data/GeneralViewAddExistingElementsTestProjectData.java index 46cf99182..e98becc82 100644 --- a/backend/application/syson-application/src/test/java/org/eclipse/syson/application/data/GeneralViewAddExistingElementsTestProjectData.java +++ b/backend/application/syson-application/src/test/java/org/eclipse/syson/application/data/GeneralViewAddExistingElementsTestProjectData.java @@ -39,6 +39,8 @@ public static final class SemanticIds { public static final String PACKAGE_1_ID = "8d4123ac-3ac5-412d-90f2-49282b923003"; + public static final String GENERAL_VIEW_VIEW_USAGE_ID = "b67872fa-5900-48d3-88f0-e6ced193c8ec"; + public static final String SUCCESSION_START_ACTION_2_IDS = "18d6f2fc-2182-4217-8da2-bf68c36ffa41"; } diff --git a/backend/application/syson-application/src/test/java/org/eclipse/syson/tree/explorer/view/handlers/DropTreeItemHandlerTest.java b/backend/application/syson-application/src/test/java/org/eclipse/syson/tree/explorer/view/handlers/DropTreeItemHandlerTest.java index 4b5ce10cb..fa142988e 100644 --- a/backend/application/syson-application/src/test/java/org/eclipse/syson/tree/explorer/view/handlers/DropTreeItemHandlerTest.java +++ b/backend/application/syson-application/src/test/java/org/eclipse/syson/tree/explorer/view/handlers/DropTreeItemHandlerTest.java @@ -80,8 +80,9 @@ public void beforeEach() { this.givenInitialServerState.initialize(); } - @DisplayName("Given the simple project, when drag an dropping a part definition on a package, then the part definition should be moved under the Package.") - @Sql(scripts = { SimpleProjectElementsTestProjectData.SCRIPT_PATH }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) + @DisplayName("GIVEN a SySML project, WHEN drag an dropping a PartDefinition on a Package, THEN the PartDefinition should be moved under the Package.") + @Sql(scripts = { SimpleProjectElementsTestProjectData.SCRIPT_PATH }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, + config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED)) @Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED)) @Test public void checkDnDPartDefinitionOnPackage() { @@ -153,8 +154,9 @@ public void checkDnDPartDefinitionOnPackage() { } - @DisplayName("Given a SySML project, when drag an dropping an element into one of its descendant, then the selected element should not be moved") - @Sql(scripts = { SimpleProjectElementsTestProjectData.SCRIPT_PATH }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) + @DisplayName("GIVEN a SySML project, WHEN drag an dropping an Element into one of its descendant, THEN the selected Element should not be moved") + @Sql(scripts = { SimpleProjectElementsTestProjectData.SCRIPT_PATH }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, + config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED)) @Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED)) @Test public void checkForbiddenDropOnDescendant() { @@ -211,5 +213,4 @@ public void checkForbiddenDropOnDescendant() { .verify(Duration.ofSeconds(10)); } - } diff --git a/backend/views/syson-diagram-common-view/src/main/java/org/eclipse/syson/diagram/common/view/services/ViewToolService.java b/backend/views/syson-diagram-common-view/src/main/java/org/eclipse/syson/diagram/common/view/services/ViewToolService.java index 8eb43dbd1..879496215 100644 --- a/backend/views/syson-diagram-common-view/src/main/java/org/eclipse/syson/diagram/common/view/services/ViewToolService.java +++ b/backend/views/syson-diagram-common-view/src/main/java/org/eclipse/syson/diagram/common/view/services/ViewToolService.java @@ -392,7 +392,6 @@ public Element dropElementFromExplorer(Element element, IEditingContext editingC } if (optElementToDrop.isPresent()) { this.dropElementFromExplorerInTarget(optElementToDrop.get(), targetElement, editingContext, diagramContext, selectedNode, convertedNodes); - this.updateExposedElements(targetElement, optElementToDrop.get(), editingContext, diagramContext); } } } diff --git a/doc/content/modules/user-manual/pages/release-notes/2025.8.0.adoc b/doc/content/modules/user-manual/pages/release-notes/2025.8.0.adoc index 125161007..16e772fbc 100644 --- a/doc/content/modules/user-manual/pages/release-notes/2025.8.0.adoc +++ b/doc/content/modules/user-manual/pages/release-notes/2025.8.0.adoc @@ -14,7 +14,8 @@ == Bug fixes -- Fix an issue that made the _Expand All_ tool not work consistently in SysON _Explorer_ view +- Fix an issue that made the _Expand All_ tool not work consistently in SysON _Explorer_ view. +- Fix an issue where a d'n'd of an `Element` from the _Explorer_ view to a diagram exposed the `Element` twice in the `ViewUsage` associated to the diagram. == Improvements