-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3794] Change showIcon by showIconExpression in Diagram View DSL
Bug: #3794 Signed-off-by: Axel RICHARD <axel.richard@obeo.fr>
- Loading branch information
1 parent
21e9f7a
commit 790fec7
Showing
27 changed files
with
582 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ion/editingcontext/migration/participants/NodeLabelStyleShowIconMigrationParticipant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 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 | ||
* 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 com.google.gson.JsonObject; | ||
|
||
import java.util.Optional; | ||
|
||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.sirius.components.emf.migration.api.IMigrationParticipant; | ||
import org.eclipse.sirius.components.view.diagram.NodeLabelStyle; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* MigrationParticipant that update the showIcon (to ShowIconExpression) of NodeLabelStyle. | ||
* | ||
* @author arichard | ||
*/ | ||
@Service | ||
public class NodeLabelStyleShowIconMigrationParticipant implements IMigrationParticipant { | ||
|
||
private static final String PARTICIPANT_VERSION = "2024.9.0-202407191430"; | ||
|
||
@Override | ||
public String getVersion() { | ||
return PARTICIPANT_VERSION; | ||
} | ||
|
||
@Override | ||
public void postObjectLoading(EObject eObject, JsonObject jsonObject) { | ||
if (eObject instanceof NodeLabelStyle nodeLabelStyle) { | ||
var optionalNodeLabelStyle = Optional.ofNullable(jsonObject.getAsJsonObject("data")); | ||
optionalNodeLabelStyle.ifPresent(nodeLabelStyleData -> { | ||
var optionalShowIcon = Optional.ofNullable(nodeLabelStyleData.get("showIcon")); | ||
optionalShowIcon.ifPresent(showIcon -> { | ||
nodeLabelStyle.setShowIconExpression("aql:" + showIcon); | ||
}); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...clipse/sirius/web/services/migration/NodeLabelStyleShowIconMigrationParticipantTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 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 | ||
* 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 static org.assertj.core.api.Assertions.assertThat; | ||
|
||
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.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; | ||
|
||
/** | ||
* Integration tests of NodeLabelStyleShowIconMigrationParticipant. | ||
* | ||
* @author arichard | ||
*/ | ||
@Transactional | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public class NodeLabelStyleShowIconMigrationParticipantTests extends AbstractIntegrationTests { | ||
|
||
@Autowired | ||
private IEditingContextSearchService editingContextSearchService; | ||
|
||
@Test | ||
@DisplayName("Given a project with an old model, NodeLabelStyleShowIconMigrationParticipant 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_NODE_LABEL_STYLE_SHOW_ICON_STUDIO.toString()); | ||
assertThat(optionalEditingContext).isPresent(); | ||
this.testIsMigrationSuccessful(optionalEditingContext.get()); | ||
} | ||
|
||
private void testIsMigrationSuccessful(IEditingContext editingContext) { | ||
if (editingContext instanceof EditingContext siriusWebEditingContext) { | ||
var optionalDiagramDescription = siriusWebEditingContext.getViews().stream().flatMap(view -> view.getDescriptions().stream()) | ||
.filter(representationDescription -> representationDescription.getName().equals(MigrationIdentifiers.MIGRATION_NODE_LABEL_STYLE_SHOW_ICON_STUDIO_DIAGRAM)).findFirst(); | ||
assertThat(optionalDiagramDescription).isPresent(); | ||
assertThat(optionalDiagramDescription.get()).isInstanceOf(DiagramDescription.class); | ||
optionalDiagramDescription.ifPresent(representationDescription -> { | ||
if (representationDescription instanceof DiagramDescription diagramDescription) { | ||
assertThat(diagramDescription.getNodeDescriptions()).hasSize(2); | ||
var nodeDescriptionShowIconTrue = diagramDescription.getNodeDescriptions().get(0); | ||
assertThat(nodeDescriptionShowIconTrue.getInsideLabel().getStyle().getShowIconExpression()).isEqualTo("aql:true"); | ||
var nodeDescriptionShowIconNoValue = diagramDescription.getNodeDescriptions().get(1); | ||
assertThat(nodeDescriptionShowIconNoValue.getInsideLabel().getStyle().getShowIconExpression()).isEqualTo(null); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.