Commit 57775301 authored by npedot's avatar npedot
Browse files

adds transformer xml

parent 7fb47621
......@@ -68,26 +68,31 @@ technology depenent packages
* A domain component has to depends on nothing.
## v1.0.0
## v0.1.0
from object database meta representation as input
apply kotlin transformer vertical or horizontal
obtain a second database meta representation as output
## v2.0.0
## v0.2.0
from xml object database meta representation as input
apply kotlin transformer vertical or horizontal
obtain a changeset representation as output
## v3.0.0
## v0.3.0
from xml object database meta representation as input
a generic xpath engine extraction plus freemarker template to generate
obtain a database meta representation as output
## v0.4.0
from xml object database meta representation as input
a xml transfomer descriptor
### to do
* horizontal simple decomposition to remove null columns
......
......@@ -77,4 +77,18 @@ class XMLSerializerJacksonAdapter : IXMLSerializerService {
return writer.writeValueAsString(table)
}
override fun serializeTransfomer(transformer: Transformer): String {
val mapper = XmlMapper().registerModule(KotlinModule())
val writer = mapper.writerWithDefaultPrettyPrinter()
return writer.writeValueAsString(transformer)
}
override fun deserializeTransformer(transformerXml: String): Transformer {
println(transformerXml)
val mapper = XmlMapper()
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
return mapper.readValue(transformerXml,Transformer::class.java)
}
}
\ No newline at end of file
package unibz.cs.semint.kprime.domain
class Composer {
var xman = Xmen()
var template = Template()
}
\ No newline at end of file
package unibz.cs.semint.kprime.domain
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 com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText
import java.util.*
@JacksonXmlRootElement(localName = "splitter")
class Splitter {
var xman = Xmen()
var template = Template()
}
package unibz.cs.semint.kprime.domain
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
import java.util.*
@JacksonXmlRootElement(localName = "template")
class Template {
@JacksonXmlProperty(isAttribute = true)
var filename=""
}
\ No newline at end of file
package unibz.cs.semint.kprime.domain
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
@JacksonXmlRootElement(localName = "transformer")
class Transformer {
@JacksonXmlProperty(isAttribute = true)
var name: String =""
var composer = Composer()
var splitter = Splitter()
}
\ No newline at end of file
package unibz.cs.semint.kprime.domain
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
@JacksonXmlRootElement(localName = "xmen")
class Xmen {
var xrules = ArrayList<Xrule>()
}
\ No newline at end of file
package unibz.cs.semint.kprime.domain
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText
@JacksonXmlRootElement(localName = "xrule")
class Xrule() {
@JacksonXmlProperty(isAttribute = true)
var name = ""
@JacksonXmlText
var rule = ""
}
\ No newline at end of file
......@@ -58,4 +58,14 @@ class XMLSerializeUseCase(val xmlSerializerService: IXMLSerializerService) {
return UseCaseResult("done",xmlSerializerService.prettyChangeSet(changeset))
}
// trasnfomer
fun serializeTransformer(transformer: Transformer): UseCaseResult<String> {
return UseCaseResult("done",xmlSerializerService.serializeTransfomer(transformer))
}
fun deserializeTransformer(transformerXml: String): UseCaseResult<Transformer> {
return UseCaseResult("done",xmlSerializerService.deserializeTransformer(transformerXml))
}
}
\ No newline at end of file
......@@ -13,15 +13,16 @@ import javax.xml.xpath.XPathFactory
class XPathTransformUseCase {
fun transform(dbFilePath: String, trasformerName: String, trasformerDirection: String, trasformerVersion: String, tranformerParmeters: MutableMap<String, Any>) {
fun transform(dbFilePath: String, trasformerName: String, trasformerDirection: String, trasformerVersion: String, tranformerParmeters: MutableMap<String, Any>,outWriter:OutputStreamWriter) {
val vdecomposeFilePath = "/transformer/${trasformerName}/${trasformerDirection}/${trasformerName}_${trasformerDirection}_${trasformerVersion}.paths"
val vdecomposeTemplatePath = "transformer/${trasformerName}/${trasformerDirection}/${trasformerName}_${trasformerDirection}_${trasformerVersion}.template"
val personProperties = XPathTransformUseCase::class.java.getResourceAsStream(vdecomposeFilePath)
val xPaths = Properties()
xPaths.load(personProperties)
return transform(dbFilePath,vdecomposeTemplatePath,xPaths, tranformerParmeters,outWriter)
}
fun transform(dbFilePath: String, templateFilePath: String, xPaths: Properties, tranformerParmeters: MutableMap<String, Any>,outWriter:OutputStreamWriter) {
var dbStream : InputStream
if (dbFilePath.startsWith("/"))
dbStream = FileInputStream(dbFilePath)
......@@ -77,8 +78,8 @@ class XPathTransformUseCase {
// = = 0 xpath
val templ = //Template.getPlainTextTemplate("templ1",personTemplate,templConfig)
templConfig.getTemplate(vdecomposeTemplatePath)
templ.process(templModel, OutputStreamWriter(System.out))
templConfig.getTemplate(templateFilePath)
templ.process(templModel, outWriter)
}
private fun parametrized(line: String, tranformerParmeters: MutableMap<String, Any>): String {
......
package unibz.cs.semint.kprime.usecase.service
import unibz.cs.semint.kprime.domain.ChangeSet
import unibz.cs.semint.kprime.domain.Constraint
import unibz.cs.semint.kprime.domain.Database
import unibz.cs.semint.kprime.domain.Table
import unibz.cs.semint.kprime.domain.*
interface IXMLSerializerService {
fun serializeTable(table: Table): String
......@@ -17,4 +14,6 @@ interface IXMLSerializerService {
fun serializeChangeSet(changeset: ChangeSet): String
fun deserializeChangeSet(changeset: String): ChangeSet
fun prettyChangeSet(table: ChangeSet): String
fun serializeTransfomer(transformer: Transformer): String
fun deserializeTransformer(transformer: String): Transformer
}
\ No newline at end of file
package unibz.cs.semint.kprime.domain
import org.junit.Test
import unibz.cs.semint.kprime.adapter.service.XMLSerializerJacksonAdapter
import unibz.cs.semint.kprime.usecase.XMLSerializeUseCase
class TransfomerTest {
@Test
fun test_empty_trasfomer_xml(){
// given
val transformer = Transformer()
// when
val serializedTransformer = XMLSerializeUseCase(XMLSerializerJacksonAdapter()).serializeTransformer(transformer)
// then
println(serializedTransformer)
}
@Test
fun test_vsplit_trasfomer_xml(){
// given
val transformer = Transformer()
val xrule = Xrule()
xrule.name="all"
xrule.rule="/database/schema/tables/tables[@name='%%table%%']/columns/columns/@name = 4"
transformer.splitter.xman.xrules.add(xrule)
// when
val serializedTransformer = XMLSerializeUseCase(XMLSerializerJacksonAdapter()).serializeTransformer(transformer)
// then
println(serializedTransformer)
}
}
\ No newline at end of file
package unibz.cs.semint.kprime.scenario
import org.junit.Test
import unibz.cs.semint.kprime.adapter.service.XMLSerializerJacksonAdapter
import unibz.cs.semint.kprime.domain.Xrule
import unibz.cs.semint.kprime.usecase.XMLSerializeUseCase
import unibz.cs.semint.kprime.usecase.XPathTransformUseCase
import java.io.OutputStreamWriter
import java.util.*
class PersonTransfomerScenarioTI {
@Test
fun test_xpath_vertical_decomposition_on_person_db() {
// given
val dbFilePath = "db/person.xml"
val transfomerXml = PersonTransfomerScenarioTI::class.java.getResource("/transformer/verticalTransfomer.xml").readText()
val vTransfomer = XMLSerializeUseCase(XMLSerializerJacksonAdapter()).deserializeTransformer(transfomerXml).ok
val templateFilePath = vTransfomer!!.splitter.template.filename
val xrules = toProperties(vTransfomer!!.splitter.xman.xrules)
val tranformerParmeters = mutableMapOf<String,Any>()
tranformerParmeters["table"]="person"
println(templateFilePath)
// when
XPathTransformUseCase().transform(dbFilePath, templateFilePath, xrules,tranformerParmeters, OutputStreamWriter(System.out))
// then
// print to console output
}
private fun toProperties(xrules: ArrayList<Xrule>): Properties {
var pros = Properties()
for (xrule in xrules) {
pros[xrule.name]=xrule.rule
}
return pros
}
@Test
fun test_xpath_horizontal_decomposition_on_person_db() {
/*
// given
val dbFilePath = "db/person.xml"
val trasformerName = "horizontal"
val trasformerDirection = "decompose"
val trasformerVersion = "1"
val tranformerParmeters = mutableMapOf<String,Any>()
tranformerParmeters["table"]="person"
// when
XPathTransformUseCase().transform(dbFilePath, trasformerName, trasformerDirection, trasformerVersion,tranformerParmeters,OutputStreamWriter(System.out))
// then
// print to console output
*/
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package unibz.cs.semint.kprime.scenario
import org.junit.Test
import unibz.cs.semint.kprime.usecase.XPathTransformUseCase
import java.io.OutputStreamWriter
class PersonXPathScenarioTI {
......@@ -15,7 +16,7 @@ class PersonXPathScenarioTI {
val tranformerParmeters = mutableMapOf<String,Any>()
tranformerParmeters["table"]="person"
// when
XPathTransformUseCase().transform(dbFilePath, trasformerName, trasformerDirection, trasformerVersion,tranformerParmeters)
XPathTransformUseCase().transform(dbFilePath, trasformerName, trasformerDirection, trasformerVersion,tranformerParmeters, OutputStreamWriter(System.out))
// then
// print to console output
}
......@@ -30,7 +31,7 @@ class PersonXPathScenarioTI {
val tranformerParmeters = mutableMapOf<String,Any>()
tranformerParmeters["table"]="person"
// when
XPathTransformUseCase().transform(dbFilePath, trasformerName, trasformerDirection, trasformerVersion,tranformerParmeters)
XPathTransformUseCase().transform(dbFilePath, trasformerName, trasformerDirection, trasformerVersion,tranformerParmeters,OutputStreamWriter(System.out))
// then
// print to console output
}
......
<transformer name="">
<composer>
<xman>
<xrules>
<xrules name="all">/database/schema/tables/tables[@name='%%table%%']/columns/columns/@name = 4</xrules>
</xrules>
</xman>
<template filename=""/>
</composer>
<splitter>
<xman>
<xrules>
<xrules name="all">/database/schema/tables/tables[@name='%%table%%']/columns/columns/@name = 4</xrules>
<xrules name="keys">/database/schema/constraints/constraints[@type='PRIMARY_KEY']/source[@table='%%table%%']/columns/columns/@name > 0</xrules>
<xrules name="lhss">/database/schema/constraints/constraints[@type='FUNCTIONAL']/source[@table='%%table%%']/columns/columns/@name</xrules>
<xrules name="rhss">/database/schema/constraints/constraints[@type='FUNCTIONAL']/target[@table='%%table%%']/columns/columns/@name</xrules>
<xrules name="rests">- all keys lhss rhss</xrules>
<xrules name="table">/database/schema/tables/tables[@name='%%table%%']/@name = 1</xrules>
</xrules>
</xman>
<template filename="transformer/vertical/decompose/vertical_decompose_1.template"/>
</splitter>
</transformer>
\ No newline at end of file
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