From 4fbbb10eb1f3dd979eaec953e5803dc71fb9fe4d Mon Sep 17 00:00:00 2001
From: npedot <nicola.pedot@gmail.com>
Date: Wed, 1 Apr 2020 09:59:51 +0200
Subject: [PATCH] adds cmd add double inclusion to schema

---
 .../domain/ddl/Schema.kt                      | 24 +++++++++++++++++++
 .../domain/SchemaTest.kt                      | 13 ++++++++++
 2 files changed, 37 insertions(+)

diff --git a/src/main/kotlin/unibz.cs.semint.kprime/domain/ddl/Schema.kt b/src/main/kotlin/unibz.cs.semint.kprime/domain/ddl/Schema.kt
index dd34fa3..bd82e5d 100644
--- a/src/main/kotlin/unibz.cs.semint.kprime/domain/ddl/Schema.kt
+++ b/src/main/kotlin/unibz.cs.semint.kprime/domain/ddl/Schema.kt
@@ -62,6 +62,10 @@ class Schema () {
         return constraints().filter { c -> c.type.equals(Constraint.TYPE.FOREIGN_KEY.name) }
     }
 
+    fun doubleIncs(): List<Constraint> {
+        return constraints().filter { c -> c.type.equals(Constraint.TYPE.DOUBLE_INCLUSION.name) }
+    }
+
     fun functionalLHS(tableName: String): Set<Column> {
         var resultCols = mutableSetOf<Column>()
         val first = constraints().filter { c ->
@@ -161,6 +165,26 @@ class Schema () {
         return this
     }
 
+    fun addDoubleInc(commandArgs:String):Schema {
+        val source:String = commandArgs.split("-->")[0]
+        val target:String = commandArgs.split("-->")[1]
+
+        val sourceTableName:String = source.split(":")[0]
+        val sourceAttributeNames = source.split(":")[1]
+
+        val targetTableName:String = target.split(":")[0]
+        val targetAttributeNames = target.split(":")[1]
+
+        val constraint = doubleInclusion {}
+        constraint.name = "${sourceTableName}_${targetTableName}.doubleInc"
+        constraint.source.table=sourceTableName
+        constraint.target.table=targetTableName
+        constraint.source.columns.addAll(Column.set(sourceAttributeNames))
+        constraint.target.columns.addAll(Column.set(targetAttributeNames))
+        constraints().add(constraint)
+        return this
+    }
+
     companion object {
 
         private fun <T> reducedPowerSet(originalSet: Set<T>): Set<Set<T>> {
diff --git a/src/test/kotlin/unibz.cs.semint.kprime/domain/SchemaTest.kt b/src/test/kotlin/unibz.cs.semint.kprime/domain/SchemaTest.kt
index 3b17318..a7693e5 100644
--- a/src/test/kotlin/unibz.cs.semint.kprime/domain/SchemaTest.kt
+++ b/src/test/kotlin/unibz.cs.semint.kprime/domain/SchemaTest.kt
@@ -208,4 +208,17 @@ class SchemaTest {
         // then
         assertEquals(1,schema.foreignKeys().size)
     }
+
+
+    @Test
+    fun test_addDoubleInc() {
+        // given
+        var schema = Schema()
+        assertEquals(0,schema.doubleIncs().size)
+        // when
+        schema.addDoubleInc("person:dep_id-->department:dep_id")
+        // then
+        assertEquals(1,schema.doubleIncs().size)
+    }
+
 }
\ No newline at end of file
-- 
GitLab