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

adds compose x transformer use case

parent 393ac216
No related branches found
No related tags found
No related merge requests found
...@@ -45,13 +45,9 @@ class TransformerXUseCase( ...@@ -45,13 +45,9 @@ class TransformerXUseCase(
override fun decompose(db: Database, params: Map<String, Any>): Transformation { override fun decompose(db: Database, params: Map<String, Any>): Transformation {
// lateinit var traceDir :String // val functionals = db.schema.functionals()
// if (traceName.endsWith("/")) traceDir = traceName // if (functionals.isEmpty()) return errorTransformation(db,
// else traceDir = traceName + "/" // "ERROR: TransformerXUseCase no functionals")
val functionals = db.schema.functionals()
if (functionals.isEmpty()) return errorTransformation(db,
"ERROR: TransformerXUseCase no functionals")
val dbFilePath = fileIOAdapter.writeOnWorkingFilePath( val dbFilePath = fileIOAdapter.writeOnWorkingFilePath(
...@@ -81,7 +77,30 @@ class TransformerXUseCase( ...@@ -81,7 +77,30 @@ class TransformerXUseCase(
} }
override fun compose(db: Database, params: Map<String, Any>): Transformation { override fun compose(db: Database, params: Map<String, Any>): Transformation {
TODO("Not yet implemented") val dbFilePath = fileIOAdapter.writeOnWorkingFilePath(
serializer.prettyDatabase(db), workingDir + "db_worked.xml")
println("Updated db file db_worked.xml")
val xPaths = File(coXPathsFilePath).readLines()
val tranformerParmeters = mutableMapOf<String,Any>()
tranformerParmeters.putAll(params)
val changeSet = xpathTransform.compute(
dbFilePath, coTemplateFilePath,
xPaths, tranformerParmeters)
println("Computed changeSet : $changeSet")
val changeSetFileName = "${LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss_nnnnnnnnnn"))}_cs.xml"
changeSet.id=changeSetFileName
val changeSetFilePath = workingDir + changeSetFileName
fileIOAdapter.writeOnWorkingFilePath(serializer.prettyChangeSet(changeSet), changeSetFilePath)
val newdb = ApplyChangeSetUseCase(serializer).apply(db, changeSet)
val dbFileName = "${LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss_nnnnnnnnnn"))}_db.xml"
newdb.name=dbFileName
val newDbFilePath = workingDir + dbFileName
fileIOAdapter.writeOnWorkingFilePath(serializer.prettyDatabase(newdb), newDbFilePath)
println("Written new db file : $newDbFilePath")
return Transformation(changeSet, newdb, "TransformerXUseCase.decomposed ")
} }
override fun decomposeApplicable(db: Database, transformationStrategy: TransformationStrategy): Applicability { override fun decomposeApplicable(db: Database, transformationStrategy: TransformationStrategy): Applicability {
...@@ -90,13 +109,6 @@ class TransformerXUseCase( ...@@ -90,13 +109,6 @@ class TransformerXUseCase(
val xPathProperties = File(decoXPathsFilePath).readLines() val xPathProperties = File(decoXPathsFilePath).readLines()
if (db.name.isEmpty()) return Applicability(false,"db name empty", transformerParams) if (db.name.isEmpty()) return Applicability(false,"db name empty", transformerParams)
// lateinit var traceDir :String
// if (traceName.endsWith("/")) traceDir = traceName
// else traceDir = traceName + "/"
//println("decomposeApplicable workingDir:"+workingDir)
// println("traceDir:"+traceDir)
//println("decomposeApplicable db name:"+db.name)
val dbFilePath = workingDir + db.name val dbFilePath = workingDir + db.name
if (!File(dbFilePath).isFile) return Applicability(false,"db name ${dbFilePath} not exists", transformerParams) if (!File(dbFilePath).isFile) return Applicability(false,"db name ${dbFilePath} not exists", transformerParams)
...@@ -120,6 +132,30 @@ class TransformerXUseCase( ...@@ -120,6 +132,30 @@ class TransformerXUseCase(
} }
override fun composeApplicable(db: Database, transformationStrategy: TransformationStrategy): Applicability { override fun composeApplicable(db: Database, transformationStrategy: TransformationStrategy): Applicability {
return Applicability(false,"composeApplicable", mutableMapOf()) val transformerParams = mutableMapOf<String,Any>()
val xPathProperties = File(coXPathsFilePath).readLines()
if (db.name.isEmpty()) return Applicability(false,"db name empty", transformerParams)
val dbFilePath = workingDir + db.name
if (!File(dbFilePath).isFile) return Applicability(false,"db name ${dbFilePath} not exists", transformerParams)
//println("composeApplicable 1:")
var message = ""
var applicable = false
var mutableMap = mutableMapOf<String,Any>()
try {
//println("composeApplicable 2:")
val (templateMap, violation) = xpathTransform.getTemplateModel(dbFilePath, xPathProperties, transformerParams)
if (templateMap.keys.isEmpty()) return Applicability(false,"Empty rules.", mutableMap)
//println("composeApplicable 3:")
applicable = violation.isEmpty()
message = "composeApplicable ${violation.isEmpty()} ${violation}"
mutableMap = templateMap as MutableMap<String, Any>
} catch (e:Exception) {
message = e.message.toString()
e.printStackTrace()
}
return Applicability(applicable, message, mutableMap)
} }
} }
\ No newline at end of file
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