Skip to content
Snippets Groups Projects
Commit 100a4613 authored by npedot's avatar npedot
Browse files

adds first version of labels to column

parent b24ea7ae
No related branches found
No related tags found
No related merge requests found
......@@ -3,9 +3,8 @@ package unibz.cs.semint.kprime.domain.ddl
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import kotlin.math.exp
class Column () {
class Column (): Labelled {
@JacksonXmlProperty(isAttribute = true)
var name: String = ""
@JacksonXmlProperty(isAttribute = true)
......@@ -24,6 +23,10 @@ class Column () {
var cardinality: String? = null
@JacksonXmlProperty(isAttribute = true)
var role: String? = null
@JacksonXmlProperty(isAttribute = true)
var labels: String? = null
private var labeller = Labeller()
@JsonCreator
constructor(
......@@ -37,7 +40,7 @@ class Column () {
companion object {
fun set(expr:String):Set<Column> {
if (expr.isEmpty()) return HashSet<Column>()
if (expr.isEmpty()) return HashSet()
val names = expr.replace("\\s+","")
return set(names.split(","))
}
......@@ -58,8 +61,31 @@ class Column () {
}
}
override fun resetLabels(labelsAsString: String): String {
labels = labeller.resetLabels(labelsAsString)
return labelsAsString()
}
override fun addLabels(labelsAsString: String): String {
labels = labeller.addLabels(labelsAsString)
return labelsAsString()
}
override fun addLabels(newLabels: List<Label>): String {
labels = labeller.addLabels(newLabels)
return labelsAsString()
}
override fun labelsAsString(): String {
return labels?: ""
}
override fun hasLabel(label: String): Boolean {
return labeller.hasLabel(label)
}
override fun toString(): String {
return "$name"
return name
}
override fun equals(other: Any?): Boolean {
......
......@@ -5,36 +5,6 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
fun addKey(alfa:Constraint.()->Unit):Constraint {
val constraint = Constraint()
constraint.type = Constraint.TYPE.PRIMARY_KEY.name
return constraint
}
fun foreignkey(alfa:Constraint.()->Unit):Constraint {
val constraint = Constraint()
constraint.type = Constraint.TYPE.FOREIGN_KEY.name
return constraint
}
fun addFunctional(alfa:Constraint.()->Unit):Constraint {
val constraint = Constraint()
constraint.type = Constraint.TYPE.FUNCTIONAL.name
return constraint
}
fun inclusion(alfa:Constraint.()->Unit):Constraint {
val constraint = Constraint()
constraint.type = Constraint.TYPE.INCLUSION.name
return constraint
}
fun doubleInclusion(alfa:Constraint.()->Unit):Constraint {
val constraint = Constraint()
constraint.type = Constraint.TYPE.DOUBLE_INCLUSION.name
return constraint
}
@JacksonXmlRootElement(localName = "constraint")
class Constraint () {
fun left(): Collection<Column> {
......@@ -89,6 +59,37 @@ class Constraint () {
companion object {
fun addKey(alfa:Constraint.()->Unit):Constraint {
val constraint = Constraint()
constraint.type = Constraint.TYPE.PRIMARY_KEY.name
return constraint
}
fun foreignkey(alfa:Constraint.()->Unit):Constraint {
val constraint = Constraint()
constraint.type = Constraint.TYPE.FOREIGN_KEY.name
return constraint
}
fun addFunctional(alfa:Constraint.()->Unit):Constraint {
val constraint = Constraint()
constraint.type = Constraint.TYPE.FUNCTIONAL.name
return constraint
}
fun inclusion(alfa:Constraint.()->Unit):Constraint {
val constraint = Constraint()
constraint.type = Constraint.TYPE.INCLUSION.name
return constraint
}
fun doubleInclusion(alfa:Constraint.()->Unit):Constraint {
val constraint = Constraint()
constraint.type = Constraint.TYPE.DOUBLE_INCLUSION.name
return constraint
}
fun set(exprs : String ):Set<Constraint> {
if (exprs.equals("")) return HashSet<Constraint>()
val replace = exprs.replace("\\s+", "")
......
package unibz.cs.semint.kprime.domain.ddl
typealias Label = String
\ No newline at end of file
package unibz.cs.semint.kprime.domain.ddl
interface Labelled {
fun resetLabels(labelsAsString:String): String
fun addLabels(labelsAsString: String): String
fun addLabels(newLabels:List<Label>): String
fun labelsAsString():String
fun hasLabel(label:String) :Boolean
}
\ No newline at end of file
package unibz.cs.semint.kprime.domain.ddl
class Labeller: Labelled {
private lateinit var labels : MutableList<Label>
override
fun resetLabels(labelsAsString: String):String {
if (labels==null) labels = mutableListOf()
else labels.clear()
addLabels(labelsAsString)
return labelsAsString()
}
override
fun addLabels(labelsAsString: String):String {
if (labels==null) labels = mutableListOf()
labels.addAll(labelsAsString.split(","))
return labelsAsString()
}
override
fun addLabels(newLabels: List<Label>): String {
if (labels==null) labels = mutableListOf()
labels.addAll(newLabels)
return labelsAsString()
}
override
fun labelsAsString(): String {
return labels?.joinToString(",")?: ""
}
override
fun hasLabel(label:String):Boolean {
return labelsAsString().contains(label)
}
}
\ No newline at end of file
......@@ -178,7 +178,7 @@ class Schema () {
fun addKey(commandArgs:String):Schema {
val tableName:String = commandArgs.split(":")[0]
val attributeNames = commandArgs.split(":")[1]
val constraint = addKey {}
val constraint = Constraint.addKey {}
constraint.name = tableName+".primaryKey"
constraint.source.table=tableName
constraint.target.table=tableName
......@@ -198,7 +198,7 @@ class Schema () {
val targetTableName:String = target.split(":")[0]
val targetAttributeNames = target.split(":")[1]
val constraint = foreignkey {}
val constraint = Constraint.foreignkey {}
constraint.name = "${sourceTableName}_${targetTableName}.foreignKey"
constraint.source.table=sourceTableName
constraint.target.table=targetTableName
......@@ -218,7 +218,7 @@ class Schema () {
val targetTableName:String = target.split(":")[0]
val targetAttributeNames = target.split(":")[1]
val constraint = doubleInclusion {}
val constraint = Constraint.doubleInclusion {}
constraint.name = "${sourceTableName}_${targetTableName}.doubleInc"
constraint.source.table=sourceTableName
constraint.target.table=targetTableName
......
......@@ -2,8 +2,7 @@ package unibz.cs.semint.kprime.scenario.person
import org.junit.Test
import unibz.cs.semint.kprime.adapter.service.XMLSerializerJacksonAdapter
import unibz.cs.semint.kprime.domain.ddl.doubleInclusion
import unibz.cs.semint.kprime.domain.ddl.addKey
import unibz.cs.semint.kprime.domain.ddl.Constraint
import unibz.cs.semint.kprime.domain.dml.*
import kotlin.test.assertEquals
......@@ -24,8 +23,8 @@ class PersonVSplitChangesetTI {
vsplitChangeSet minus dropPersonTable minus dropPrimaryKeyConstraint
val table1 = CreateTable() name "person1" withColumn "K" withColumn "T" withColumn "S"
val table2 = CreateTable() name "person2" withColumn "T" withColumn "S"
val doubleInc = doubleInclusion {}
val person2Key = addKey { }
val doubleInc = Constraint.doubleInclusion {}
val person2Key = Constraint.addKey { }
vsplitChangeSet plus table1 plus table2 plus doubleInc plus person2Key
val serializedChangeSet = XMLSerializerJacksonAdapter().prettyChangeSet(vsplitChangeSet)
println(serializedChangeSet)
......
......@@ -99,7 +99,6 @@ class ApplyChangeSetUseCaseTest {
val newdb = ApplyChangeSetUseCase(serializer).apply(db, changeset)
//then
// checks identity
val serializeDb = serializer.serializeDatabase(db)
val serializeNewDb = serializer.prettyDatabase(newdb)
val expectedDb = """
<database name="person" id="" source="">
......@@ -172,8 +171,8 @@ class ApplyChangeSetUseCaseTest {
vsplitChangeSet minus dropPersonTable minus dropPrimaryKeyConstraint
val table1 = CreateTable() name "person1" withColumn "K" withColumn "T" withColumn "S"
val table2 = CreateTable() name "person2" withColumn "T" withColumn "S"
val doubleInc = doubleInclusion {}
val person2Key = addKey { }
val doubleInc = Constraint.doubleInclusion {}
val person2Key = Constraint.addKey { }
vsplitChangeSet plus table1 plus table2 plus doubleInc plus person2Key
return vsplitChangeSet
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment