Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Pedot Nicola
semint-kprime
Commits
a1c8e7e6
Commit
a1c8e7e6
authored
Mar 16, 2022
by
npedot
Browse files
adds vocabulary, vocabularies,sources to database entity
parent
d8c2cf12
Changes
9
Hide whitespace changes
Inline
Side-by-side
src/main/kotlin/unibz/cs/semint/kprime/domain/ddl/Database.kt
View file @
a1c8e7e6
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
?
{
...
...
src/test/kotlin/unibz/cs/semint/kprime/adapter/jackson/JacksonOptionalFields.kt
0 → 100644
View file @
a1c8e7e6
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
src/test/kotlin/unibz/cs/semint/kprime/domain/ddl/DatabaseTest.kt
View file @
a1c8e7e6
...
...
@@ -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">
...
...
src/test/kotlin/unibz/cs/semint/kprime/usecase/ApplyChangeSetUseCaseTest.kt
View file @
a1c8e7e6
...
...
@@ -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="">
...
...
src/test/kotlin/unibz/cs/semint/kprime/usecase/serialize/JacksonTest.kt
View file @
a1c8e7e6
...
...
@@ -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/>
...
...
src/test/kotlin/unibz/cs/semint/kprime/usecase/serialize/XMLSerializerDatabaseTest.kt
View file @
a1c8e7e6
...
...
@@ -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="">
...
...
src/test/kotlin/unibz/cs/semint/kprime/usecase/serialize/XStreamTest.kt
View file @
a1c8e7e6
...
...
@@ -29,6 +29,7 @@ class XStreamTest {
</schema>
<mappings/>
<source></source>
<vocabulary></vocabulary>
</database>
"""
.
trimIndent
(),
dbxml
)
}
...
...
src/test/kotlin/unibz/cs/semint/kprime/usecase/serialize/YAMLSerializerDatabaseTest.kt
View file @
a1c8e7e6
...
...
@@ -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
())
}
...
...
src/test/resources/database_with_two_empty_tables.xml
View file @
a1c8e7e6
<database
name=
"dbname"
id=
"iddb"
source=
""
>
<database
name=
"dbname"
id=
"iddb"
source=
""
vocabulary=
""
>
<schema
name=
""
id=
"idschema"
>
<tables>
<table
name=
""
id=
""
condition=
""
view=
""
>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment