From 4dcfb4b31b291954ad88fa44b0c0f6251fecaccd Mon Sep 17 00:00:00 2001 From: suarezgpablo Date: Sat, 30 Nov 2024 09:13:49 +0100 Subject: [PATCH] Added rule to consider migration from ascendant entities and 3 entity (#111) relationships --- ...sBoardV11NewColumnNonKey-dataMigration.xmi | 2 +- ...hingsBoardV12NewColumnPK-dataMigration.xmi | 2 +- modevo-transform/dat/inp/ThingsBoardCM.xmi | 3 +-- .../atl/Metamodels/ConceptualModel.ecore | 2 ++ .../atl/Metamodels/DataMigration.ecore | 1 + .../modevo/transformations/atl/NewColumn.atl | 26 ++++++++++++++++++- .../atl/helpers/ConceptualModelEntity.atl | 8 +++++- .../atl/helpers/SchemaTable.atl | 2 +- 8 files changed, 39 insertions(+), 7 deletions(-) diff --git a/modevo-transform/dat/bmk/testThingsBoardV11NewColumnNonKey-dataMigration.xmi b/modevo-transform/dat/bmk/testThingsBoardV11NewColumnNonKey-dataMigration.xmi index 667169f..e493b55 100644 --- a/modevo-transform/dat/bmk/testThingsBoardV11NewColumnNonKey-dataMigration.xmi +++ b/modevo-transform/dat/bmk/testThingsBoardV11NewColumnNonKey-dataMigration.xmi @@ -1,6 +1,6 @@ - + diff --git a/modevo-transform/dat/bmk/testThingsBoardV12NewColumnPK-dataMigration.xmi b/modevo-transform/dat/bmk/testThingsBoardV12NewColumnPK-dataMigration.xmi index 00c938a..fd49287 100644 --- a/modevo-transform/dat/bmk/testThingsBoardV12NewColumnPK-dataMigration.xmi +++ b/modevo-transform/dat/bmk/testThingsBoardV12NewColumnPK-dataMigration.xmi @@ -1,6 +1,6 @@ - + diff --git a/modevo-transform/dat/inp/ThingsBoardCM.xmi b/modevo-transform/dat/inp/ThingsBoardCM.xmi index d202745..3d7f9fe 100644 --- a/modevo-transform/dat/inp/ThingsBoardCM.xmi +++ b/modevo-transform/dat/inp/ThingsBoardCM.xmi @@ -20,7 +20,6 @@ - - + \ No newline at end of file diff --git a/modevo-transform/src/main/java/giis/modevo/transformations/atl/Metamodels/ConceptualModel.ecore b/modevo-transform/src/main/java/giis/modevo/transformations/atl/Metamodels/ConceptualModel.ecore index e9aab47..a064b92 100644 --- a/modevo-transform/src/main/java/giis/modevo/transformations/atl/Metamodels/ConceptualModel.ecore +++ b/modevo-transform/src/main/java/giis/modevo/transformations/atl/Metamodels/ConceptualModel.ecore @@ -23,6 +23,8 @@ + + diff --git a/modevo-transform/src/main/java/giis/modevo/transformations/atl/Metamodels/DataMigration.ecore b/modevo-transform/src/main/java/giis/modevo/transformations/atl/Metamodels/DataMigration.ecore index 86ba670..28a9a95 100644 --- a/modevo-transform/src/main/java/giis/modevo/transformations/atl/Metamodels/DataMigration.ecore +++ b/modevo-transform/src/main/java/giis/modevo/transformations/atl/Metamodels/DataMigration.ecore @@ -18,6 +18,7 @@ + diff --git a/modevo-transform/src/main/java/giis/modevo/transformations/atl/NewColumn.atl b/modevo-transform/src/main/java/giis/modevo/transformations/atl/NewColumn.atl index b23c392..2872d9a 100644 --- a/modevo-transform/src/main/java/giis/modevo/transformations/atl/NewColumn.atl +++ b/modevo-transform/src/main/java/giis/modevo/transformations/atl/NewColumn.atl @@ -23,9 +23,12 @@ lazy rule MigCol { ->select (c | c.nameAttribute = r.nameAttribute and c.nameEntity = r.nameEntity and thisModule.keyInTable(c.tableColumn, keyColumnToColumn)).first(); --Gets key columns colKeyFromVariable: Sequence (Schema!Column) = colFromVariable.tableColumn.Column -> select (c | c.equivalentColumnInSequenceTables(keyColumnToColumn)); + + ascendantsUsed : Boolean = thisModule.ascendentsUsed (r.tab.tableFromLM().Column, thisModule.extractEntityByName (r.nameEntity), r.tab.tableFromLM()); } to add: DataMigration!MigrationCol ( --for each new column + multipleMigration <- ascendantsUsed, ColTo <- thisModule.columnTo (r, keyColumnToColumn), ColFrom <- thisModule.columnFrom (colKeyFromVariable, colFromVariable) ) @@ -81,10 +84,31 @@ helper def: typeKey (columns: Sequence (Schema!Column), entity: ConceptualModel! if (not (table.descendentsEntityInTable(entity).isEmpty())) then thisModule.keyEntitiesSequence (columns, table.descendentsEntityInTable(entity)) else - thisModule.keyEntitiesSequence (columns, table.NMEntities(entity)) + if (not (table.NMEntities(entity).isEmpty())) + then thisModule.keyEntitiesSequence (columns, table.NMEntities(entity)) + else + thisModule.keyEntitiesSequence (columns, table.ascendantsEntityInTable(entity)) + endif + endif + endif; + +---Copy of typeKey to know if "thisModule.keyEntitiesSequence (columns, table.ascendantsEntityInTable(entity)" was used +helper def: ascendentsUsed (columns: Sequence (Schema!Column), entity: ConceptualModel!Entity, table: Schema!Table): Boolean = +if (thisModule.isKeyEntityInColumns (columns, entity)) + then false + else + if (not (table.descendentsEntityInTable(entity).isEmpty())) + then false + else + if (not (table.NMEntities(entity).isEmpty())) + then false + else + true + endif endif endif; + ---Returns true if in given columns there are columns associated to the key attributes of entity helper def: isKeyEntityInColumns (columns: Sequence (Schema!Column), entity: ConceptualModel!Entity): Boolean = let keyAttributes : Sequence (ConceptualModel!Attribute) = diff --git a/modevo-transform/src/main/java/giis/modevo/transformations/atl/helpers/ConceptualModelEntity.atl b/modevo-transform/src/main/java/giis/modevo/transformations/atl/helpers/ConceptualModelEntity.atl index 3b060e5..d8aa72b 100644 --- a/modevo-transform/src/main/java/giis/modevo/transformations/atl/helpers/ConceptualModelEntity.atl +++ b/modevo-transform/src/main/java/giis/modevo/transformations/atl/helpers/ConceptualModelEntity.atl @@ -50,7 +50,13 @@ helper context ConceptualModel!Entity def: entitiesRelatedAscendancy (): Sequenc ---Returns true if the given entity is detail of e helper context ConceptualModel!Entity def: isEntityAscendancy (e: ConceptualModel!Entity): Boolean = - if (ConceptualModel!Relationship.allInstancesFrom('CM')->any (r | (r.entity1 = e and r.entity2 = self and r.cardinality1 = 'n' and r.cardinality2 = '1') or (r.entity1 = self and r.entity2 = e and r.cardinality1 = '1' and r.cardinality2 = 'n')).oclIsUndefined()) + if (ConceptualModel!Relationship.allInstancesFrom('CM')->any (r | (r.entity1 = e and r.entity2 = self and r.cardinality1 = 'n' and r.cardinality2 = '1') + or (r.entity1 = self and r.entity2 = e and r.cardinality1 = '1' and r.cardinality2 = 'n') + or (r.entity1 = e and r.entity3 = self and r.cardinality1 = 'n' and r.cardinality3 = '1') + or (r.entity1 = self and r.entity3 = e and r.cardinality1 = '1' and r.cardinality3 = 'n') + or (r.entity2 = e and r.entity3 = self and r.cardinality2 = 'n' and r.cardinality3 = '1') + or (r.entity2 = self and r.entity3 = e and r.cardinality2 = '1' and r.cardinality3 = 'n') + ).oclIsUndefined()) then false else diff --git a/modevo-transform/src/main/java/giis/modevo/transformations/atl/helpers/SchemaTable.atl b/modevo-transform/src/main/java/giis/modevo/transformations/atl/helpers/SchemaTable.atl index fa98bc6..187ad15 100644 --- a/modevo-transform/src/main/java/giis/modevo/transformations/atl/helpers/SchemaTable.atl +++ b/modevo-transform/src/main/java/giis/modevo/transformations/atl/helpers/SchemaTable.atl @@ -32,7 +32,7 @@ helper context Schema!Table def: EntitiesInTable (): Sequence (ConceptualModel!E ---Obtains the entities that are in the self table that are also ascendants of e helper context Schema!Table def: ascendantsEntityInTable (e: ConceptualModel!Entity): Sequence (ConceptualModel!Entity) = - e.entitiesRelatedAscendancy().intersection(self.EntitiesInTable()); + e.entitiesRelatedAscendancy()->select (entity | self.EntitiesInTable().includes(entity)); ---Obtains the key columns of a given table. helper def: keyColumnsNewTable (table : SchemaEvolution!Table): Sequence (SchemaEvolution!Column) =