Commit a489d3b7 by Amelin Konstantin

remove output split, change sorting input - zip lastmodified

parent 6e748efd
...@@ -33,12 +33,12 @@ object Main { ...@@ -33,12 +33,12 @@ object Main {
var logString = "" var logString = ""
val paths = Files.list(Paths.get(args(0))) val paths = Files.list(Paths.get(args(0)))
.filter {
p => !Files.isDirectory(p)
}
.iterator .iterator
.asScala .asScala
.toStream .toStream
.filter {
p => !Files.isDirectory(p)
}
val start = LocalDateTime.now.toString.replace(":", ".") val start = LocalDateTime.now.toString.replace(":", ".")
...@@ -48,22 +48,14 @@ object Main { ...@@ -48,22 +48,14 @@ object Main {
val sourceNameNotValidated = s"${args(0)}/${start}_not_validated" val sourceNameNotValidated = s"${args(0)}/${start}_not_validated"
val sourceNotValidated = Try { Files.createDirectory(Paths.get(sourceNameNotValidated)) } val sourceNotValidated = Try { Files.createDirectory(Paths.get(sourceNameNotValidated)) }
val sourceNameError = s"${args(0)}/${start}_error" val sourceNameError = s"${args(0)}/error_$start"
val sourceError = Try { Files.createDirectory(Paths.get(sourceNameError)) } val sourceError = Try { Files.createDirectory(Paths.get(sourceNameError)) }
val outputNameValidated = s"${args(1)}/${start}_validated"
val outputValidated = Try { Files.createDirectory(Paths.get(outputNameValidated)) }
val outputNameNotValidated = s"${args(1)}/${start}_not_validated"
val outputNotValidated = Try { Files.createDirectory(Paths.get(outputNameNotValidated)) }
val createDirRes = for { val createDirRes = for {
sv <- sourceValidated sv <- sourceValidated
snv <- sourceNotValidated snv <- sourceNotValidated
se <- sourceError se <- sourceError
ov <- outputValidated } yield se
onv <- outputNotValidated
} yield onv
createDirRes match { createDirRes match {
case Success(_) => case Success(_) =>
...@@ -88,7 +80,7 @@ object Main { ...@@ -88,7 +80,7 @@ object Main {
FileEntry( FileEntry(
s"${name}_${e.getName}", s"${name}_${e.getName}",
//e.getName, //e.getName,
e.getLastModifiedTime, Files.getLastModifiedTime(p),
Some(zip.getInputStream(e)), Some(zip.getInputStream(e)),
zip.getInputStream(e), zip.getInputStream(e),
Some(zip), Some(zip),
...@@ -143,23 +135,18 @@ object Main { ...@@ -143,23 +135,18 @@ object Main {
rtsXmlValid, rtsXmlValid,
p) p)
} match { } match {
case Success((oXml, ti)) if ti.contains("isn`t wellformed or invalid") =>
XML.save(
Paths.get(outputNameNotValidated, s"converted_${f.name}").toString,
oXml,
xmlDecl = true
)
logString += s"'$now'\n$ti"
Files.copy(f.streamMove, Paths.get(sourceNameNotValidated, f.name))
case Success((oXml, ti)) => case Success((oXml, ti)) =>
XML.save( XML.save(
Paths.get(outputNameValidated, s"converted_${f.name}").toString, Paths.get(args(1), s"converted_${f.name}").toString,
oXml, oXml,
xmlDecl = true xmlDecl = true
) )
logString += s"'$now'\n$ti" logString += s"'$now'\n$ti"
Files.copy(f.streamMove, Paths.get(sourceNameValidated, f.name))
if (ti.contains("isn`t wellformed or invalid"))
Files.copy(f.streamMove, Paths.get(sourceNameNotValidated, f.name))
else
Files.copy(f.streamMove, Paths.get(sourceNameValidated, f.name))
case Failure(ex) => case Failure(ex) =>
logString += s"'$now'\nImpossible to convert '${f.name}': ${ex.toString}\n\n" logString += s"'$now'\nImpossible to convert '${f.name}': ${ex.toString}\n\n"
...@@ -199,8 +186,6 @@ object Main { ...@@ -199,8 +186,6 @@ object Main {
if (Files.list(sourceNotValidated.get).toArray.isEmpty) Files.delete(sourceNotValidated.get) if (Files.list(sourceNotValidated.get).toArray.isEmpty) Files.delete(sourceNotValidated.get)
if (Files.list(sourceError.get).toArray.isEmpty) Files.delete(sourceError.get) if (Files.list(sourceError.get).toArray.isEmpty) Files.delete(sourceError.get)
if (Files.list(outputValidated.get).toArray.isEmpty) Files.delete(outputValidated.get)
if (Files.list(outputNotValidated.get).toArray.isEmpty) Files.delete(outputNotValidated.get)
} match { } match {
case Success(_) => println(s"Converting has been finished. $logFileName located in ${args(0)}") case Success(_) => println(s"Converting has been finished. $logFileName located in ${args(0)}")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment