Commit a1c8e7e6 authored by npedot's avatar npedot
Browse files

adds vocabulary, vocabularies,sources to database entity

parent d8c2cf12
package unibz.cs.semint.kprime.domain.ddl
import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
import unibz.cs.semint.kprime.domain.DataSource
import unibz.cs.semint.kprime.domain.Gid
import unibz.cs.semint.kprime.domain.dql.Query
import unibz.cs.semint.kprime.domain.nextGid
......@@ -12,6 +14,7 @@ import javax.xml.bind.annotation.XmlElements
import kotlin.collections.ArrayList
@JacksonXmlRootElement(localName = "database")
@JsonInclude(JsonInclude.Include.NON_NULL)
open class Database () {
@JacksonXmlProperty(isAttribute = true)
......@@ -36,13 +39,24 @@ open class Database () {
@JacksonXmlElementWrapper(localName = "mappings")
@JacksonXmlProperty(localName = "query")
var mappings : MutableList<Query>? = ArrayList<Query>()
var mappings : MutableList<Query>? = ArrayList()
@JacksonXmlProperty(isAttribute = true)
var source: String = ""
@JacksonXmlElementWrapper(localName = "sources")
var sources : MutableList<DataSource>? = null
@JacksonXmlProperty(isAttribute = true)
var vocabulary: String? = ""
@JacksonXmlElementWrapper(localName = "vocabularies")
var vocabularies : MutableList<DataSource>? = null
init {
this.mappings = mutableListOf()
// this.sources = mutableListOf()
// this.vocabularies = mutableListOf()
}
fun lineage(tableName:String) : List<String> {
......@@ -58,7 +72,7 @@ open class Database () {
fun mappings():MutableList<Query> {
if (mappings!=null) return mappings as MutableList<Query>
return ArrayList<Query>()
return ArrayList()
}
fun mapping(name:String): Query? {
......
package unibz.cs.semint.kprime.adapter.jackson
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import org.junit.Test
import unibz.cs.semint.kprime.domain.DataSource
import kotlin.test.assertEquals
class JacksonOptionalFields {
@JsonInclude(JsonInclude.Include.NON_NULL)
class ToSer() {
@JacksonXmlProperty(isAttribute = true)
var vocabulary: String = ""
@JacksonXmlProperty(isAttribute = true)
var source: String = "sss"
@JacksonXmlElementWrapper(localName = "vocabularies")
var vocabularies : MutableList<DataSource>? = null
}
@Test
fun test_serialize_one_optional_field_unused() {
// given
val mapper = jacksonObjectMapper()
// when
val toSerString = mapper.writeValueAsString(ToSer())
// then
assertEquals("{\"vocabulary\":\"\",\"source\":\"sss\"}",toSerString)
}
@Test
fun test_deserialize_one_optional_field_unused() {
// given
val mapper = jacksonObjectMapper()
// val json = "{\"vocabulary\":\"aaa\",\"vocabularies\":null}"
val json = "{\"vocabulary\":\"aaa\"}"
// when
val toSerString = mapper.readValue<ToSer>(json)
// then
assertEquals("aaa",toSerString.vocabulary)
assertEquals("sss",toSerString.source)
}
}
\ No newline at end of file
......@@ -56,7 +56,7 @@ class DatabaseTest {
val dbXml = XMLSerializerJacksonAdapter().prettyDatabase(db)
// then
assertEquals("""
<database name="" id="" source="">
<database name="" id="" source="" vocabulary="">
<schema name="" id="">
<tables>
<table name="pure_person" id="" view="person" condition="person.T=null AND person.S=null">
......
......@@ -60,7 +60,7 @@ class ApplyChangeSetUseCaseTest {
val db = setUpPersonDb()
val serialized = XMLSerializerJacksonAdapter().prettyDatabase(db)
assertEquals("""
<database name="person" id="" source="">
<database name="person" id="" source="" vocabulary="">
<schema name="" id="">
<tables>
<table name="person" id="" view="" condition="">
......@@ -101,7 +101,7 @@ class ApplyChangeSetUseCaseTest {
// checks identity
val serializeNewDb = serializer.prettyDatabase(newdb)
val expectedDb = """
<database name="person" id="" source="">
<database name="person" id="" source="" vocabulary="">
<schema name="" id="">
<tables>
<table name="person1" id="" view="" condition="">
......@@ -220,7 +220,7 @@ class ApplyChangeSetUseCaseTest {
// checks identity
val serializeNewDb = serializer.prettyDatabase(newDB)
val expectedDb = """
<database name="" id="" source="">
<database name="" id="" source="" vocabulary="">
<schema name="" id="">
<tables>
<table name="person" id="t1" view="" condition="">
......@@ -299,7 +299,7 @@ class ApplyChangeSetUseCaseTest {
assertEquals(1,newDB.schema.constraints?.size)
// checks identity
val serializeNewDb = serializer.prettyDatabase(newDB)
val expectedDb ="""<database name="" id="" source="">
val expectedDb ="""<database name="" id="" source="" vocabulary="">
<schema name="" id="">
<tables>
<table name="person" id="t1" view="" condition="">
......
......@@ -37,7 +37,7 @@ class JacksonTest {
val result = writer.writeValueAsString(db).trimEnd()
// then
assertEquals("""
<database name="" id="" source="">
<database name="" id="" source="" vocabulary="">
<schema name="" id="">
<tables/>
<constraints/>
......@@ -52,7 +52,7 @@ class JacksonTest {
fun test_deserialize_db() {
// given
val dbxml = """
<database name="" id="" source="">
<database name="" id="" source="" vocabulary="">
<schema name="" id="">
<tables/>
<constraints/>
......@@ -73,7 +73,7 @@ class JacksonTest {
// then
assertEquals(0,newdb.schema.tables().size)
assertEquals("""
<database name="" id="" source="">
<database name="" id="" source="" vocabulary="">
<schema name="" id="">
<tables/>
<constraints/>
......
......@@ -62,7 +62,7 @@ class XMLSerializerDatabaseTest {
val serializedDatabase = serializer.prettyDatabase(database).ok
// then
assertEquals("""
<database name="dbname" id="iddb" source="">
<database name="dbname" id="iddb" source="" vocabulary="">
<schema name="" id="idschema">
<tables>
<table name="" id="" view="" condition="">
......
......@@ -29,6 +29,7 @@ class XStreamTest {
</schema>
<mappings/>
<source></source>
<vocabulary></vocabulary>
</database>
""".trimIndent(),dbxml)
}
......
......@@ -27,12 +27,8 @@ class YAMLSerializerDatabaseTest {
objectMapper.writeValue(outWriter,database)
assertEquals("""
---
gid: null
name: "dbname"
id: "iddb"
author: null
time: null
parent: null
schema:
name: ""
id: "idschema"
......@@ -62,6 +58,7 @@ class YAMLSerializerDatabaseTest {
constraints: []
mappings: []
source: ""
vocabulary: ""
""".trimIndent(),outWriter.toString())
}
......
<database name="dbname" id="iddb" source="">
<database name="dbname" id="iddb" source="" vocabulary="">
<schema name="" id="idschema">
<tables>
<table name="" id="" condition="" view="">
......
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