Commit 614f9e72 authored by npedot's avatar npedot
Browse files

adds Labeller delegate

parent c0c1db64
...@@ -3,8 +3,9 @@ package unibz.cs.semint.kprime.domain.ddl ...@@ -3,8 +3,9 @@ package unibz.cs.semint.kprime.domain.ddl
import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import unibz.cs.semint.kprime.domain.ddl.schemalgo.equivalent
class Column (): Labelled { class Column (): Labelled by Labeller() {
@JacksonXmlProperty(isAttribute = true) @JacksonXmlProperty(isAttribute = true)
var name: String = "" var name: String = ""
@JacksonXmlProperty(isAttribute = true) @JacksonXmlProperty(isAttribute = true)
...@@ -25,6 +26,8 @@ class Column (): Labelled { ...@@ -25,6 +26,8 @@ class Column (): Labelled {
var role: String? = null var role: String? = null
@JacksonXmlProperty(isAttribute = true) @JacksonXmlProperty(isAttribute = true)
var labels: String? = null var labels: String? = null
get() = if (labelsAsString().isEmpty()) null else labelsAsString()
set(value) { field = resetLabels(value?:"") }
@JacksonXmlProperty(isAttribute = true) @JacksonXmlProperty(isAttribute = true)
var default: Any? = null var default: Any? = null
@JacksonXmlProperty(isAttribute = true) @JacksonXmlProperty(isAttribute = true)
...@@ -80,35 +83,6 @@ class Column (): Labelled { ...@@ -80,35 +83,6 @@ class Column (): Labelled {
} }
} }
} }
override fun resetLabels(labelsAsString: String): String {
labels = labelsAsString
return labels!!
}
override fun addLabels(labelsAsString: String): String {
if (labels==null) labels = labelsAsString
else labels += labelsAsString
return labels!!
}
override fun addLabels(newLabels: List<Label>): String {
return addLabels(newLabels.joinToString(","))
}
override fun remLabels(newLabels: List<Label>): String {
val labels2 = labels ?: return ""
return resetLabels(labels2.split(",")
.filter { !newLabels.contains(it) }
.joinToString(","))
}
override fun hasLabel(label: String): Boolean {
return labels?.contains(label)?:false
}
override fun labelsAsString(): String {
return labels?: ""
}
override fun toString(): String { override fun toString(): String {
return name return name
......
...@@ -6,7 +6,7 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty ...@@ -6,7 +6,7 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
@JacksonXmlRootElement(localName = "constraint") @JacksonXmlRootElement(localName = "constraint")
class Constraint : Labelled { class Constraint : Labelled by Labeller() {
fun left(): Collection<Column> { fun left(): Collection<Column> {
return source.columns return source.columns
} }
...@@ -45,6 +45,8 @@ class Constraint : Labelled { ...@@ -45,6 +45,8 @@ class Constraint : Labelled {
@JacksonXmlProperty(isAttribute = true) @JacksonXmlProperty(isAttribute = true)
var labels: String? = null var labels: String? = null
get() = if (labelsAsString().isEmpty()) null else labelsAsString()
set(value) { field = resetLabels(value?:"") }
fun clone():Constraint { fun clone():Constraint {
val objectMapper = ObjectMapper() val objectMapper = ObjectMapper()
...@@ -142,36 +144,6 @@ class Constraint : Labelled { ...@@ -142,36 +144,6 @@ class Constraint : Labelled {
} }
} }
override fun resetLabels(labelsAsString: String): String {
labels = labelsAsString
return labels!!
}
override fun addLabels(labelsAsString: String): String {
if (labels==null) labels = labelsAsString
else labels += labelsAsString
return labels!!
}
override fun addLabels(newLabels: List<Label>): String {
return addLabels(newLabels.joinToString(","))
}
override fun hasLabel(label: String): Boolean {
return labels?.contains(label)?:false
}
override fun labelsAsString(): String {
return labels?: ""
}
override fun remLabels(newLabels: List<Label>): String {
val labels2 = labels ?: return ""
return resetLabels(labels2.split(",")
.filter { !newLabels.contains(it) }
.joinToString(","))
}
fun toStringWithName(): String { fun toStringWithName(): String {
return "${this.name}:${toString()}" return "${this.name}:${toString()}"
} }
......
package unibz.cs.semint.kprime.domain.ddl
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
class Labeller(): Labelled {
@JacksonXmlProperty(isAttribute = true)
var labels: String? = null
override fun resetLabels(labelsAsString: String): String {
labels = labelsAsString
return labels!!
}
override fun addLabels(labelsAsString: String): String {
if (labels==null) labels = labelsAsString
else labels += labelsAsString
return labels!!
}
override fun addLabels(newLabels: List<Label>): String {
return addLabels(newLabels.joinToString(","))
}
override fun hasLabel(label: String): Boolean {
return labels?.contains(label)?:false
}
override fun labelsAsString(): String {
return labels?: ""
}
override fun remLabels(newLabels: List<Label>): String {
val labels2 = labels ?: return ""
return resetLabels(labels2.split(",")
.filter { !newLabels.contains(it) }
.joinToString(","))
}
}
\ No newline at end of file
...@@ -4,7 +4,7 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty ...@@ -4,7 +4,7 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
@JacksonXmlRootElement(localName = "table") @JacksonXmlRootElement(localName = "table")
class Table (): Labelled { class Table (): Labelled by Labeller(){
@JacksonXmlProperty(isAttribute = true) @JacksonXmlProperty(isAttribute = true)
var name: String ="" var name: String =""
...@@ -23,9 +23,6 @@ class Table (): Labelled { ...@@ -23,9 +23,6 @@ class Table (): Labelled {
var columns= ArrayList<Column>() var columns= ArrayList<Column>()
@JacksonXmlProperty(isAttribute = true)
var labels: String? = null
@JacksonXmlProperty(isAttribute = true) @JacksonXmlProperty(isAttribute = true)
var catalog: String? = null var catalog: String? = null
...@@ -35,6 +32,10 @@ class Table (): Labelled { ...@@ -35,6 +32,10 @@ class Table (): Labelled {
@JacksonXmlProperty(isAttribute = true) @JacksonXmlProperty(isAttribute = true)
var source: String? = null var source: String? = null
@JacksonXmlProperty(isAttribute = true)
var labels: String? = null
get() = if (labelsAsString().isEmpty()) null else labelsAsString()
set(value) { field = resetLabels(value?:"") }
fun hasColumn(nameToFind:String): Boolean { fun hasColumn(nameToFind:String): Boolean {
for (col in columns) { for (col in columns) {
...@@ -79,43 +80,13 @@ class Table (): Labelled { ...@@ -79,43 +80,13 @@ class Table (): Labelled {
this.columns.addAll(cols) this.columns.addAll(cols)
} }
override fun resetLabels(labelsAsString: String): String {
labels = labelsAsString
return labels!!
}
override fun addLabels(labelsAsString: String): String {
if (labels==null) labels = labelsAsString
else labels += labelsAsString
return labels!!
}
override fun addLabels(newLabels: List<Label>): String {
return addLabels(newLabels.joinToString(","))
}
override fun hasLabel(label: String): Boolean {
return labels?.contains(label)?:false
}
override fun labelsAsString(): String {
return labels?: ""
}
override fun remLabels(newLabels: List<Label>): String {
val labels2 = labels ?: return ""
return resetLabels(labels2.split(",")
.filter { !newLabels.contains(it) }
.joinToString(","))
}
fun addColomunsLabels(labelsAsString: String): String { fun addColomunsLabels(labelsAsString: String): String {
for (column in columns) column.addLabels(labelsAsString) for (column in columns) column.addLabels(labelsAsString)
return "" return ""
} }
override fun toString(): String { override fun toString(): String {
return "Table(name='$name', id='$id', view='$view', condition='$condition', parent=$parent, columns=$columns, labels=$labels, catalog=$catalog, schema=$schema, source=$source)" return "Table(name='$name', id='$id', view='$view', condition='$condition', parent=$parent, columns=$columns, catalog=$catalog, schema=$schema, source=$source)"
} }
......
package unibz.cs.semint.kprime.domain.ddl package unibz.cs.semint.kprime.domain.ddl
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import org.junit.Test import org.junit.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
...@@ -23,4 +24,31 @@ class ColumnTest { ...@@ -23,4 +24,31 @@ class ColumnTest {
assertEquals("colA",col.name) assertEquals("colA",col.name)
} }
@Test
fun test_json() {
// given
val col = Column.of("colA")
// when
val colJson = jacksonObjectMapper().writeValueAsString(col)
// then
val result = """
{"name":"colA","id":"","dbname":null,"nullable":false,"dbtype":"","type":null,"unit":null,"cardinality":null,"role":null,"labels":null,"default":null,"dbtable":""}
""".trimIndent()
assertEquals(result,colJson)
}
@Test
fun test_json_with_labels() {
// given
val col = Column.of("colA")
col.labels = "aaa"
// when
val colJson = jacksonObjectMapper().writeValueAsString(col)
// then
val result = """
{"name":"colA","id":"","dbname":null,"nullable":false,"dbtype":"","type":null,"unit":null,"cardinality":null,"role":null,"labels":"aaa","default":null,"dbtable":""}
""".trimIndent()
assertEquals(result,colJson)
}
} }
\ No newline at end of file
...@@ -43,20 +43,20 @@ class YAMLSerializerDatabaseTest { ...@@ -43,20 +43,20 @@ class YAMLSerializerDatabaseTest {
condition: "" condition: ""
parent: null parent: null
columns: [] columns: []
labels: null
catalog: null catalog: null
schema: null schema: null
source: null source: null
labels: null
- name: "" - name: ""
id: "" id: ""
view: "" view: ""
condition: "" condition: ""
parent: null parent: null
columns: [] columns: []
labels: null
catalog: null catalog: null
schema: null schema: null
source: null source: null
labels: null
constraints: [] constraints: []
mappings: [] mappings: []
source: "" source: ""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment