Commit c384a46b authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Refactor Reporting Messages

Refactor Formats & Extensions object into a separate file each.
parent 0ce0d6c0
/*
* text-file-validation
* Copyright (C) 2020-2021 Memoriav
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.memobase
object Extensions {
const val csv = "csv"
const val tsv = "tsv"
const val xlsx = "xlsx"
const val xls = "xls"
const val xml = "xml"
}
\ No newline at end of file
/*
* text-file-validation
* Copyright (C) 2020-2021 Memoriav
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.memobase
object Formats {
const val csv = "CSV"
const val tsv = "TSV"
const val xlsx = "XLSX"
const val xls = "XLS"
const val xml = "XML"
const val invalid = "INVALID"
const val error = "ERROR"
}
\ No newline at end of file
/*
* text-file-validation
* Copyright (C) 2020 Memoriav
* Copyright (C) 2020-2021 Memoriav
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
......@@ -18,44 +18,26 @@
package org.memobase
object Formats {
const val csv = "CSV"
const val tsv = "TSV"
const val xlsx = "XLSX"
const val xls = "XLS"
const val ods = "ODS"
const val xml = "XML"
const val invalid = "INVALID"
const val error = "ERROR"
}
object Extensions {
const val csv = "csv"
const val tsv = "tsv"
const val xlsx = "xlsx"
const val xls = "xls"
const val ods = "ods"
const val xml = "xml"
}
object ReportMessages {
fun processFailure(failures: Int, total: Int): String {
return "Failed to validate $failures of $total files."
}
fun processSuccess(total: Int): String {
return "Successfully validated $total files."
// SUCCESS
fun validatedFile(path: String, format: String): String {
return "Validated file at path $path with format $format."
}
// FATAL
fun invalidFileExtension(fileName: String): String {
return "File Extension Error: Not a valid file extension: $fileName."
}
fun validatedFile(path: String, format: String): String {
return "Validated file at path $path with format $format."
fun sftpException(message: String): String {
return "SFTP Exception: $message."
}
fun formatError(path: String, format: String, message: String): String {
return "$format ERROR: $message for file $path."
}
fun unknownException(message: String): String {
return "Unknown Exception: $message."
}
}
/*
* text-file-validation
* Copyright (C) 2020 Memoriav
* Copyright (C) 2020-2021 Memoriav
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
......@@ -93,7 +93,7 @@ class Service(fileName: String = "app.yml") {
val report = Report(
"$recordSetId#$sessionId",
status = ReportStatus.fatal,
message = "SFTP Exception: ${ex.localizedMessage}",
message = ReportMessages.sftpException(ex.localizedMessage),
step = step
)
producer.sendReport(report)
......@@ -117,11 +117,11 @@ class Service(fileName: String = "app.yml") {
reportCount += 1
}
} catch (ex: SftpClientException) {
log.error("SFTP Exception: ${ex.localizedMessage}")
log.error(ReportMessages.sftpException(ex.localizedMessage))
val report = Report(
file.name,
status = ReportStatus.fatal,
message = "SFTP Exception: ${ex.localizedMessage}.",
message = ReportMessages.sftpException(ex.localizedMessage),
step = step
)
producer.sendReport(report)
......@@ -137,7 +137,7 @@ class Service(fileName: String = "app.yml") {
Report(
"$recordSetId#$sessionId",
status = ReportStatus.fatal,
message = "SFTP Exception: ${ex.localizedMessage}.",
message = ReportMessages.sftpException(ex.localizedMessage),
step = step
)
)
......@@ -149,7 +149,7 @@ class Service(fileName: String = "app.yml") {
Report(
"$recordSetId#$sessionId",
status = ReportStatus.fatal,
message = "Unknown Exception: ${ex.localizedMessage}.",
message = ReportMessages.unknownException(ex.localizedMessage),
step = step
)
)
......
Supports Markdown
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