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 {
...
@@ -37,34 +37,50 @@ object Main {
for
(
v
<-
Files
.
walk
(
Paths
.
get
(
args
(
0
))).
toArray
;
f
=
v
.
asInstanceOf
[
Path
];
if
!
Files
.
isDirectory
(
f
))
{
for
(
v
<-
Files
.
walk
(
Paths
.
get
(
args
(
0
))).
toArray
;
f
=
v
.
asInstanceOf
[
Path
];
if
!
Files
.
isDirectory
(
f
))
{
val
fSourceName
=
f
.
getFileName
.
toString
val
fSourceName
=
f
.
getFileName
.
toString
val
fOutputName
=
s
"Converted_$fSourceName"
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
now
=
LocalDateTime
.
now
().
toString
val
sourceXmlValid
=
if
(
template
.
isStraight
)
nsdXmlValid
else
rtsXmlValid
Try
{
val
outputXmlValid
=
if
(
template
.
isStraight
)
rtsXmlValid
else
nsdXmlValid
val
sourceXml
=
XML
.
loadFile
(
f
.
toString
)
val
msgCheckSource
=
Try
{
val
template
=
Template
(
sourceXml
)
sourceXmlValid
.
loadString
(
sourceXml
.
mkString
)
val
outputXml
=
XML
.
loadString
(
p
.
format
(
template
.
render
))
}
match
{
case
Success
(
_
)
=>
s
"'$fSourceName' successfully checked against schema"
case
Failure
(
ex
)
=>
s
"'$fSourceName' isn`t wellformed or invalid: ${ex.getMessage}"
}
val
msgCheckOutput
=
Try
{
val
sourceXmlValid
=
if
(
template
.
isStraight
)
nsdXmlValid
else
rtsXmlValid
outputXmlValid
.
loadString
(
outputXml
.
mkString
)
val
outputXmlValid
=
if
(
template
.
isStraight
)
rtsXmlValid
else
nsdXmlValid
}
match
{
case
Success
(
_
)
=>
s
"'$fOutputName' successfully checked against schema"
val
msgCheckSource
=
Try
{
case
Failure
(
ex
)
=>
s
"'$fOutputName' isn`t wellformed or invalid: ${ex.getMessage}"
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 {
...
@@ -72,13 +72,13 @@ trait Logger {
case
(
t
,
v
,
m
)
if
v
!=
null
||
(
m
!=
null
&&
m
.
nonEmpty
)
=>
true
case
(
t
,
v
,
m
)
if
v
!=
null
||
(
m
!=
null
&&
m
.
nonEmpty
)
=>
true
case
_
=>
false
case
_
=>
false
}
}
.
map
{
.
map
{
case
(
t
,
v
,
m
)
=>
s
"tag: $t, value: ${if (v != null) v else ""}"
+
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
{
(
if
(
m
!=
null
&&
m
.
nonEmpty
)
", "
+
m
.
toVector
.
map
{
case
(
k
,
v1
)
=>
v1
}.
map
{
case
(
k1
,
v2
)
=>
s
"attr: $k1, value: $v2"
case
(
k1
,
v2
)
=>
s
"attr: $k1, value: $v2"
}.
mkString
(
", "
)
else
""
)
}.
mkString
(
", "
)
else
""
)
}
}
.
mkString
(
"\n"
)
.
mkString
(
"\n"
)
s
"$msg\nNot used:\n$additionalInfo"
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