Commit 696decf7 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Make step name configurable and update to new naming convention

parent a5fd3aa9
......@@ -19,4 +19,5 @@ data:
TABLE_IDENTIFIER_INDEX: "{{ .Values.tableIdentifierIndex }}"
CLIENT_ID: "text-file-validation-{{ .Values.sessionId }}"
TOPIC_OUT: "{{.Values.topicName }}"
TOPIC_REPORTING: "{{ .Values.reportingTopicName }}"
\ No newline at end of file
TOPIC_REPORTING: "{{ .Values.reportingTopicName }}"
REPORTING_STEP_NAME: "{{ .Values.reportingStepName }}"
\ No newline at end of file
......@@ -22,6 +22,9 @@ recordSetId: placeholder
isPublished: false
drupalJobUuid: placeholder
drupalJobLogResultUuid: placeholder
reportingStepName: 01-text-file-validation
env: placeholder
# Step 2
......
......@@ -23,7 +23,7 @@ import org.apache.logging.log4j.LogManager
class App {
companion object {
private val log = LogManager.getLogger("TextFileValidationApp")
private val log = LogManager.getLogger(this::class.java)
@JvmStatic fun main(args: Array<String>) {
try {
val service = Service()
......@@ -31,7 +31,7 @@ class App {
exitProcess(0)
} catch (ex: Exception) {
ex.printStackTrace()
log.error("Stopping application due to error: " + ex.message)
log.error("Unexpected Exception Thrown (shutting down service): " + ex.message)
exitProcess(1)
}
}
......
......@@ -18,20 +18,20 @@
package org.memobase
import ch.memobase.reporting.Report
import ch.memobase.reporting.ReportStatus
import com.github.doyaaaaaken.kotlincsv.dsl.csvReader
import com.github.doyaaaaaken.kotlincsv.util.MalformedCSVException
import org.apache.logging.log4j.LogManager
import org.apache.poi.ss.usermodel.WorkbookFactory
import org.xml.sax.SAXException
import java.io.File
import java.io.IOException
import java.io.InputStream
import javax.xml.parsers.DocumentBuilderFactory
import org.apache.logging.log4j.LogManager
import org.apache.poi.ss.usermodel.WorkbookFactory
import org.xml.sax.SAXException
import ch.memobase.reporting.Report
import ch.memobase.reporting.ReportStatus
class FileValidation {
private val log = LogManager.getLogger("TextFileValidationService")
class FileValidation(private val step: String) {
private val log = LogManager.getLogger(this::class.java)
private val supportedExtensions = mapOf(
Pair(Extensions.csv, Formats.csv),
......@@ -64,7 +64,7 @@ class FileValidation {
id = file.name,
status = ReportStatus.fatal,
message = ReportMessages.formatError(file.path, format, ex.localizedMessage),
step = Service.step
step = step
)
)
}
......@@ -74,7 +74,7 @@ class FileValidation {
id = file.name,
status = ReportStatus.success,
message = ReportMessages.validatedFile(file.path, format),
step = Service.step
step = step
)
)
}
......@@ -90,7 +90,7 @@ class FileValidation {
id = file.name,
status = ReportStatus.fatal,
message = ReportMessages.formatError(file.path, format, ex.localizedMessage),
step = Service.step
step = step
)
)
}
......@@ -100,7 +100,7 @@ class FileValidation {
id = file.name,
status = ReportStatus.success,
message = ReportMessages.validatedFile(file.path, format),
step = Service.step
step = step
)
)
}
......@@ -116,7 +116,7 @@ class FileValidation {
id = file.name,
status = ReportStatus.success,
message = ReportMessages.validatedFile(file.path, format),
step = Service.step
step = step
)
)
} catch (ex: SAXException) {
......@@ -126,7 +126,7 @@ class FileValidation {
id = file.name,
status = ReportStatus.fatal,
message = ReportMessages.formatError(file.path, format, ex.localizedMessage),
step = Service.step
step = step
)
)
} catch (ex: IOException) {
......@@ -136,7 +136,7 @@ class FileValidation {
id = file.name,
status = ReportStatus.fatal,
message = ReportMessages.formatError(file.path, format, ex.localizedMessage),
step = Service.step
step = step
)
)
}
......@@ -148,7 +148,7 @@ class FileValidation {
id = file.name,
status = ReportStatus.fatal,
message = ReportMessages.invalidFileExtension(file.name),
step = Service.step
step = step
)
)
}
......
......@@ -32,25 +32,39 @@ class Service(fileName: String = "app.yml") {
private val log: Logger = LogManager.getLogger("TextFileValidationService")
companion object {
const val step = "text-file-validation"
const val envPropName = "env"
const val sessionIdPropName = "sessionId"
const val recordSetIdPropName = "recordSetId"
const val institutionIdPropName = "institutionId"
const val isPublishedPropName = "isPublished"
const val xmlRecordTagPropName = "xmlRecordTag"
const val xmlIdentifierFieldNamePropName = "xmlIdentifierFieldName"
const val tableSheetIndexPropName = "tableSheetIndex"
const val tableHeaderCountPropName = "tableHeaderCount"
const val tableHeaderIndexPropName = "tableHeaderIndex"
const val tableIdentifierIndexPropName = "tableIdentifierIndex"
const val drupalJobUuidPropName = "drupalJobUuid"
const val drupalJobLogResultUuidPropName = "drupalJobLogResultUuid"
const val reportingStepNamePropName = "reportingStepName"
}
val settings =
SettingsLoader(
listOf(
"env",
"sessionId",
"recordSetId",
"institutionId",
"isPublished",
"xmlRecordTag",
"xmlIdentifierFieldName",
"tableSheetIndex",
"tableHeaderCount",
"tableHeaderIndex",
"tableIdentifierIndex",
"drupalJobUuid",
"drupalJobLogResultUuid"
envPropName,
sessionIdPropName,
recordSetIdPropName,
institutionIdPropName,
isPublishedPropName,
xmlRecordTagPropName,
xmlIdentifierFieldNamePropName,
tableSheetIndexPropName,
tableHeaderCountPropName,
tableHeaderIndexPropName,
tableIdentifierIndexPropName,
drupalJobUuidPropName,
drupalJobLogResultUuidPropName,
reportingStepNamePropName
),
fileName,
useProducerConfig = true,
......@@ -63,17 +77,19 @@ class Service(fileName: String = "app.yml") {
settings.outputTopic,
settings.processReportTopic
)
private val recordSetId = settings.appSettings.getProperty("recordSetId")
private val recordSetId = settings.appSettings.getProperty(recordSetIdPropName)
private val basePath = run {
val env = settings.appSettings.getProperty("env")
val env = settings.appSettings.getProperty(envPropName)
if (env == "prod") {
recordSetId
} else {
"$env/$recordSetId"
}
}
private val sessionId = settings.appSettings.getProperty("sessionId")
private val validator = FileValidation()
private val step = settings.appSettings.getProperty(reportingStepNamePropName)
private val sessionId = settings.appSettings.getProperty(sessionIdPropName)
private val validator = FileValidation(step)
private val sftpClient = SftpClient(settings.sftpSettings)
......
......@@ -17,6 +17,7 @@ app:
tableIdentifierIndex: ${TABLE_IDENTIFIER_INDEX:?env}
drupalJobUuid: ${DRUPAL_JOB_UUID:?env}
drupalJobLogResultUuid: ${DRUPAL_JOB_UUID_LOG_RESULT_UUID:?env}
reportingStepName: ${REPORTING_STEP_NAME:?env}
kafka:
producer:
bootstrap.servers: ${KAFKA_BOOTSTRAP_SERVERS:?env}
......
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