Due to a scheduled upgrade to version 14.10, GitLab will be unavailabe on Monday 30.05., from 19:00 until 20:00.

Unverified Commit ba08b4f2 authored by Sebastian Schüpbach's avatar Sebastian Schüpbach
Browse files

provide exacter warnings


Signed-off-by: Sebastian Schüpbach's avatarSebastian Schüpbach <sebastian.schuepbach@unibas.ch>
parent 98e136b9
Pipeline #17878 passed with stages
in 4 minutes and 53 seconds
......@@ -46,7 +46,7 @@ object App
case Success(rep) => Some(rep)
case Failure(ex) =>
logger.warn(s"Ignoring message because parsing failed: ${ex.getMessage}")
logger.info(s"$record")
logger.info(s"${record.value()}")
None
}
}
......
/*
* Import Process Delete
* Copyright (C) 2020 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 ch.memobase.models
import java.io.IOException
class ParserException(message: String) extends IOException(message)
......@@ -39,16 +39,20 @@ object Report {
private val dateFormatter = new SimpleDateFormat("YYYY-MM-dd'T'HH:mm:ss.SSS")
def apply(consumerRecord: ConsumerRecord[String, String]): Try[Report] = Try {
val json = ujson.read(consumerRecord.value())
val id = json.obj("id").str
val step = json.obj("step").str
val timestamp = dateFormatter.parse(json.obj("timestamp").str)
val status = json.obj("status").str
val message = json.obj("message").str
val json = Try(ujson.read(consumerRecord.value())).getOrElse(throw new ParserException("JSON is not valid!"))
val id = Try(json.obj("id").str).getOrElse(throw new ParserException("No `id` field in JSON obj"))
val step = Try(json.obj("step").str).getOrElse(throw new ParserException("No `step` field in JSON obj"))
val timestampString = Try(json.obj("timestamp").str).getOrElse(throw new ParserException("No `timestamp` field in JSON obj"))
val timestamp = Try(dateFormatter.parse(timestampString)).getOrElse(throw new ParserException("No valid timestamp"))
val status = Try(json.obj("status").str).getOrElse(throw new ParserException("No `status` field in JSON obj"))
val message = Try(json.obj("message").str).getOrElse(throw new ParserException("No `message` field in JSON obj"))
val headers = consumerRecord.headers()
val recordSet = new String(headers.lastHeader("recordSetId").value())
val institution = new String(headers.lastHeader("institutionId").value())
val session = new String(headers.lastHeader("sessionId").value())
val recordSet = Try(new String(headers.lastHeader("recordSetId").value()))
.getOrElse(throw new ParserException("Extraction of `recordSetId` header field failed"))
val institution = Try(new String(headers.lastHeader("institutionId").value()))
.getOrElse(throw new ParserException("Extraction of `institutionId` header field failed"))
val session = Try(new String(headers.lastHeader("sessionId").value()))
.getOrElse(throw new ParserException("Extraction of `sessionId` header field failed"))
Report(consumerRecord.key, id, step, timestamp, status, message, recordSet, institution, session)
}
}
......
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