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
1755b013
Commit
1755b013
authored
Jul 06, 2019
by
Amelin Konstantin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add source moving logic.
parent
5745ddcd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
93 additions
and
58 deletions
+93
-58
src/main/scala/Main.scala
+93
-58
No files found.
src/main/scala/Main.scala
View file @
1755b013
...
...
@@ -2,7 +2,7 @@ import com.typesafe.config.{Config, ConfigFactory}
import
scala.xml._
import
java.nio.file.
{
Files
,
Path
,
Paths
,
StandardOpenOption
}
import
java.io.
{
FileInputStream
,
InputStream
}
import
java.io.
{
File
,
File
InputStream
,
InputStream
}
import
java.util.zip.ZipFile
import
java.time.LocalDateTime
...
...
@@ -30,69 +30,104 @@ object Main {
val
rtsXmlValid
=
XMLValid
(
getClass
.
getResource
(
"/rts/fpml-recordkeeping-merged-schema.xsd"
))
var
logString
=
""
for
(
v
<-
Files
.
walk
(
Paths
.
get
(
args
(
0
))).
toArray
;
f
=
v
.
asInstanceOf
[
Path
];
if
!
Files
.
isDirectory
(
f
))
{
val
fSourceName
=
f
.
getFileName
.
toString
val
fSourceNameArray
=
fSourceName
.
split
(
'.'
)
val
fSourceNameBase
=
fSourceNameArray
.
head
val
fSourceNameExtension
=
fSourceNameArray
.
last
.
toLowerCase
val
now
=
LocalDateTime
.
now
().
toString
if
(
fSourceNameExtension
==
"zip"
)
Try
{
val
fZip
=
new
ZipFile
(
f
.
toFile
)
val
fZipEntries
=
fZip
.
entries
while
(
fZipEntries
.
hasMoreElements
)
{
val
e
=
fZipEntries
.
nextElement
if
(!
e
.
isDirectory
)
{
val
fZipEntryName
=
e
.
getName
val
nowForZip
=
LocalDateTime
.
now
().
toString
Try
{
convert
(
fZip
.
getInputStream
(
e
),
s
"${fSourceNameBase}_$fZipEntryName"
,
s
"Converted_${fSourceNameBase}_$fZipEntryName"
,
nsdXmlValid
,
rtsXmlValid
,
p
)
}
match
{
case
Success
((
oXml
,
ti
))
=>
XML
.
save
(
Paths
.
get
(
args
(
1
),
s
"Converted_${fSourceNameBase}_$fZipEntryName"
).
toString
,
oXml
,
xmlDecl
=
true
)
logString
+=
s
"$nowForZip\n$ti"
case
Failure
(
ex
)
=>
logString
+=
s
"'$nowForZip\nImpossible to convert '${fSourceNameBase}_$fZipEntryName': ${ex.getMessage}\n\n"
val
files
=
new
File
(
args
(
0
))
.
listFiles
.
filter
{
!
_
.
isDirectory
}
.
sortBy
{
_
.
lastModified
}
val
start
=
LocalDateTime
.
now
().
toString
val
successSourcesName
=
s
"./${start}_success"
val
successSources
=
new
File
(
successSourcesName
)
val
errorSourcesName
=
s
"./${start}_error"
val
errorSources
=
new
File
(
errorSourcesName
)
if
(
successSources
.
mkdir
()
&&
errorSources
.
mkdir
())
{
for
(
f
<-
files
)
{
val
fSourceName
=
f
.
getName
val
fSourceNameArray
=
fSourceName
.
split
(
'.'
)
val
fSourceNameBase
=
fSourceNameArray
.
head
val
fSourceNameExtension
=
fSourceNameArray
.
last
.
toLowerCase
val
now
=
LocalDateTime
.
now
().
toString
if
(
fSourceNameExtension
==
"zip"
)
Try
{
val
fZip
=
new
ZipFile
(
f
)
val
fZipEntries
=
fZip
.
entries
while
(
fZipEntries
.
hasMoreElements
)
{
val
e
=
fZipEntries
.
nextElement
if
(!
e
.
isDirectory
)
{
val
fZipEntryName
=
e
.
getName
val
nowForZip
=
LocalDateTime
.
now
().
toString
Try
{
convert
(
fZip
.
getInputStream
(
e
),
s
"${fSourceName}_$fZipEntryName"
,
s
"Converted_${fSourceName}_$fZipEntryName"
,
nsdXmlValid
,
rtsXmlValid
,
p
)
}
match
{
case
Success
((
oXml
,
ti
))
=>
XML
.
save
(
Paths
.
get
(
args
(
1
),
s
"Converted_${fSourceName}_$fZipEntryName"
).
toString
,
oXml
,
xmlDecl
=
true
)
logString
+=
s
"$nowForZip\n$ti"
Files
.
copy
(
fZip
.
getInputStream
(
e
),
Paths
.
get
(
successSourcesName
,
s
"${fSourceName}_$fZipEntryName"
))
case
Failure
(
ex
)
=>
logString
+=
s
"'$nowForZip\nImpossible to convert '${fSourceName}_$fZipEntryName': ${ex.getMessage}\n\n"
Files
.
copy
(
fZip
.
getInputStream
(
e
),
Paths
.
get
(
errorSourcesName
,
s
"${fSourceName}_$fZipEntryName"
))
}
}
}
}
match
{
case
Success
(
_
)
=>
case
Failure
(
ex
)
=>
logString
+=
s
"'$now\nImpossible to convert '$fSourceName': ${ex.getMessage}\n\n"
}
}
match
{
case
Success
(
_
)
=>
case
Failure
(
ex
)
=>
logString
+=
s
"'$now\nImpossible to convert '$fSourceName': ${ex.getMessage}\n\n"
}
else
Try
{
convert
(
new
FileInputStream
(
f
.
toFile
),
s
"$fSourceNameBase"
,
s
"Converted_$fSourceName"
,
nsdXmlValid
,
rtsXmlValid
,
p
)
}
match
{
case
Success
((
oXml
,
ti
))
=>
else
Try
{
convert
(
new
FileInputStream
(
f
),
s
"$fSourceNameBase"
,
s
"Converted_$fSourceName"
,
nsdXmlValid
,
rtsXmlValid
,
p
)
}
match
{
case
Success
((
oXml
,
ti
))
=>
XML
.
save
(
Paths
.
get
(
args
(
1
),
s
"Converted_$fSourceName"
).
toString
,
oXml
,
xmlDecl
=
true
)
logString
+=
s
"$now\n$ti"
case
Failure
(
ex
)
=>
logString
+=
s
"'$now\nImpossible to convert '$fSourceName': ${ex.getMessage}\n\n"
Files
.
copy
(
f
.
toPath
,
Paths
.
get
(
successSourcesName
,
f
.
getName
))
case
Failure
(
ex
)
=>
logString
+=
s
"'$now\nImpossible to convert '$fSourceName': ${ex.getMessage}\n\n"
Files
.
copy
(
f
.
toPath
,
Paths
.
get
(
errorSourcesName
,
f
.
getName
))
}
}
Try
{
//files.foreach { _.delete }
Files
.
write
(
Paths
.
get
(
args
(
0
),
logFileName
),
logString
.
getBytes
(
"utf-8"
),
StandardOpenOption
.
CREATE
,
StandardOpenOption
.
TRUNCATE_EXISTING
)
if
(
successSources
.
listFiles
.
nonEmpty
)
Files
.
copy
(
Paths
.
get
(
args
(
0
),
logFileName
),
Paths
.
get
(
successSourcesName
,
logFileName
))
else
successSources
.
delete
if
(
errorSources
.
listFiles
.
isEmpty
)
errorSources
.
delete
}
match
{
case
Success
(
_
)
=>
println
(
s
"Converting has been finished. $logFileName located in ${args(0)}"
)
case
Failure
(
ex
)
=>
println
(
s
"Error. Converting hasn`t been finished: ${ex.getMessage}"
)
}
}
Try
{
Files
.
write
(
Paths
.
get
(
args
(
1
),
logFileName
),
logString
.
getBytes
(
"utf-8"
),
StandardOpenOption
.
CREATE
,
StandardOpenOption
.
TRUNCATE_EXISTING
)
}
match
{
case
Success
(
_
)
=>
println
(
s
"Converting has been finished. $logFileName located in ${args(1)}"
)
case
Failure
(
ex
)
=>
println
(
s
"Error. Converting hasn`t been finished: ${ex.getMessage}"
)
}
}
else
println
(
s
"Error. Converting hasn`t been finished: unable to create source moving directory."
)
}
}
...
...
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