Commit 030264f1 authored by npedot's avatar npedot
Browse files

adds working dir with timestamp with db cs trace files

parent 28be7895
......@@ -95,9 +95,9 @@ a xml transfomer descriptor
### to fix
* xml with constraint and empty columns (as primary keys).
* use case API transform/scenario , must output database, input database to let iterate.
* PROBLEM: xpath uses doc database file as source, must use string not file OR write database to file as output.
* film_id doppio nella tabella film_core.
* redirect FOREIGN_KEY from splitted table.
* remove select PRIMARY KEY not by name, but by source table.
### to do
......
......@@ -5,6 +5,7 @@ import unibz.cs.semint.kprime.usecase.TransformerUseCase
class TransformationStrategyYesAdapter : TransformationStrategy {
override fun choose(transformersApplicable: List<TransformerUseCase>): List<TransformerUseCase> {
if (transformersApplicable.size==0) return emptyList()
return listOf(transformersApplicable.first())
}
}
\ No newline at end of file
......@@ -84,6 +84,7 @@ class Schema () {
fun addFunctionals(tableName:String, setExpression: String): Schema {
val constraintsToAdd = Constraint.set(setExpression)
for (constraint in constraintsToAdd) {
constraint.name=tableName+".functional"
constraint.type=Constraint.TYPE.FUNCTIONAL.name
constraint.source.table=tableName
constraint.target.table=tableName
......
package unibz.cs.semint.kprime.usecase
import unibz.cs.semint.kprime.domain.Applicability
import unibz.cs.semint.kprime.domain.Transformation
import unibz.cs.semint.kprime.domain.TransformationStrategy
import unibz.cs.semint.kprime.domain.ddl.Database
import unibz.cs.semint.kprime.domain.dml.ChangeSet
import java.util.*
import java.io.File
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import kotlin.collections.ArrayList
import kotlin.collections.mapOf
class OptimusUseCase(transformationStrategy: TransformationStrategy) {
......@@ -20,22 +20,33 @@ class OptimusUseCase(transformationStrategy: TransformationStrategy) {
return this
}
fun transfom(db: Database, params: Map<String, Any>):List<Transformation> {
fun transfom(database: Database, params: Map<String, Any>):List<Transformation> {
var newdb = database
if (transfomers.size==0) {
return listOf(errorTransformation(db, "Required at least one transformer. Use addTrasnsformers()."))
return listOf(errorTransformation(database, "Required at least one transformer. Use addTrasnsformers()."))
}
var totalTransformationPath = mutableListOf<Transformation>()
var tryMoreSteps = true
var maxSteps = 10
var steps = 0
var steps = 1
while(tryMoreSteps && steps < maxSteps) {
println("========================================================= $steps =========================")
val transformersApplicable = transfomers
.filter { t -> t.decomposeApplicable(db, transformationStrategy).ok }
.filter { t -> t.decomposeApplicable(newdb, transformationStrategy).ok }
println("transformersApplicable : $transformersApplicable ")
val transfomersChoosed: List<TransformerUseCase> = transformationStrategy.choose(transformersApplicable)
println("transfomersChoosed : $transfomersChoosed ")
val transformationPath = transfomersChoosed
.map { t -> t.decompose(db, params) }.toList()
.map { t -> t.decompose(newdb, params) }.toList()
if (transformationPath.size > 0)
newdb = transformationPath.last().newdb
println("transformationPath : $transformationPath ")
totalTransformationPath.addAll(transformationPath)
tryMoreSteps = false
......@@ -44,6 +55,7 @@ class OptimusUseCase(transformationStrategy: TransformationStrategy) {
}
steps++
}
println("========================================================= END =========================")
return totalTransformationPath
}
......
......@@ -44,7 +44,7 @@ class MetaSchemaReadUseCase() {
if (tokens.size==3)
table = tokens[2]
db = metaSchemaRepository.metaDatabase(datasource)
print(xmlSerializer.prettyDatabase(db))
//print(xmlSerializer.prettyDatabase(db))
}
return UseCaseResult("${name()} done.", db)
}
......
......@@ -51,7 +51,7 @@ class XPathTransformUseCase {
val newdb = ApplyChangeSetUseCase(serializer).apply(db, changeSet);
println("-----------------------NEW-DB---------------")
println(serializer.prettyDatabase(newdb))
//println(serializer.prettyDatabase(newdb))
return newdb
}
......
......@@ -9,7 +9,10 @@ import unibz.cs.semint.kprime.usecase.TransformerUseCase
import unibz.cs.semint.kprime.usecase.common.XPathTransformUseCase
import unibz.cs.semint.kprime.usecase.service.FileIOService
import unibz.cs.semint.kprime.usecase.service.IXMLSerializerService
import java.io.File
import java.io.StringWriter
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
class TransformerVUseCase(serializer: IXMLSerializerService, fileIOAdapter: FileIOService) : TransformerUseCase {
val serializer = serializer
......@@ -17,20 +20,41 @@ class TransformerVUseCase(serializer: IXMLSerializerService, fileIOAdapter: File
override fun decompose(db: Database, params:Map<String,Any>): Transformation {
val tranformerParmeters = mutableMapOf<String,Any>()
tranformerParmeters.putAll(params)
if (tranformerParmeters["originTable"]==null) return errorTransformation(db,"ERROR: TransformerVUseCase originTable null")
if (tranformerParmeters["targetTable1"]==null) return errorTransformation(db,"ERROR: TransformerVUseCase targetTable1 null")
if (tranformerParmeters["targetTable2"]==null) return errorTransformation(db,"ERROR: TransformerVUseCase targetTable2 null")
val functionals = db.schema.functionals()
if (functionals.size==0) return errorTransformation(db,"ERROR: TransformerVUseCase no functionals")
val tableToSplit = functionals.first().source.table
tranformerParmeters["originTable"] = tableToSplit
tranformerParmeters["targetTable1"] = tableToSplit +"_1"
tranformerParmeters["targetTable2"] = tableToSplit +"_2"
if (params["workingDir"]==null) return errorTransformation(db,"ERROR: TransformerVUseCase workingDir null")
val workingDir = params["workingDir"] as String
val changeSet = XPathTransformUseCase().compute(fileIOAdapter.writeOnWorkingFilePath(serializer.prettyDatabase(db), workingDir+"db.xml"),
val timestamp = LocalDateTime.now()
val dbFilePath = fileIOAdapter.writeOnWorkingFilePath(serializer.prettyDatabase(db), workingDir + "db_worked.xml")
println("Updated db file db_worked.xml")
val changeSet = XPathTransformUseCase().compute(dbFilePath,
"vertical",
"decompose",
"1",
tranformerParmeters,
StringWriter())
return Transformation(changeSet, ApplyChangeSetUseCase(serializer).apply(db,changeSet), "TransformerVUseCase.decompose")
if (changeSet.size()!=0) {
val csFileName = workingDir + "cs_${timestamp.format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss_nnnnnnnnnn"))}.xml"
println("Written cs file $tableToSplit : $csFileName ")
fileIOAdapter.writeOnWorkingFilePath(serializer.prettyChangeSet(changeSet), csFileName)
}
val newdb = ApplyChangeSetUseCase(serializer).apply(db, changeSet)
val newDbFileName = workingDir + "db_${timestamp.format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss_nnnnnnnnnn"))}.xml"
fileIOAdapter.writeOnWorkingFilePath(serializer.prettyDatabase(newdb), newDbFileName)
println("Written db files $tableToSplit : $newDbFileName")
return Transformation(changeSet, newdb, "TransformerVUseCase.decompose ($tableToSplit)")
}
override fun compose(db: Database, params: Map<String,Any>): Transformation {
......@@ -48,8 +72,9 @@ class TransformerVUseCase(serializer: IXMLSerializerService, fileIOAdapter: File
// then extract targetTable2 transformationStrategy.askParameter
// then extract workingDir fileIOAdapter
// then extract workingFileName
val applicability = db.schema.functionals().size > 0
val tranformerParmeters = mutableMapOf<String,Any>()
return Applicability(true,"TransformerVUseCase.decomposeApplicable", tranformerParmeters)
return Applicability(applicability,"TransformerVUseCase.decomposeApplicable", tranformerParmeters)
}
override fun composeApplicable(db: Database, transformationStrategy: TransformationStrategy): Applicability {
......
......@@ -12,6 +12,9 @@ import unibz.cs.semint.kprime.scenario.sakila.readMeta
import unibz.cs.semint.kprime.scenario.sakila.sakilaDataSource
import unibz.cs.semint.kprime.usecase.current.TransformerHUseCase
import unibz.cs.semint.kprime.usecase.current.TransformerVUseCase
import java.io.File
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
/**
* Applies Optimus to local Sakila Postgres Example.
......@@ -42,16 +45,25 @@ class OptimusUseCaseTI {
database.schema
.addFunctionals("film","film_id --> replacement_cost, rental_duration, rental_rate")
database.schema
.addFunctionals("address", "address_id --> address2")
val rootWorkingDir = "/home/nipe/Temp/"
val timestampSuffix = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss_nnnnnnnnnn"))
val workingDir = rootWorkingDir + timestampSuffix + "/"
File(workingDir).mkdirs()
val params = mapOf(
"workingDir" to "/home/nipe/Temp/",
"originTable" to "film",
"targetTable1" to "film_core",
"targetTable2" to "film_rental"
"workingDir" to workingDir
)
// when
val serializerService = XMLSerializerJacksonAdapter()
val fileIOService = FileIOAdapter()
fileIOService.writeOnWorkingFilePath(serializerService.prettyDatabase(database), workingDir + "db_original.xml")
// when
val transformationPath = OptimusUseCase(
TransformationStrategyYesAdapter()
).addTrasnsformers(listOf(
......
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