Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
semint-kprime-arm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pedot Nicola
semint-kprime-arm
Commits
73e1b183
Commit
73e1b183
authored
4 years ago
by
npedot
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/kotlin/unibz.cs.semint.kprime/usecase/common/XPathTransformUseCase.kt
+18
-19
18 additions, 19 deletions
....cs.semint.kprime/usecase/common/XPathTransformUseCase.kt
with
18 additions
and
19 deletions
src/main/kotlin/unibz.cs.semint.kprime/usecase/common/XPathTransformUseCase.kt
+
18
−
19
View file @
73e1b183
...
@@ -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
>,
tranformerPar
a
meters
:
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
],
tranformerPar
a
meters
)
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
]
tranformerPar
a
meters
[
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
tranformerPar
a
meters
)
{
templModel
.
put
(
parCouple
.
key
,
listOf
(
parCouple
.
value
.
toString
()))
templModel
.
put
(
parCouple
.
key
,
listOf
(
parCouple
.
value
.
toString
()))
}
}
return
Pair
(
templModel
,
violation
)
return
Pair
(
templModel
,
violation
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment