Skip to content

Commit

Permalink
renaming from messages to issues
Browse files Browse the repository at this point in the history
  • Loading branch information
benediktschwab committed Dec 22, 2023
1 parent 87bfe22 commit d30fdc1
Show file tree
Hide file tree
Showing 57 changed files with 780 additions and 780 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,42 @@
* limitations under the License.
*/

package io.rtron.io.messages
package io.rtron.io.issues

class ContextMessageList<out V>(
class ContextIssueList<out V>(
val value: V,
val messageList: DefaultMessageList
val issueList: DefaultIssueList
) {
// Properties and Initializers

// Methods
fun appendReport(other: DefaultMessageList): ContextMessageList<V> {
this.messageList += other
fun appendReport(other: DefaultIssueList): ContextIssueList<V> {
this.issueList += other
return this
}

fun handleMessageList(f: (DefaultMessageList) -> Unit): V {
f(messageList)
fun handleIssueList(f: (DefaultIssueList) -> Unit): V {
f(issueList)
return value
}

fun <R> map(transform: (V) -> R): ContextMessageList<R> = ContextMessageList(transform(value), messageList)
fun <R> map(transform: (V) -> R): ContextIssueList<R> = ContextIssueList(transform(value), issueList)
}

fun <V : Any> List<ContextMessageList<V>>.mergeMessageLists(): ContextMessageList<List<V>> {
val mergedMessageList = DefaultMessageList()
this.forEach { mergedMessageList += it.messageList }
return ContextMessageList(this.map { it.value }, mergedMessageList)
fun <V : Any> List<ContextIssueList<V>>.mergeIssueLists(): ContextIssueList<List<V>> {
val mergedIssueList = DefaultIssueList()
this.forEach { mergedIssueList += it.issueList }
return ContextIssueList(this.map { it.value }, mergedIssueList)
}

/**
* Handles a list of reports with [block] and then returns only the list of [ContextMessageList.value].
* Handles a list of reports with [block] and then returns only the list of [ContextIssueList.value].
*
* @receiver list of [ContextMessageList] to be handled
* @receiver list of [ContextIssueList] to be handled
* @param block the actual handler for the report message
* @return remaining list of [ContextMessageList.value]
* @return remaining list of [ContextIssueList.value]
*/
inline fun <V : Any> List<ContextMessageList<V>>.handleMessageList(block: (ContextMessageList<V>) -> Unit): List<V> =
inline fun <V : Any> List<ContextIssueList<V>>.handleIssueList(block: (ContextIssueList<V>) -> Unit): List<V> =
map {
block(it)
it.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* limitations under the License.
*/

package io.rtron.io.messages
package io.rtron.io.issues

import kotlinx.serialization.Serializable

/**
* Single message.
* Single issue.
*/
@Serializable
data class DefaultMessage(
data class DefaultIssue(
val type: String,
val info: String,
val location: String,
Expand All @@ -32,7 +32,7 @@ data class DefaultMessage(
) {

// Properties and Initializers
val messageSeverity: Severity = when (Pair(incidentSeverity, wasFixed)) {
val issueSeverity: Severity = when (Pair(incidentSeverity, wasFixed)) {
Pair(Severity.FATAL_ERROR, true) -> Severity.ERROR
Pair(Severity.ERROR, true) -> Severity.WARNING
else -> incidentSeverity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@
* limitations under the License.
*/

package io.rtron.io.messages
package io.rtron.io.issues

typealias DefaultMessageList = MessageList<DefaultMessage>
typealias DefaultIssueList = IssueList<DefaultIssue>

/**
* Returns the number of entries with a certain [severity].
*/
fun DefaultMessageList.getNumberOfMessages(severity: Severity) = getMessages().filter { it.messageSeverity == severity }.size
fun DefaultIssueList.getNumberOfIssues(severity: Severity) = getIssues().count { it.issueSeverity == severity }

/**
* Returns true, if list contains messages with fatal error severity.
* Returns true, if list contains issues with fatal error severity.
*/
fun DefaultMessageList.containsFatalErrors() = getMessages().any { it.messageSeverity == Severity.FATAL_ERROR }
fun DefaultIssueList.containsFatalErrors() = getIssues().any { it.issueSeverity == Severity.FATAL_ERROR }

/**
* Returns a summary of the message numbers depending on the severity.
* Returns a summary of the issue numbers depending on the severity.
*/
fun DefaultMessageList.getTextSummary(): String {
val numberOfWarnings = getNumberOfMessages(severity = Severity.WARNING)
val numberOfErrors = getNumberOfMessages(severity = Severity.ERROR)
val numberOfFatalErrors = getNumberOfMessages(severity = Severity.FATAL_ERROR)
fun DefaultIssueList.getTextSummary(): String {
val numberOfWarnings = getNumberOfIssues(severity = Severity.WARNING)
val numberOfErrors = getNumberOfIssues(severity = Severity.ERROR)
val numberOfFatalErrors = getNumberOfIssues(severity = Severity.FATAL_ERROR)

return "$numberOfWarnings warnings, $numberOfErrors errors, $numberOfFatalErrors fatal errors"
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,42 @@
* limitations under the License.
*/

package io.rtron.io.messages
package io.rtron.io.issues

import kotlinx.serialization.Serializable

@Serializable
@JvmInline
value class MessageList<T>(private val messages: MutableList<T> = mutableListOf()) {
value class IssueList<T>(private val issues: MutableList<T> = mutableListOf()) {

// Properties
val size: Int
get() = messages.size
get() = issues.size

// Operators
operator fun plusAssign(other: MessageList<T>) {
append(other.messages)
operator fun plusAssign(other: IssueList<T>) {
append(other.issues)
}

operator fun plusAssign(other: T) {
append(other)
}

// Methods
fun getMessages(): List<T> = messages
fun getIssues(): List<T> = issues

fun isEmpty(): Boolean = messages.isEmpty()
fun isNotEmpty(): Boolean = messages.isNotEmpty()
fun isEmpty(): Boolean = issues.isEmpty()
fun isNotEmpty(): Boolean = issues.isNotEmpty()

fun append(message: T) { this.messages += message }
fun append(messages: List<T>) { this.messages += messages }
fun append(issues: T) { this.issues += issues }
fun append(issues: List<T>) { this.issues += issues }

companion object {

fun <T> of(messages: List<T>): MessageList<T> = MessageList(messages as MutableList<T>)
fun <T> of(message: T): MessageList<T> = MessageList(mutableListOf(message))
fun <T> of(issues: List<T>): IssueList<T> = IssueList(issues as MutableList<T>)
fun <T> of(issue: T): IssueList<T> = IssueList(mutableListOf(issue))
}
}

fun <T> List<T>.mergeToReport(): MessageList<T> = MessageList.of(this)
fun <T> List<MessageList<T>>.merge(): MessageList<T> = MessageList.of(flatMap { it.getMessages() })
fun <T> List<T>.mergeToReport(): IssueList<T> = IssueList.of(this)
fun <T> List<IssueList<T>>.merge(): IssueList<T> = IssueList.of(flatMap { it.getIssues() })
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.rtron.io.messages
package io.rtron.io.issues

import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ data class OpendriveToCitygmlParameters(
) {
// Methods
fun isValid(): Either<List<String>, Unit> {
val messages = mutableListOf<String>()
val issues = mutableListOf<String>()
if (cropPolygonX.size != cropPolygonY.size) {
messages += "cropPolygonX must have the same number of values as cropPolygonY"
issues += "cropPolygonX must have the same number of values as cropPolygonY"
}
if (cropPolygonX.isNotEmpty() && cropPolygonX.size < 3) {
messages += "cropPolygonX must be empty or have at least three values for representing a triangle"
issues += "cropPolygonX must be empty or have at least three values for representing a triangle"
}
if (cropPolygonY.isNotEmpty() && cropPolygonY.size < 3) {
messages += "cropPolygonX must be empty or have at least three values for representing a triangle"
issues += "cropPolygonX must be empty or have at least three values for representing a triangle"
}

return if (messages.isEmpty()) {
return if (issues.isEmpty()) {
Unit.right()
} else {
messages.left()
issues.left()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package io.rtron.main.processor

import arrow.core.getOrElse
import com.charleskorn.kaml.Yaml
import io.rtron.io.messages.getTextSummary
import io.rtron.io.issues.getTextSummary
import io.rtron.io.serialization.serializeToJsonFile
import io.rtron.main.project.processAllFiles
import io.rtron.readerwriter.citygml.CitygmlWriter
Expand Down Expand Up @@ -56,8 +56,8 @@ class OpendriveToCitygmlProcessor(
val outputSubDirectoryPath = outputDirectoryPath / "citygml_${parameters.getCitygmlWriteVersion()}"
outputSubDirectoryPath.createDirectories()
// check if parameters are valid
parameters.isValid().onLeft { messages ->
messages.forEach { logger.warn("Parameters are not valid: $it") }
parameters.isValid().onLeft { issues ->
issues.forEach { logger.warn("Parameters are not valid: $it") }
return@processAllFiles
}
// write the parameters as yaml file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package io.rtron.main.processor

import arrow.core.getOrElse
import com.charleskorn.kaml.Yaml
import io.rtron.io.messages.getTextSummary
import io.rtron.io.issues.getTextSummary
import io.rtron.io.serialization.serializeToJsonFile
import io.rtron.main.project.processAllFiles
import io.rtron.readerwriter.citygml.CitygmlVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import arrow.core.getOrElse
import arrow.core.left
import arrow.core.raise.either
import io.rtron.io.files.inputStreamFromDirectOrCompressedFile
import io.rtron.io.messages.MessageList
import io.rtron.io.issues.IssueList
import io.rtron.readerwriter.opendrive.reader.OpendriveUnmarshaller
import io.rtron.readerwriter.opendrive.report.SchemaValidationIssue
import io.rtron.readerwriter.opendrive.report.SchemaValidationReport
import io.rtron.readerwriter.opendrive.report.SchemaValidationReportMessage
import io.rtron.readerwriter.opendrive.version.OpendriveVersion
import io.rtron.readerwriter.opendrive.version.OpendriveVersionUtils
import mu.KotlinLogging
Expand All @@ -47,21 +47,21 @@ object OpendriveValidator {
}

fun validateFromStream(opendriveVersion: OpendriveVersion, inputStream: InputStream): Either<OpendriveReaderException, SchemaValidationReport> = either {
val messageList = runValidation(opendriveVersion, inputStream)
val issueList = runValidation(opendriveVersion, inputStream)
.getOrElse {
logger.warn("Schema validation was aborted due the following error: ${it.message}")
return@either SchemaValidationReport(opendriveVersion, completedSuccessfully = false, validationAbortMessage = it.message)
return@either SchemaValidationReport(opendriveVersion, completedSuccessfully = false, validationAbortIssue = it.message)
}
if (!messageList.isEmpty()) {
logger.warn("Schema validation for OpenDRIVE $opendriveVersion found ${messageList.size} incidents.")
if (!issueList.isEmpty()) {
logger.warn("Schema validation for OpenDRIVE $opendriveVersion found ${issueList.size} incidents.")
} else {
logger.info("Schema validation report for OpenDRIVE $opendriveVersion: Everything ok.")
}

SchemaValidationReport(opendriveVersion, messageList)
SchemaValidationReport(opendriveVersion, issueList)
}

private fun runValidation(opendriveVersion: OpendriveVersion, inputStream: InputStream): Either<OpendriveReaderException, MessageList<SchemaValidationReportMessage>> =
private fun runValidation(opendriveVersion: OpendriveVersion, inputStream: InputStream): Either<OpendriveReaderException, IssueList<SchemaValidationIssue>> =
either {
val unmarshaller = OpendriveUnmarshaller.of(opendriveVersion).bind()

Expand All @@ -76,7 +76,7 @@ object OpendriveValidator {
.bind<OpendriveReaderException.FatalSchemaValidationError>()
}

val messageList = unmarshaller.validationEventHandler.toMessageList()
messageList
val issueList = unmarshaller.validationEventHandler.toIssueList()
issueList
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package io.rtron.readerwriter.opendrive.reader.validation

import io.rtron.io.messages.MessageList
import io.rtron.readerwriter.opendrive.report.SchemaValidationReportMessage
import io.rtron.readerwriter.opendrive.report.toMessage
import io.rtron.io.issues.IssueList
import io.rtron.readerwriter.opendrive.report.SchemaValidationIssue
import io.rtron.readerwriter.opendrive.report.toIssue
import jakarta.xml.bind.ValidationEvent
import jakarta.xml.bind.ValidationEventHandler

Expand All @@ -38,8 +38,8 @@ class OpendriveValidationEventHandler : ValidationEventHandler {
}

// Conversions
fun toMessageList(): MessageList<SchemaValidationReportMessage> {
val messages = this.validationEvents.map { it.toMessage() }
return MessageList.of(messages)
fun toIssueList(): IssueList<SchemaValidationIssue> {
val issues = this.validationEvents.map { it.toIssue() }
return IssueList.of(issues)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package io.rtron.readerwriter.opendrive.report

import io.rtron.io.messages.Severity
import io.rtron.io.issues.Severity
import jakarta.xml.bind.ValidationEvent

fun ValidationEvent.toMessage(): SchemaValidationReportMessage {
fun ValidationEvent.toIssue(): SchemaValidationIssue {
val text = this.message ?: ""
val severity = when (this.severity) {
ValidationEvent.WARNING -> Severity.WARNING
Expand All @@ -31,5 +31,5 @@ fun ValidationEvent.toMessage(): SchemaValidationReportMessage {
val lineNumber = this.locator.lineNumber
val columnNumber = this.locator.columnNumber

return SchemaValidationReportMessage(text, severity, lineNumber, columnNumber)
return SchemaValidationIssue(text, severity, lineNumber, columnNumber)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package io.rtron.readerwriter.opendrive.report

import io.rtron.io.messages.Severity
import io.rtron.io.issues.Severity
import kotlinx.serialization.Serializable

@Serializable
data class SchemaValidationReportMessage(
data class SchemaValidationIssue(
val description: String,
val severity: Severity,
val lineNumber: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@

package io.rtron.readerwriter.opendrive.report

import io.rtron.io.messages.MessageList
import io.rtron.io.messages.Severity
import io.rtron.io.issues.IssueList
import io.rtron.io.issues.Severity
import io.rtron.readerwriter.opendrive.version.OpendriveVersion
import kotlinx.serialization.Serializable

@Serializable
class SchemaValidationReport(
val opendriveVersion: OpendriveVersion,

val validationMessages: MessageList<SchemaValidationReportMessage> = MessageList(),
val validationIssues: IssueList<SchemaValidationIssue> = IssueList(),

val completedSuccessfully: Boolean = true,
val validationAbortMessage: String = ""
val validationAbortIssue: String = ""
) {

fun validationProcessAborted() = !completedSuccessfully

fun containsFatalErrorMessages(): Boolean =
validationMessages.getMessages().any { it.severity == Severity.FATAL_ERROR }
fun containsFatalErrorIssues(): Boolean =
validationIssues.getIssues().any { it.severity == Severity.FATAL_ERROR }
}
Loading

0 comments on commit d30fdc1

Please sign in to comment.