Commit 023693eb by Amelin Konstantin

Fix exception handling

parent ff5e7399
......@@ -7,7 +7,7 @@
Запуск осуществляется из командной строки с двумя параметрами: путь к директории входящих сообщений, путь к директории сконвертированных сообщений.
Конвертер работает по принципу пакетного обработчика. Действие выполняется над всеми файлами, находящимися в директории входящих сообщений.
Поддерживается формат xml и zip (архив, cодержащий xml файлы).
Лог файл с отчетом о конвертации сохраняется в директории сконвертированных сообщений.
Лог файл с отчетом о конвертации сохраняется в директории входящих сообщений.
Запуск.
......
......@@ -61,7 +61,7 @@ object Main {
val name = f.getName
val ext = name.split('.').last.toLowerCase
if (ext == "zip") {
if (ext == "zip")
Try {
val zip = new ZipFile(f)
......@@ -73,6 +73,7 @@ object Main {
e =>
FileEntry(
s"${name}_${e.getName}",
//e.getName,
e.getLastModifiedTime.toMillis,
Some(zip.getInputStream(e)),
zip.getInputStream(e),
......@@ -82,21 +83,23 @@ object Main {
case Success(v) =>
v
case Failure(ex) =>
Array(FileEntry(name, f.lastModified, None, new FileInputStream(f), Some(ex.getMessage)))
Array(FileEntry(name, f.lastModified, None, new FileInputStream(f), Some(ex.toString)))
}
} else
else
Array(FileEntry(name, f.lastModified, Some(new FileInputStream(f)), new FileInputStream(f), None))
}
}
.flatten
.sortWith { (a, b) => (a.modified == b.modified && a.name <= b.name) || (a.modified < b.modified) }
Try {
for (f <- sourceArray) {
val now = LocalDateTime.now.toString
f.msg match {
case Some(msg) =>
logString += s"$now\nImpossible to convert '${f.name}': $msg\n\n"
logString += s"'$now'\nImpossible to convert '${f.name}': $msg\n\n"
Files.copy(f.streamMove, Paths.get(sourceNameError, f.name))
case None =>
......@@ -115,7 +118,7 @@ object Main {
oXml,
xmlDecl = true
)
logString += s"$now\n$ti"
logString += s"'$now'\n$ti"
Files.copy(f.streamMove, Paths.get(sourceNameNotValidated, f.name))
case Success((oXml, ti)) =>
......@@ -124,17 +127,16 @@ object Main {
oXml,
xmlDecl = true
)
logString += s"$now\n$ti"
logString += s"'$now'\n$ti"
Files.copy(f.streamMove, Paths.get(sourceNameValidated, f.name))
case Failure(ex) =>
logString += s"$now\nImpossible to convert '${f.name}': ${ex.getMessage}\n\n"
logString += s"'$now'\nImpossible to convert '${f.name}': ${ex.toString}\n\n"
Files.copy(f.streamMove, Paths.get(sourceNameError, f.name))
}
}
}
Try {
//files.foreach { _.delete }
Files.write(
......@@ -155,10 +157,11 @@ object Main {
} 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}")
case Failure(ex) => println(s"Error. Converting hasn`t been finished: ${ex.toString}")
}
} else
println(s"Error. Converting hasn`t been finished: unable to create moving directories.")
println(s"Error. Converting hasn`t been finished: unable to create directories to move files.")
}
}
......@@ -215,6 +218,7 @@ object Main {
nsdScheme: XMLValid,
rtsScheme: XMLValid,
pp: PrettyPrinter): (Node, String) = {
val sourceXml = XML.load(inputStream)
val template = Template(sourceXml)
......@@ -231,14 +235,14 @@ object Main {
sourceXmlValid.loadString(sourceXml.mkString)
} match {
case Success(_) => s"'$sName' successfully checked against schema"
case Failure(ex) => s"'$sName' isn`t wellformed or invalid: ${ex.getMessage}"
case Failure(ex) => s"'$sName' isn`t wellformed or invalid: ${ex.toString}"
}
val msgCheckOutput = Try {
outputXmlValid.loadString(outputXml.mkString)
} match {
case Success(_) => s"'$oName' successfully checked against schema"
case Failure(ex) => s"'$oName' isn`t wellformed or invalid: ${ex.getMessage}"
case Failure(ex) => s"'$oName' isn`t wellformed or invalid: ${ex.toString}"
}
(outputXml, template.info(s"$msgCheckSource\n$msgCheckOutput") + "\n\n")
......
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