From 287c2075cff3a82a3ffa4f691f1858bbc0633736 Mon Sep 17 00:00:00 2001 From: Michael Charfadi Date: Wed, 4 Dec 2024 12:18:05 +0100 Subject: [PATCH] [4192] Add migration participant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: https://github.com/eclipse-sirius/sirius-web/issues/4192 Signed-off-by: Michaƫl Charfadi --- ...IconURLExpressionMigrationParticipant.java | 47 ++++++ .../sirius/web/data/MigrationIdentifiers.java | 4 + ...RLExpressionMigrationParticipantTests.java | 71 ++++++++ .../src/test/resources/scripts/migration.sql | 158 ++++++++++++++++++ 4 files changed, 280 insertions(+) create mode 100644 packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/editingcontext/migration/participants/TreeDescriptionIconURLExpressionMigrationParticipant.java create mode 100644 packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/services/migration/TreeDescriptionIconURLExpressionMigrationParticipantTests.java diff --git a/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/editingcontext/migration/participants/TreeDescriptionIconURLExpressionMigrationParticipant.java b/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/editingcontext/migration/participants/TreeDescriptionIconURLExpressionMigrationParticipant.java new file mode 100644 index 00000000000..f2a71cd03e6 --- /dev/null +++ b/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/editingcontext/migration/participants/TreeDescriptionIconURLExpressionMigrationParticipant.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2024 CEA LIST. + * 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.web.application.editingcontext.migration.participants; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EStructuralFeature; + +import org.eclipse.sirius.components.emf.migration.api.IMigrationParticipant; +import org.eclipse.sirius.components.view.tree.TreePackage; +import org.springframework.stereotype.Service; + +/** + * MigrationParticipant that update the iconURLExpression of a TreeDescription to treeItemIconExpression. + * + * @author mcharfadi + */ +@Service +public class TreeDescriptionIconURLExpressionMigrationParticipant implements IMigrationParticipant { + + public static final String FEATURE_TO_MIGRATE = "iconURLExpression"; + private static final String PARTICIPANT_VERSION = "2024.11.1-202412041104"; + + @Override + public String getVersion() { + return PARTICIPANT_VERSION; + } + + @Override + public EStructuralFeature getEStructuralFeature(EClass eClass, String eStructuralFeatureName) { + var newFeature = eClass.getEStructuralFeature(eStructuralFeatureName); + if (eClass.getName().equals("TreeDescription") && eStructuralFeatureName.equals(FEATURE_TO_MIGRATE)) { + newFeature = TreePackage.eINSTANCE.getTreeDescription_TreeItemIconExpression(); + } + return newFeature; + } +} diff --git a/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/data/MigrationIdentifiers.java b/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/data/MigrationIdentifiers.java index 8ccd4490c41..d4d8dc3efc9 100644 --- a/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/data/MigrationIdentifiers.java +++ b/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/data/MigrationIdentifiers.java @@ -63,6 +63,10 @@ public final class MigrationIdentifiers { public static final String MIGRATION_WIDGET_DESCRIPTION_STYLE_LAYOUT_PROPERTIES_MIGRATION_PARTICIPANT_STUDIO_FORM = "Form View for WidgetDescriptionStyleLayoutPropertiesMigrationParticipant"; + public static final String MIGRATION_TREE_DESCRIPTION_ICON_URL_STUDIO = "718868e6-de6d-4b00-b84f-56802aa6d5d0"; + + public static final String MIGRATION_TREE_DESCRIPTION_ICON_URL_STUDIO_DOCUMENT_NAME = "TreeDescription#iconUrlDescription migration"; + private MigrationIdentifiers() { // Prevent instantiation } diff --git a/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/services/migration/TreeDescriptionIconURLExpressionMigrationParticipantTests.java b/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/services/migration/TreeDescriptionIconURLExpressionMigrationParticipantTests.java new file mode 100644 index 00000000000..7ba1272bd74 --- /dev/null +++ b/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/services/migration/TreeDescriptionIconURLExpressionMigrationParticipantTests.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2024 CEA LIST. + * 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.web.services.migration; + +import org.eclipse.sirius.components.core.api.IEditingContext; +import org.eclipse.sirius.components.core.api.IEditingContextSearchService; +import org.eclipse.sirius.components.view.diagram.DiagramDescription; +import org.eclipse.sirius.components.view.diagram.HeaderSeparatorDisplayMode; +import org.eclipse.sirius.components.view.tree.TreeDescription; +import org.eclipse.sirius.web.AbstractIntegrationTests; +import org.eclipse.sirius.web.application.editingcontext.EditingContext; +import org.eclipse.sirius.web.data.MigrationIdentifiers; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.jdbc.SqlConfig; +import org.springframework.transaction.annotation.Transactional; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests of TreeDescriptionIconURLExpressionMigrationParticipant. + * + * @author mcharfadi + */ +@Transactional +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class TreeDescriptionIconURLExpressionMigrationParticipantTests extends AbstractIntegrationTests { + + @Autowired + private IEditingContextSearchService editingContextSearchService; + + @Test + @DisplayName("Given a project with an old model, TreeDescriptionIconURLExpressionMigrationParticipant migrates the model correctly") + @Sql(scripts = { "/scripts/migration.sql" }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) + @Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED)) + public void givenAnOldModelMigrationParticipantCanBeContributedToUpdateTheModel() { + var optionalEditingContext = this.editingContextSearchService.findById(MigrationIdentifiers.MIGRATION_TREE_DESCRIPTION_ICON_URL_STUDIO); + assertThat(optionalEditingContext).isPresent(); + this.testIsMigrationSuccessful(optionalEditingContext.get()); + } + + private void testIsMigrationSuccessful(IEditingContext editingContext) { + if (editingContext instanceof EditingContext siriusWebEditingContext) { + var optionalTreeDescription = siriusWebEditingContext.getViews().stream().flatMap(view -> view.getDescriptions().stream()) + .filter(representationDescription -> representationDescription.getName().equals(MigrationIdentifiers.MIGRATION_TREE_DESCRIPTION_ICON_URL_STUDIO_DOCUMENT_NAME)) + .findFirst(); + assertThat(optionalTreeDescription).isPresent(); + assertThat(optionalTreeDescription.get()).isInstanceOf(TreeDescription.class); + optionalTreeDescription.ifPresent(representationDescription -> { + if (representationDescription instanceof TreeDescription treeDescription) { + assertThat(treeDescription.getTreeItemIconExpression()).isEqualTo("iconUrl"); + + } + }); + } + } +} diff --git a/packages/sirius-web/backend/sirius-web/src/test/resources/scripts/migration.sql b/packages/sirius-web/backend/sirius-web/src/test/resources/scripts/migration.sql index 8e6f52ce270..9f9c5de4bcf 100644 --- a/packages/sirius-web/backend/sirius-web/src/test/resources/scripts/migration.sql +++ b/packages/sirius-web/backend/sirius-web/src/test/resources/scripts/migration.sql @@ -1487,3 +1487,161 @@ INSERT INTO document ( '2024-01-01 9:42:0.000', '2024-01-02 9:42:0.000' ); +-- Test project for TreeDescriptionIconURLExpressionMigrationParticipantTests +INSERT INTO project ( + id, + name, + created_on, + last_modified_on +) VALUES ( + '718868e6-de6d-4b00-b84f-56802aa6d5d0', + 'Studio', + '2024-01-01 9:42:0.000', + '2024-01-02 9:42:0.000' +); +INSERT INTO nature ( + project_id, + name +) VALUES ( + '718868e6-de6d-4b00-b84f-56802aa6d5d0', + 'siriusComponents://nature?kind=studio' +); +INSERT INTO semantic_data ( + id, + project_id, + created_on, + last_modified_on +) VALUES ( + '340026b5-1363-4c93-8c2b-7f11188cca8b', + '718868e6-de6d-4b00-b84f-56802aa6d5d0', + '2024-01-01 9:42:0.000', + '2024-01-02 9:42:0.000' +); +INSERT INTO semantic_data_domain ( + semantic_data_id, + uri +) VALUES ( + '340026b5-1363-4c93-8c2b-7f11188cca8b', + 'http://www.eclipse.org/sirius-web/tree' +); +INSERT INTO semantic_data_domain ( + semantic_data_id, + uri +) VALUES ( + '340026b5-1363-4c93-8c2b-7f11188cca8b', + 'http://www.eclipse.org/sirius-web/view' +); +INSERT INTO document ( + id, + semantic_data_id, + name, + content, + created_on, + last_modified_on +) VALUES ( + 'd92b61ec-46a3-4c69-9e08-c5f625a9ac6d', + '340026b5-1363-4c93-8c2b-7f11188cca8b', + 'TreeDescription#iconUrlDescription migration', + '{ + "json": { + "version": "1.0", + "encoding": "utf-8" + }, + "ns": { + "tree": "http://www.eclipse.org/sirius-web/tree", + "view": "http://www.eclipse.org/sirius-web/view" + }, + "migration": { + "lastMigrationPerformed": "WidgetDescriptionStyleLayoutPropertiesMigrationParticipant", + "migrationVersion": "2024.1.0-202411081600" + }, + "content": [ + { + "id": "a4168469-6c99-4685-a847-7a81d9684ce9", + "eClass": "view:View", + "data": { + "descriptions": [ + { + "id": "df899cf6-2f11-47d4-b9ac-def01094b84e", + "eClass": "tree:TreeDescription", + "data": { + "name": "TreeDescription#iconUrlDescription migration", + "domainType": "buck::Human", + "titleExpression": "New Tree Representation", + "kindExpression": "root", + "iconURLExpression": "iconUrl", + "treeItemIdExpression": "root", + "treeItemObjectExpression": "aql:self", + "elementsExpression": "aql:self", + "hasChildrenExpression": "aql:false", + "treeItemLabelDescriptions": [ + { + "id": "6fb8754f-b51a-42ac-b9ce-e2c4a7194af9", + "eClass": "tree:TreeItemLabelDescription", + "data": { + "name": "Label", + "children": [ + { + "id": "fecd22d2-66b0-4ced-95d1-04f969c04aac", + "eClass": "tree:TreeItemLabelFragmentDescription", + "data": { + "labelExpression": "aql:self.name" + } + } + ] + } + } + ] + } + } + ], + "colorPalettes": [ + { + "id": "648a95a6-5ec3-462f-8e68-f3206463e53f", + "eClass": "view:ColorPalette", + "data": { + "colors": [ + { + "id": "0ea0f185-849a-4644-a811-713406eabb8c", + "eClass": "view:FixedColor", + "data": { "name": "color_dark", "value": "#002639" } + }, + { + "id": "03cadcd8-a8e7-4b11-a404-df32bb72b6fc", + "eClass": "view:FixedColor", + "data": { "name": "color_blue", "value": "#E5F5F8" } + }, + { + "id": "07fc0265-6a78-4ecc-842f-7867dc4f634e", + "eClass": "view:FixedColor", + "data": { "name": "color_green", "value": "#B1D8B7" } + }, + { + "id": "4dfe7438-03b0-453b-a6fd-57ae128b4a39", + "eClass": "view:FixedColor", + "data": { "name": "border_blue", "value": "#33B0C3" } + }, + { + "id": "a48045ae-dd76-47e9-8b28-02f8f9ed0d1a", + "eClass": "view:FixedColor", + "data": { "name": "border_green", "value": "#76B947" } + }, + { + "id": "afcc8880-c5ea-4fb7-a35f-f91c9fb44e55", + "eClass": "view:FixedColor", + "data": { + "name": "color_transparent", + "value": "transparent" + } + } + ] + } + } + ] + } + } + ] + }', + '2024-04-12 9:42:0.000', + '2024-04-12 9:42:0.000' +);