@@ -24,6 +24,7 @@ import org.eclipse.apoapsis.ortserver.dao.tables.shared.IdentifiersTable
2424import org.eclipse.apoapsis.ortserver.dao.utils.SortableEntityClass
2525import org.eclipse.apoapsis.ortserver.dao.utils.SortableTable
2626import org.eclipse.apoapsis.ortserver.model.Severity
27+ import org.eclipse.apoapsis.ortserver.model.runs.LicenseSource
2728import org.eclipse.apoapsis.ortserver.model.runs.RuleViolation
2829
2930import org.jetbrains.exposed.dao.LongEntity
@@ -37,7 +38,7 @@ object RuleViolationsTable : SortableTable("rule_violations") {
3738 val rule = text(" rule" ).sortable()
3839 val identifierId = reference(" identifier_id" , IdentifiersTable ).nullable()
3940 val license = text(" license" ).nullable()
40- val licenseSource = text(" license_source " ).nullable()
41+ val licenseSources = text(" license_sources " ).nullable()
4142 val severity = enumerationByName<Severity >(" severity" , 128 ).sortable()
4243 val message = text(" message" )
4344 val howToFix = text(" how_to_fix" )
@@ -50,7 +51,7 @@ class RuleViolationDao(id: EntityID<Long>) : LongEntity(id) {
5051 rule = ruleViolation.rule
5152 identifierId = getIdentifierDaoOrNull(ruleViolation)
5253 license = ruleViolation.license
53- licenseSource = ruleViolation.licenseSource
54+ licenseSources = ruleViolation.licenseSources
5455 severity = ruleViolation.severity
5556 message = ruleViolation.message
5657 howToFix = ruleViolation.howToFix
@@ -63,7 +64,7 @@ class RuleViolationDao(id: EntityID<Long>) : LongEntity(id) {
6364 RuleViolationsTable .rule eq ruleViolation.rule and
6465 (RuleViolationsTable .identifierId eq identifierDao?.id) and
6566 (RuleViolationsTable .license eq ruleViolation.license) and
66- (RuleViolationsTable .licenseSource eq ruleViolation.licenseSource ) and
67+ (RuleViolationsTable .licenseSources eq ruleViolation.licenseSources.mapToString() ) and
6768 (RuleViolationsTable .severity eq ruleViolation.severity)
6869 }.find { it.message == ruleViolation.message && it.howToFix == ruleViolation.howToFix }
6970 }
@@ -80,7 +81,8 @@ class RuleViolationDao(id: EntityID<Long>) : LongEntity(id) {
8081 var rule by RuleViolationsTable .rule
8182 var identifierId by IdentifierDao optionalReferencedOn RuleViolationsTable .identifierId
8283 var license by RuleViolationsTable .license
83- var licenseSource by RuleViolationsTable .licenseSource
84+ var licenseSources by RuleViolationsTable .licenseSources
85+ .transform({ it.mapToString() }, { it.mapToLicenseSources() })
8486 var severity by RuleViolationsTable .severity
8587 var message by RuleViolationsTable .message
8688 var howToFix by RuleViolationsTable .howToFix
@@ -89,9 +91,20 @@ class RuleViolationDao(id: EntityID<Long>) : LongEntity(id) {
8991 rule = rule,
9092 id = identifierId?.mapToModel(),
9193 license = license,
92- licenseSource = licenseSource ,
94+ licenseSources = licenseSources ,
9395 severity = severity,
9496 message = message,
9597 howToFix = howToFix,
9698 )
9799}
100+
101+ /* *
102+ * Map a set of [LicenseSource] to a comma-separated [String], or `null` if the set is empty.
103+ */
104+ private fun Set<LicenseSource>.mapToString () = takeIf { it.isNotEmpty() }?.joinToString(" ," ) { it.name }
105+
106+ /* *
107+ * Map a comma-separated [String] to a set of [LicenseSource], or an empty set if the string is `null`.
108+ */
109+ private fun String?.mapToLicenseSources (): Set <LicenseSource > =
110+ this ?.split(' ,' )?.mapTo(mutableSetOf ()) { enumValueOf<LicenseSource >(it) }.orEmpty()
0 commit comments