Skip to content

Commit

Permalink
eclipse-capella#2913 Make association source and target reliable in CDB
Browse files Browse the repository at this point in the history
This commit updates the CDB association edge mapping in the VSM
(source/target mappings and styles) to make association source and
target reliable in CDB, to always have the same source and target, and
to prevent a change in property from changing the source or the target.

This commit also adds a migration to reverse the association edge in the
wrong direction in existing projects.

Signed-off-by: Séraphin Costa <[email protected]>
  • Loading branch information
scosta-obeo committed Nov 21, 2024
1 parent ab46da0 commit 0abfad1
Show file tree
Hide file tree
Showing 7 changed files with 408 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@
<migrationContributor
class="org.polarsys.capella.core.data.migration.aird.AutoSizeSquareStyleMigrationContributor">
</migrationContributor>
<migrationContributor
class="org.polarsys.capella.core.data.migration.aird.AssociationCDBMigrationContributor">
</migrationContributor>

</extension>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ public class MigrationConstants {
public static final String MIGRATION_KIND__VIEWPOINT = "MIGRATION_KIND__VIEWPOINT";
public static final String MIGRATION_KIND__IMAGE_DEPENDENCIES = "MIGRATION_KIND__IMAGE_DEPENDENCIES";
public static final String MIGRATION_KIND__AUTOSIZE_SQUARE_STYLE = "MIGRATION_KIND__AUTOSIZE_SQUARE_STYLE";
public static final String MIGRATION_KIND__ASSOCIATION_CDB = "MIGRATION_KIND__ASSOCIATION_CDB";

public static final String[] DEFAULT_KIND_ORDER = { MIGRATION_KIND__CHECK_MISSING_VP, MIGRATION_KIND__PATTERN,
MIGRATION_KIND__SEMANTIC, MIGRATION_KIND__DIAGRAM, MIGRATION_KIND__FCDDIAGRAM, MIGRATION_KIND__AFM,
MIGRATION_KIND__VIEWPOINT, MIGRATION_KIND__SCF, MIGRATION_KIND__IMAGE_DEPENDENCIES, MIGRATION_KIND__AUTOSIZE_SQUARE_STYLE };
MIGRATION_KIND__VIEWPOINT, MIGRATION_KIND__SCF, MIGRATION_KIND__IMAGE_DEPENDENCIES, MIGRATION_KIND__AUTOSIZE_SQUARE_STYLE, MIGRATION_KIND__ASSOCIATION_CDB };
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class Messages extends NLS {
public static String MigrationAction_AutoSizeSquareStyleMigration;
public static String MigrationAction_DiagramMigration;
public static String MigrationAction_ImageProjectDependencies;
public static String MigrationAction_AssociationCDBMigration;
public static String MigrationAction_InvalidEdgeExtremityInvalidType;

static {
// initialize resource bundle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
#===============================================================================
MigrationAction_AutoSizeSquareStyleMigration=Auto-size Square style migration
MigrationAction_DiagramMigration=Diagrams migration
MigrationAction_ImageProjectDependencies=Image project dependencies migration
MigrationAction_ImageProjectDependencies=Image project dependencies migration
MigrationAction_AssociationCDBMigration=CDB association direction migration
MigrationAction_InvalidEdgeExtremityInvalidType=The source or target of the edge ''{0}'' in the diagram ''{1}'' should be a DSemanticDecorator. This edge has not been migrated.
Original file line number Diff line number Diff line change
Expand Up @@ -1868,7 +1868,7 @@
</style>
</conditionnalStyles>
<conditionnalStyles predicateExpression="aql:(self.getAssociationTarget().aggregationKind = information::AggregationKind::ASSOCIATION) and (self.getAssociationSource().aggregationKind = information::AggregationKind::ASSOCIATION) and (self.navigableMembers->includes(self.getAssociationSource())) and (not (self.navigableMembers->includes(self.getAssociationTarget())))">
<style strokeColor="//@userColorsPalettes[name='Migration%20Palette']/@entries[name='_CAP_Association_Color']">
<style strokeColor="//@userColorsPalettes[name='Migration%20Palette']/@entries[name='_CAP_Association_Color']" sourceArrow="InputArrow" targetArrow="NoDecoration">
<beginLabelStyleDescription showIcon="false" labelExpression="aql:self.getAssociationBeginRoleLabel(self,self.getAssociationSource(),view)">
<labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/>
</beginLabelStyleDescription>
Expand Down Expand Up @@ -1920,7 +1920,7 @@
</style>
</conditionnalStyles>
<conditionnalStyles predicateExpression="aql:(self.getAssociationTarget().aggregationKind = information::AggregationKind::ASSOCIATION) and (self.getAssociationSource().aggregationKind = information::AggregationKind::AGGREGATION) and (self.navigableMembers->includes(self.getAssociationSource())) and (not (self.navigableMembers->includes(self.getAssociationTarget())))">
<style strokeColor="//@userColorsPalettes[name='Migration%20Palette']/@entries[name='_CAP_Association_Color']" sourceArrow="InputArrowWithDiamond" targetArrow="NoDecoration">
<style strokeColor="//@userColorsPalettes[name='Migration%20Palette']/@entries[name='_CAP_Association_Color']" sourceArrow="InputArrow" targetArrow="Diamond">
<beginLabelStyleDescription showIcon="false" labelExpression="aql:self.getAssociationBeginRoleLabel(self,self.getAssociationSource(),view)">
<labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/>
</beginLabelStyleDescription>
Expand All @@ -1946,7 +1946,7 @@
</style>
</conditionnalStyles>
<conditionnalStyles predicateExpression="aql:(self.getAssociationTarget().aggregationKind = information::AggregationKind::ASSOCIATION) and (self.getAssociationSource().aggregationKind = information::AggregationKind::COMPOSITION) and (self.navigableMembers->size() = 0)">
<style strokeColor="//@userColorsPalettes[name='Migration%20Palette']/@entries[name='_CAP_Association_Color']" targetArrow="Diamond">
<style strokeColor="//@userColorsPalettes[name='Migration%20Palette']/@entries[name='_CAP_Association_Color']" targetArrow="FillDiamond">
<beginLabelStyleDescription showIcon="false" labelExpression="aql:self.getAssociationBeginRoleLabel(self,self.getAssociationSource(),view)">
<labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/>
</beginLabelStyleDescription>
Expand All @@ -1972,7 +1972,7 @@
</style>
</conditionnalStyles>
<conditionnalStyles predicateExpression="aql:(self.getAssociationTarget().aggregationKind = information::AggregationKind::ASSOCIATION) and (self.getAssociationSource().aggregationKind = information::AggregationKind::COMPOSITION) and (self.navigableMembers->includes(self.getAssociationSource())) and (not (self.navigableMembers->includes(self.getAssociationTarget())))">
<style strokeColor="//@userColorsPalettes[name='Migration%20Palette']/@entries[name='_CAP_Association_Color']" sourceArrow="InputArrowWithDiamond" targetArrow="FillDiamond">
<style strokeColor="//@userColorsPalettes[name='Migration%20Palette']/@entries[name='_CAP_Association_Color']" sourceArrow="InputArrow" targetArrow="FillDiamond">
<beginLabelStyleDescription showIcon="false" labelExpression="aql:self.getAssociationBeginRoleLabel(self,self.getAssociationSource(),view)">
<labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/>
</beginLabelStyleDescription>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Stream;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
Expand Down Expand Up @@ -749,16 +750,11 @@ private Property getOthers(Property property, Collection<Property> properties) {
* @return
*/
public Property getAssociationSource(Association association) {
int navigableMembersSize = association.getNavigableMembers().size();
if (1 == navigableMembersSize) {
return getOthers(association.getNavigableMembers().get(0), association.getOwnedMembers());
} else if (2 == navigableMembersSize) {
return association.getNavigableMembers().get(1);
} else if (!association.getOwnedMembers().isEmpty()) {
return association.getOwnedMembers().get(0);
} else {
return null;
}
return Stream.concat(association.getNavigableMembers().stream(), association.getOwnedMembers().stream())
// we sort properties by ascending Id to always have the same source
.sorted((prop1, prop2) -> prop1.getId().compareTo(prop2.getId()))
.findFirst()
.orElse(null);
}

/**
Expand All @@ -781,14 +777,11 @@ public Collection<Property> getAssociationProperties(Association association) {
* @return
*/
public Property getAssociationTarget(Association association) {
int navigableMembersSize = association.getNavigableMembers().size();
if ((1 == navigableMembersSize) || (2 == navigableMembersSize)) {
return association.getNavigableMembers().get(0);
} else if (association.getOwnedMembers().size() > 1) {
return association.getOwnedMembers().get(1);
} else {
return null;
}
return Stream.concat(association.getNavigableMembers().stream(), association.getOwnedMembers().stream())
// we sort properties by decreasing Id to always have the same target
.sorted((prop1, prop2) -> prop2.getId().compareTo(prop1.getId()))
.findFirst()
.orElse(null);
}

public AssociationPkg getSourceClassPkg(Class sourceClass) {
Expand Down

0 comments on commit 0abfad1

Please sign in to comment.