Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SPB_Exchange_Repo
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Amelin Konstantin
SPB_Exchange_Repo
Commits
38c07285
Commit
38c07285
authored
Oct 26, 2018
by
Amelin Konstantin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add exception handler to Main.
parent
c617955d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
27 deletions
+43
-27
src/main/scala/Main.scala
+36
-20
src/main/scala/templates/Logger.scala
+7
-7
No files found.
src/main/scala/Main.scala
View file @
38c07285
...
...
@@ -37,34 +37,50 @@ object Main {
for
(
v
<-
Files
.
walk
(
Paths
.
get
(
args
(
0
))).
toArray
;
f
=
v
.
asInstanceOf
[
Path
];
if
!
Files
.
isDirectory
(
f
))
{
val
fSourceName
=
f
.
getFileName
.
toString
val
fOutputName
=
s
"Converted_$fSourceName"
val
sourceXml
=
XML
.
loadFile
(
f
.
toString
)
val
template
=
Template
(
sourceXml
)
val
outputXml
=
XML
.
loadString
(
p
.
format
(
template
.
render
))
val
now
=
LocalDateTime
.
now
().
toString
val
sourceXmlValid
=
if
(
template
.
isStraight
)
nsdXmlValid
else
rtsXmlValid
val
outputXmlValid
=
if
(
template
.
isStraight
)
rtsXmlValid
else
nsdXmlValid
Try
{
val
sourceXml
=
XML
.
loadFile
(
f
.
toString
)
val
msgCheckSource
=
Try
{
sourceXmlValid
.
loadString
(
sourceXml
.
mkString
)
}
match
{
case
Success
(
_
)
=>
s
"'$fSourceName' successfully checked against schema"
case
Failure
(
ex
)
=>
s
"'$fSourceName' isn`t wellformed or invalid: ${ex.getMessage}"
}
val
template
=
Template
(
sourceXml
)
val
outputXml
=
XML
.
loadString
(
p
.
format
(
template
.
render
))
val
msgCheckOutput
=
Try
{
outputXmlValid
.
loadString
(
outputXml
.
mkString
)
}
match
{
case
Success
(
_
)
=>
s
"'$fOutputName' successfully checked against schema"
case
Failure
(
ex
)
=>
s
"'$fOutputName' isn`t wellformed or invalid: ${ex.getMessage}"
}
val
sourceXmlValid
=
if
(
template
.
isStraight
)
nsdXmlValid
else
rtsXmlValid
val
outputXmlValid
=
if
(
template
.
isStraight
)
rtsXmlValid
else
nsdXmlValid
val
msgCheckSource
=
Try
{
sourceXmlValid
.
loadString
(
sourceXml
.
mkString
)
}
match
{
case
Success
(
_
)
=>
s
"'$fSourceName' successfully checked against schema"
case
Failure
(
ex
)
=>
s
"'$fSourceName' isn`t wellformed or invalid: ${ex.getMessage}"
}
XML
.
save
(
Paths
.
get
(
args
(
1
),
fOutputName
).
toString
,
outputXml
,
xmlDecl
=
true
)
val
msgCheckOutput
=
Try
{
outputXmlValid
.
loadString
(
outputXml
.
mkString
)
}
match
{
case
Success
(
_
)
=>
s
"'$fOutputName' successfully checked against schema"
case
Failure
(
ex
)
=>
s
"'$fOutputName' isn`t wellformed or invalid: ${ex.getMessage}"
}
logString
+=
template
.
info
(
s
"$now\n$msgCheckSource\n$msgCheckOutput"
)
+
"\n\n"
XML
.
save
(
Paths
.
get
(
args
(
1
),
fOutputName
).
toString
,
outputXml
,
xmlDecl
=
true
)
template
.
info
(
s
"$now\n$msgCheckSource\n$msgCheckOutput"
)
+
"\n\n"
}
match
{
case
Success
(
ti
)
=>
logString
+=
ti
case
Failure
(
ex
)
=>
logString
+=
s
"'$now\nImpossible to convert'$fSourceName': ${ex.getMessage}\n\n"
}
}
Files
.
write
(
Paths
.
get
(
args
(
1
),
logFileName
),
logString
.
getBytes
(
"utf-8"
),
StandardOpenOption
.
CREATE
,
StandardOpenOption
.
TRUNCATE_EXISTING
)
Try
{
Files
.
write
(
Paths
.
get
(
args
(
1
),
logFileName
),
logString
.
getBytes
(
"utf-8"
),
StandardOpenOption
.
CREATE
,
StandardOpenOption
.
TRUNCATE_EXISTING
)
}
match
{
case
Success
(
_
)
=>
println
(
s
"Work has finished. $logFileName located in ${args(1)}"
)
case
Failure
(
ex
)
=>
println
(
s
"Error. Work hasn`t finished: ${ex.getMessage}"
)
}
}
}
}
src/main/scala/templates/Logger.scala
View file @
38c07285
...
...
@@ -72,13 +72,13 @@ trait Logger {
case
(
t
,
v
,
m
)
if
v
!=
null
||
(
m
!=
null
&&
m
.
nonEmpty
)
=>
true
case
_
=>
false
}
.
map
{
case
(
t
,
v
,
m
)
=>
s
"tag: $t, value: ${if (v != null) v else ""}"
+
(
if
(
m
!=
null
&&
m
.
nonEmpty
)
", "
+
m
.
toVector
.
map
{
case
(
k
,
v1
)
=>
v1
}.
map
{
case
(
k1
,
v2
)
=>
s
"attr: $k1, value: $v2"
}.
mkString
(
", "
)
else
""
)
}
.
mkString
(
"\n"
)
.
map
{
case
(
t
,
v
,
m
)
=>
s
"tag: $t, value: ${if (v != null) v else ""}"
+
(
if
(
m
!=
null
&&
m
.
nonEmpty
)
", "
+
m
.
toVector
.
map
{
case
(
k
,
v1
)
=>
v1
}.
map
{
case
(
k1
,
v2
)
=>
s
"attr: $k1, value: $v2"
}.
mkString
(
", "
)
else
""
)
}
.
mkString
(
"\n"
)
s
"$msg\nNot used:\n$additionalInfo"
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment