Skip to content

Commit

Permalink
eclipse-capella#2913 Add tests for relation edge migration in CDB
Browse files Browse the repository at this point in the history
Signed-off-by: Séraphin Costa <[email protected]>
  • Loading branch information
scosta-obeo committed Nov 7, 2024
1 parent 74c25da commit b0b5b4e
Show file tree
Hide file tree
Showing 244 changed files with 26,250 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@
import org.polarsys.capella.core.sirius.analysis.InformationServices;

/**
* @author Séraphin Costa
*
* This class migrates the association of the CDB diagram to always have the same source and target.
*
* @author Séraphin Costa
*
*/
public class AssociationCDBMigrationContributor extends AirdMigrationContributor {

Expand Down Expand Up @@ -103,7 +105,8 @@ private void migrateDEdgeStyle(DEdge dEdge) {
interpreter.setVariable(IInterpreterSiriusVariables.SOURCE_VIEW, dEdge.getSourceNode());
interpreter.setVariable(IInterpreterSiriusVariables.TARGET_VIEW, dEdge.getTargetNode());

StyleDescription styleDescription = new MappingWithInterpreterHelper(interpreter).getBestStyleDescription(dEdge.getDiagramElementMapping(), dEdge.getTarget(), dEdge, containerVariable, dEdge.getParentDiagram());
StyleDescription styleDescription = new MappingWithInterpreterHelper(interpreter).getBestStyleDescription(
dEdge.getDiagramElementMapping(), dEdge.getTarget(), dEdge, containerVariable, dEdge.getParentDiagram());

interpreter.unSetVariable(IInterpreterSiriusVariables.DIAGRAM);
interpreter.unSetVariable(IInterpreterSiriusVariables.VIEW);
Expand Down Expand Up @@ -155,15 +158,18 @@ private void migrateDEdge(DEdge dEdge) {
}

private boolean isBeginLabel(Object view) {
return view instanceof Node node && SiriusVisualIDRegistry.getVisualID(node.getType()) == DEdgeBeginNameEditPart.VISUAL_ID;
return view instanceof Node node
&& SiriusVisualIDRegistry.getVisualID(node.getType()) == DEdgeBeginNameEditPart.VISUAL_ID;
}

private boolean isMiddleLabel(Object view) {
return view instanceof Node node && SiriusVisualIDRegistry.getVisualID(node.getType()) == DEdgeNameEditPart.VISUAL_ID;
return view instanceof Node node
&& SiriusVisualIDRegistry.getVisualID(node.getType()) == DEdgeNameEditPart.VISUAL_ID;
}

private boolean isEndLabel(Object view) {
return view instanceof Node node && SiriusVisualIDRegistry.getVisualID(node.getType()) == DEdgeEndNameEditPart.VISUAL_ID;
return view instanceof Node node
&& SiriusVisualIDRegistry.getVisualID(node.getType()) == DEdgeEndNameEditPart.VISUAL_ID;
}

private Object migrateBendpoint(Object rawBendpoint) {
Expand All @@ -187,6 +193,7 @@ private Point getBendpointSourcePosition(Object rawBendpoint) {
return null;
}
}

private Point getBendpointTargetPosition(Object rawBendpoint) {
if (rawBendpoint instanceof RelativeBendpoint bp) {
return new Point(bp.getTargetX(), bp.getTargetY());
Expand All @@ -196,13 +203,16 @@ private Point getBendpointTargetPosition(Object rawBendpoint) {
}

private Collector<Point, PointList, PointList> pointListCollector() {
return Collector.of(PointList::new, PointList::addPoint, (list1, list2) -> { list1.addAll(list2); return list1; });
return Collector.of(PointList::new, PointList::addPoint, (list1, list2) -> {
list1.addAll(list2);
return list1;
});
}

private int getLabelLocation(Node label) {
switch (SiriusVisualIDRegistry.getVisualID(label)) {
case DEdgeBeginNameEditPart.VISUAL_ID:
return LabelViewConstants.SOURCE_LOCATION;
return LabelViewConstants.SOURCE_LOCATION;
case DEdgeEndNameEditPart.VISUAL_ID:
return LabelViewConstants.TARGET_LOCATION;
case DEdgeNameEditPart.VISUAL_ID:
Expand All @@ -227,13 +237,15 @@ private Point getNewLabelPosition(Node label, Bounds bounds, List<?> bendPoints,
Point labelOffset = new Point(bounds.getX(), bounds.getY());

PointList bendPointList = bendPoints.stream().map(this::getBendpointTargetPosition).collect(pointListCollector());
PointList newBendPointList = revBendPoints.stream().map(this::getBendpointSourcePosition).collect(pointListCollector());
PointList newBendPointList = revBendPoints.stream().map(this::getBendpointSourcePosition)
.collect(pointListCollector());

int referenceLocation = getLabelLocation(label);
int newReferenceLocation = getLabelReverseLocation(label);

Point referencePoint = PointListUtilities.calculatePointRelativeToLine(bendPointList, 0, referenceLocation, true);
Point newReferencePoint = PointListUtilities.calculatePointRelativeToLine(newBendPointList, 0, newReferenceLocation, true);
Point newReferencePoint = PointListUtilities.calculatePointRelativeToLine(newBendPointList, 0, newReferenceLocation,
true);

Point labelCenter = EdgeLabelQuery.relativeCenterCoordinateFromOffset(bendPointList, referencePoint, labelOffset);
return EdgeLabelQuery.offsetFromRelativeCoordinate(labelCenter, newBendPointList, newReferencePoint);
Expand Down Expand Up @@ -286,7 +298,7 @@ private void migrateGMFEdge(Edge gmfEdge) {
gmfEdge.setTargetAnchor(sourceAnchor);
bendpoints.setPoints(revBendpointsList);
}

private void migrateAssociation(DEdge dEdge) {
migrateDEdge(dEdge);
migrateGMFEdge(SiriusGMFHelper.getGmfEdge(dEdge));
Expand All @@ -298,7 +310,8 @@ private boolean needMigration(DEdge dEdge) {
Property targetProp = InformationServices.getService().getAssociationTarget(association);
AbstractType expectedSource = sourceProp.getAbstractType();
AbstractType expectedTarget = targetProp.getAbstractType();
if (dEdge.getSourceNode() instanceof DSemanticDecorator sourceNode && dEdge.getTargetNode() instanceof DSemanticDecorator targetNode) {
if (dEdge.getSourceNode() instanceof DSemanticDecorator sourceNode
&& dEdge.getTargetNode() instanceof DSemanticDecorator targetNode) {
EObject sourceObject = sourceNode.getTarget();
EObject targetObject = targetNode.getTarget();
return sourceObject == expectedTarget && targetObject == expectedSource;
Expand All @@ -313,20 +326,15 @@ private boolean needMigration(DEdge dEdge) {
}

private void migrateClassDiagramBlank(DDiagram diagram) {
diagram.getEdges().stream()
.filter(edge -> isAssociation(diagram, edge))
.filter(this::needMigration)
.forEach(this::migrateAssociation);
diagram.getEdges().stream().filter(edge -> isAssociation(diagram, edge)).filter(this::needMigration)
.forEach(this::migrateAssociation);
}

private void migrate(Session session) {
session.getOwnedViews().stream()
.flatMap(dView -> dView.getOwnedRepresentationDescriptors().stream())
.map(dRepDesc -> dRepDesc.getRepresentation())
.filter(DDiagram.class::isInstance)
.map(DDiagram.class::cast)
.filter(AssociationCDBMigrationContributor.this::isClassDiagramBlank)
.forEach(AssociationCDBMigrationContributor.this::migrateClassDiagramBlank);
session.getOwnedViews().stream().flatMap(dView -> dView.getOwnedRepresentationDescriptors().stream())
.map(dRepDesc -> dRepDesc.getRepresentation()).filter(DDiagram.class::isInstance).map(DDiagram.class::cast)
.filter(AssociationCDBMigrationContributor.this::isClassDiagramBlank)
.forEach(AssociationCDBMigrationContributor.this::migrateClassDiagramBlank);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.sirius.common.ui,
org.polarsys.capella.test.diagram.layout.ju,
org.polarsys.capella.core.diagram.helpers,
org.polarsys.capella.common.queries
org.polarsys.capella.common.queries,
org.eclipse.gmf.runtime.notation.edit
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Export-Package: org.polarsys.capella.test.diagram.tools.ju,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RelationStabilityCDB</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
<nature>org.polarsys.capella.project.nature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata:Metadata xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:metadata="http://www.polarsys.org/kitalpha/ad/metadata/1.0.0" id="_0gA-QHy5Ee-JXeucC-Gkng">
<viewpointReferences id="_0gNykHy5Ee-JXeucC-Gkng" vpId="org.polarsys.capella.core.viewpoint" version="7.0.1"/>
</metadata:Metadata>
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:description_1="http://www.eclipse.org/sirius/diagram/description/1.1.0" xmlns:diagram="http://www.eclipse.org/sirius/diagram/1.1.0" xmlns:filter="http://www.eclipse.org/sirius/diagram/description/filter/1.1.0" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.3/notation" xmlns:org.polarsys.capella.core.data.information="http://www.polarsys.org/capella/core/information/7.0.0" xmlns:style="http://www.eclipse.org/sirius/diagram/description/style/1.1.0" xmlns:viewpoint="http://www.eclipse.org/sirius/1.1.0" xsi:schemaLocation="http://www.eclipse.org/sirius/description/1.1.0 http://www.eclipse.org/sirius/1.1.0#//description http://www.eclipse.org/sirius/diagram/description/1.1.0 http://www.eclipse.org/sirius/diagram/1.1.0#//description http://www.eclipse.org/sirius/diagram/description/filter/1.1.0 http://www.eclipse.org/sirius/diagram/1.1.0#//description/filter http://www.eclipse.org/sirius/diagram/description/style/1.1.0 http://www.eclipse.org/sirius/diagram/1.1.0#//description/style">
<viewpoint:DAnalysis uid="_0gCzcHy5Ee-JXeucC-Gkng" selectedViews="_0gT5MHy5Ee-JXeucC-Gkng _0gsTsHy5Ee-JXeucC-Gkng _0jjacHy5Ee-JXeucC-Gkng _0kOv4Hy5Ee-JXeucC-Gkng _0kToYHy5Ee-JXeucC-Gkng _0lHgsHy5Ee-JXeucC-Gkng _0lXYUHy5Ee-JXeucC-Gkng" version="15.4.3.202406261640">
<semanticResources>RelationStabilityCDB.afm</semanticResources>
<semanticResources>RelationStabilityCDB.capella</semanticResources>
<ownedViews xmi:type="viewpoint:DView" uid="_0gT5MHy5Ee-JXeucC-Gkng">
<viewpoint xmi:type="description:Viewpoint" href="platform:/plugin/org.polarsys.kitalpha.ad.integration.sirius/description/ad.odesign#//@ownedViewpoints[name='ad']"/>
</ownedViews>
<ownedViews xmi:type="viewpoint:DView" uid="_0gsTsHy5Ee-JXeucC-Gkng">
<viewpoint xmi:type="description:Viewpoint" href="platform:/plugin/org.polarsys.capella.core.sirius.analysis/description/physical.odesign#//@ownedViewpoints[name='Physical%20Architecture']"/>
</ownedViews>
<ownedViews xmi:type="viewpoint:DView" uid="_0jjacHy5Ee-JXeucC-Gkng">
<viewpoint xmi:type="description:Viewpoint" href="platform:/plugin/org.polarsys.capella.core.sirius.analysis/description/oa.odesign#//@ownedViewpoints[name='Operational%20Analysis']"/>
</ownedViews>
<ownedViews xmi:type="viewpoint:DView" uid="_0kOv4Hy5Ee-JXeucC-Gkng">
<viewpoint xmi:type="description:Viewpoint" href="platform:/plugin/org.polarsys.capella.core.sirius.analysis/description/EPBS.odesign#//@ownedViewpoints[name='EPBS%20architecture']"/>
</ownedViews>
<ownedViews xmi:type="viewpoint:DView" uid="_0kToYHy5Ee-JXeucC-Gkng">
<viewpoint xmi:type="description:Viewpoint" href="platform:/plugin/org.polarsys.capella.core.sirius.analysis/description/context.odesign#//@ownedViewpoints[name='System%20Analysis']"/>
</ownedViews>
<ownedViews xmi:type="viewpoint:DView" uid="_0lHgsHy5Ee-JXeucC-Gkng">
<viewpoint xmi:type="description:Viewpoint" href="platform:/plugin/org.polarsys.capella.core.sirius.analysis/description/logical.odesign#//@ownedViewpoints[name='Logical%20Architecture']"/>
</ownedViews>
<ownedViews xmi:type="viewpoint:DView" uid="_0lXYUHy5Ee-JXeucC-Gkng">
<viewpoint xmi:type="description:Viewpoint" href="platform:/plugin/org.polarsys.capella.core.sirius.analysis/description/common.odesign#//@ownedViewpoints[name='Common']"/>
<ownedRepresentationDescriptors xmi:type="viewpoint:DRepresentationDescriptor" uid="_55qjgHy5Ee-JXeucC-Gkng" name="[CDB] Data" repPath="#_55oHQHy5Ee-JXeucC-Gkng" changeId="1727705391901">
<description xmi:type="description_1:DiagramDescription" href="platform:/plugin/org.polarsys.capella.core.sirius.analysis/description/common.odesign#//@ownedViewpoints[name='Common']/@ownedRepresentations[name='Class%20Diagram%20Blank']"/>
<target xmi:type="org.polarsys.capella.core.data.information:DataPkg" href="RelationStabilityCDB.capella#6790f1ea-051b-4c74-9bff-a3f3d71c39f4"/>
</ownedRepresentationDescriptors>
</ownedViews>
</viewpoint:DAnalysis>
<diagram:DSemanticDiagram uid="_55oHQHy5Ee-JXeucC-Gkng">
<ownedAnnotationEntries xmi:type="description:AnnotationEntry" uid="_55wDEHy5Ee-JXeucC-Gkng" source="GMF_DIAGRAMS">
<data xmi:type="notation:Diagram" xmi:id="_55wDEXy5Ee-JXeucC-Gkng" type="Sirius" element="_55oHQHy5Ee-JXeucC-Gkng" measurementUnit="Pixel">
<children xmi:type="notation:Node" xmi:id="_9rJ4IHy5Ee-JXeucC-Gkng" type="2003" element="_9rBVQHy5Ee-JXeucC-Gkng">
<children xmi:type="notation:Node" xmi:id="_9rKfMHy5Ee-JXeucC-Gkng" type="5007"/>
<children xmi:type="notation:Node" xmi:id="_9rKfMXy5Ee-JXeucC-Gkng" type="7004">
<styles xmi:type="notation:SortingStyle" xmi:id="_9rKfMny5Ee-JXeucC-Gkng"/>
<styles xmi:type="notation:FilteringStyle" xmi:id="_9rKfM3y5Ee-JXeucC-Gkng"/>
</children>
<styles xmi:type="notation:ShapeStyle" xmi:id="_9rJ4IXy5Ee-JXeucC-Gkng" fontName="Segoe UI" fontHeight="8"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_9rJ4Iny5Ee-JXeucC-Gkng" x="20" y="50"/>
</children>
<children xmi:type="notation:Node" xmi:id="_CeUFIHy6Ee-JXeucC-Gkng" type="2003" element="_CeNXcHy6Ee-JXeucC-Gkng">
<children xmi:type="notation:Node" xmi:id="_CeUFI3y6Ee-JXeucC-Gkng" type="5007"/>
<children xmi:type="notation:Node" xmi:id="_CeUFJHy6Ee-JXeucC-Gkng" type="7004">
<styles xmi:type="notation:SortingStyle" xmi:id="_CeUFJXy6Ee-JXeucC-Gkng"/>
<styles xmi:type="notation:FilteringStyle" xmi:id="_CeUFJny6Ee-JXeucC-Gkng"/>
</children>
<styles xmi:type="notation:ShapeStyle" xmi:id="_CeUFIXy6Ee-JXeucC-Gkng" fontName="Segoe UI" fontHeight="8"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_CeUFIny6Ee-JXeucC-Gkng" x="300" y="50"/>
</children>
<styles xmi:type="notation:DiagramStyle" xmi:id="_55wDEny5Ee-JXeucC-Gkng"/>
</data>
</ownedAnnotationEntries>
<ownedAnnotationEntries xmi:type="description:AnnotationEntry" uid="_551ioHy5Ee-JXeucC-Gkng" source="DANNOTATION_CUSTOMIZATION_KEY">
<data xmi:type="diagram:ComputedStyleDescriptionRegistry" uid="_552JsHy5Ee-JXeucC-Gkng"/>
</ownedAnnotationEntries>
<ownedDiagramElements xmi:type="diagram:DNodeList" uid="_9rBVQHy5Ee-JXeucC-Gkng" name="A">
<target xmi:type="org.polarsys.capella.core.data.information:Class" href="RelationStabilityCDB.capella#2a30d109-d64f-4aa4-81f0-3b16e023c542"/>
<semanticElements xmi:type="org.polarsys.capella.core.data.information:Class" href="RelationStabilityCDB.capella#2a30d109-d64f-4aa4-81f0-3b16e023c542"/>
<ownedStyle xmi:type="diagram:FlatContainerStyle" uid="_9rB8UHy5Ee-JXeucC-Gkng" borderSize="1" borderSizeComputationExpression="1" borderColor="123,105,79" backgroundStyle="Liquid" foregroundColor="232,224,210">
<description xmi:type="style:FlatContainerStyleDescription" href="platform:/plugin/org.polarsys.capella.core.sirius.analysis/description/common.odesign#//@ownedViewpoints[name='Common']/@ownedRepresentations[name='Class%20Diagram%20Blank']/@defaultLayer/@containerMappings[name='DT_Class']/@style"/>
</ownedStyle>
<actualMapping xmi:type="description_1:ContainerMapping" href="platform:/plugin/org.polarsys.capella.core.sirius.analysis/description/common.odesign#//@ownedViewpoints[name='Common']/@ownedRepresentations[name='Class%20Diagram%20Blank']/@defaultLayer/@containerMappings[name='DT_Class']"/>
</ownedDiagramElements>
<ownedDiagramElements xmi:type="diagram:DNodeList" uid="_CeNXcHy6Ee-JXeucC-Gkng" name="B">
<target xmi:type="org.polarsys.capella.core.data.information:Class" href="RelationStabilityCDB.capella#ca411035-9f42-471e-bcc4-2f139ef39f6f"/>
<semanticElements xmi:type="org.polarsys.capella.core.data.information:Class" href="RelationStabilityCDB.capella#ca411035-9f42-471e-bcc4-2f139ef39f6f"/>
<ownedStyle xmi:type="diagram:FlatContainerStyle" uid="_CeNXcXy6Ee-JXeucC-Gkng" borderSize="1" borderSizeComputationExpression="1" borderColor="123,105,79" backgroundStyle="Liquid" foregroundColor="232,224,210">
<description xmi:type="style:FlatContainerStyleDescription" href="platform:/plugin/org.polarsys.capella.core.sirius.analysis/description/common.odesign#//@ownedViewpoints[name='Common']/@ownedRepresentations[name='Class%20Diagram%20Blank']/@defaultLayer/@containerMappings[name='DT_Class']/@style"/>
</ownedStyle>
<actualMapping xmi:type="description_1:ContainerMapping" href="platform:/plugin/org.polarsys.capella.core.sirius.analysis/description/common.odesign#//@ownedViewpoints[name='Common']/@ownedRepresentations[name='Class%20Diagram%20Blank']/@defaultLayer/@containerMappings[name='DT_Class']"/>
</ownedDiagramElements>
<description xmi:type="description_1:DiagramDescription" href="platform:/plugin/org.polarsys.capella.core.sirius.analysis/description/common.odesign#//@ownedViewpoints[name='Common']/@ownedRepresentations[name='Class%20Diagram%20Blank']"/>
<activatedFilters xmi:type="filter:CompositeFilterDescription" href="platform:/plugin/org.polarsys.kitalpha.ad.integration.sirius/description/ad.odesign#//@ownedViewpoints[name='ad']/@ownedRepresentations[name='AD%20diagram']/@filters[name='ModelExtensionFilter']"/>
<activatedFilters xmi:type="filter:CompositeFilterDescription" href="platform:/plugin/org.polarsys.capella.core.sirius.analysis/description/common.odesign#//@ownedViewpoints[name='Common']/@ownedRepresentations[name='Class%20Diagram%20Blank']/@filters[name='hide.technical.interfaces.filter']"/>
<filterVariableHistory xmi:type="diagram:FilterVariableHistory" uid="_55oHQXy5Ee-JXeucC-Gkng"/>
<activatedLayers xmi:type="description_1:Layer" href="platform:/plugin/org.polarsys.capella.core.sirius.analysis/description/common.odesign#//@ownedViewpoints[name='Common']/@ownedRepresentations[name='Class%20Diagram%20Blank']/@defaultLayer"/>
<activatedLayers xmi:type="description_1:AdditionalLayer" href="platform:/plugin/org.polarsys.capella.core.sirius.analysis/description/common.odesign#//@ownedViewpoints[name='Common']/@ownedRepresentations[name='Class%20Diagram%20Blank']/@additionalLayers[name='Communication%20Model']"/>
<target xmi:type="org.polarsys.capella.core.data.information:DataPkg" href="RelationStabilityCDB.capella#6790f1ea-051b-4c74-9bff-a3f3d71c39f4"/>
</diagram:DSemanticDiagram>
</xmi:XMI>
Loading

0 comments on commit b0b5b4e

Please sign in to comment.