Skip to content
Snippets Groups Projects
Commit 73e1b183 authored by npedot's avatar npedot
Browse files

fixes for template map parameters presentation and removes println compute template

parent a758bb62
No related branches found
No related tags found
No related merge requests found
...@@ -9,9 +9,7 @@ import unibz.cs.semint.kprime.domain.ddl.Database ...@@ -9,9 +9,7 @@ import unibz.cs.semint.kprime.domain.ddl.Database
import unibz.cs.semint.kprime.domain.dml.ChangeSet import unibz.cs.semint.kprime.domain.dml.ChangeSet
import unibz.cs.semint.kprime.usecase.service.FileIOService import unibz.cs.semint.kprime.usecase.service.FileIOService
import java.io.File import java.io.File
import java.io.InputStream
import java.io.StringWriter import java.io.StringWriter
import java.util.*
import javax.xml.parsers.DocumentBuilderFactory import javax.xml.parsers.DocumentBuilderFactory
import javax.xml.xpath.XPathConstants import javax.xml.xpath.XPathConstants
import javax.xml.xpath.XPathFactory import javax.xml.xpath.XPathFactory
...@@ -70,7 +68,8 @@ class XPathTransformUseCase { ...@@ -70,7 +68,8 @@ class XPathTransformUseCase {
private fun parametrized(line: String, tranformerParmeters: MutableMap<String, Any>): String { private fun parametrized(line: String, tranformerParmeters: MutableMap<String, Any>): String {
var newline = line var newline = line
for (key in tranformerParmeters.keys) { for (key in tranformerParmeters.keys) {
newline = newline.replace("%%${key}%%", tranformerParmeters[key] as String) val newValue = (tranformerParmeters[key] as List<String>).get(0)
newline = newline.replace("%%${key}%%", newValue)
} }
return newline return newline
} }
...@@ -82,24 +81,24 @@ class XPathTransformUseCase { ...@@ -82,24 +81,24 @@ class XPathTransformUseCase {
val splittedRule = derivationRule.split(" ") val splittedRule = derivationRule.split(" ")
if (splittedRule[0]=="+") { if (splittedRule[0]=="+") {
val sourceLists = splittedRule.drop(1) val sourceLists = splittedRule.drop(1)
println("sourceLists:"+sourceLists) //println("sourceLists:"+sourceLists)
derivedList.addAll(templModel[sourceLists[0]] as List<String>) derivedList.addAll(templModel[sourceLists[0]] as List<String>)
for (i in 1..(sourceLists.size-1)) { for (i in 1..(sourceLists.size-1)) {
if (!templModel[sourceLists[i]]!!.isEmpty()) if (!templModel[sourceLists[i]]!!.isEmpty())
derivedList = derivedList.plus(templModel[sourceLists[i]] as MutableList<String>) as MutableList<String> derivedList = derivedList.plus(templModel[sourceLists[i]] as MutableList<String>) as MutableList<String>
} }
println(derivedList) //println(derivedList)
} }
if (splittedRule[0]=="-") { if (splittedRule[0]=="-") {
//println(splittedRule) //println(splittedRule)
val sourceLists = splittedRule.drop(1) val sourceLists = splittedRule.drop(1)
println("sourceLists:"+sourceLists) //println("sourceLists:"+sourceLists)
derivedList.addAll(templModel[sourceLists[0]] as List<String>) derivedList.addAll(templModel[sourceLists[0]] as List<String>)
for (i in 1..(sourceLists.size-1)) { for (i in 1..(sourceLists.size-1)) {
if (!templModel[sourceLists[i]]!!.isEmpty()) if (!templModel[sourceLists[i]]!!.isEmpty())
derivedList = derivedList.minus(templModel[sourceLists[i]] as MutableList<String>) as MutableList<String> derivedList = derivedList.minus(templModel[sourceLists[i]] as MutableList<String>) as MutableList<String>
} }
println(" $derivedList") //println(" $derivedList")
} }
// if derivationRule starts with - then compute intersection // if derivationRule starts with - then compute intersection
return derivedList.toSet().toList() return derivedList.toSet().toList()
...@@ -167,37 +166,37 @@ class XPathTransformUseCase { ...@@ -167,37 +166,37 @@ class XPathTransformUseCase {
return changeSet return changeSet
} }
fun getTemplateModel(dbFilePath: String, xPaths: List<String>, tranformerParmeters: MutableMap<String, Any>): Pair<MutableMap<String, List<String>>, String> { fun getTemplateModel(dbFilePath: String, xPaths: List<String>, tranformerParameters: MutableMap<String, Any>): Pair<MutableMap<String, List<String>>, String> {
val templModel = mutableMapOf<String, List<String>>() val templModel = mutableMapOf<String, List<String>>()
// compute xpath lists // compute xpath lists
//val dbInputStream: InputStream = FileIOService.inputStreamFromPath(dbFilePath) //val dbInputStream: InputStream = FileIOService.inputStreamFromPath(dbFilePath)
val docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder() val docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder()
println("dbFilePath: ${dbFilePath}") //println("dbFilePath: ${dbFilePath}")
val doc = docBuilder.parse(File(dbFilePath)) val doc = docBuilder.parse(File(dbFilePath))
val xpath = XPathFactory.newInstance().newXPath() val xpath = XPathFactory.newInstance().newXPath()
var violation = "" var violation = ""
for (xPathLine in xPaths) { for (xPathLine in xPaths) {
println("------------------------------------------") //println("------------------------------------------")
val xPathTokens = xPathLine.split("==") val xPathTokens = xPathLine.split("==")
val name = xPathTokens[0] val name = xPathTokens[0]
println("name=|${name}|") //println("name=|${name}|")
val rule = xPathTokens[1] val rule = xPathTokens[1]
println("rule=|${rule}|") //println("rule=|${rule}|")
val pathTokens = rule.split(" ") val pathTokens = rule.split(" ")
val value = parametrized(pathTokens[0], tranformerParmeters) val value = parametrized(pathTokens[0], tranformerParameters)
println("value=|${value}|") //println("value=|${value}|")
if (value.startsWith("-") || value.startsWith("+")) { if (value.startsWith("-") || value.startsWith("+")) {
templModel[name] = computeDerivedList(templModel, rule) templModel[name] = computeDerivedList(templModel, rule)
} }
else { else {
templModel[name] = asValueList(xpath.compile(value).evaluate(doc, XPathConstants.NODESET) as NodeList) templModel[name] = asValueList(xpath.compile(value).evaluate(doc, XPathConstants.NODESET) as NodeList)
println(" ${name} = ${value}") //println(" ${name} = ${value}")
println(" ${name} = ${templModel[name]}") //println(" ${name} = ${templModel[name]}")
if (!templModel[name]!!.isEmpty()) if (!templModel[name]!!.isEmpty())
tranformerParmeters[name] = templModel[name]!![0] tranformerParameters[name] = templModel[name]!!
if (pathTokens.size == 3) { if (pathTokens.size == 3) {
println(pathTokens) //println(pathTokens)
val pathCondition = pathTokens[1] val pathCondition = pathTokens[1]
val pathSize = pathTokens[2].toInt() val pathSize = pathTokens[2].toInt()
if (pathCondition == ">") if (pathCondition == ">")
...@@ -208,7 +207,7 @@ class XPathTransformUseCase { ...@@ -208,7 +207,7 @@ class XPathTransformUseCase {
} }
} }
// adds all input parameters as template parameters // adds all input parameters as template parameters
for (parCouple in tranformerParmeters) { for (parCouple in tranformerParameters) {
templModel.put(parCouple.key, listOf(parCouple.value.toString())) templModel.put(parCouple.key, listOf(parCouple.value.toString()))
} }
return Pair(templModel, violation) return Pair(templModel, violation)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment