Minor moddel adjustments

This commit is contained in:
2025-07-01 12:54:56 +02:00
parent a9f6efc818
commit ce5b87c34e
5 changed files with 22 additions and 37 deletions

View File

@@ -1,11 +1,15 @@
package com.rak.config.model package com.rak.config.model
import io.smallrye.config.WithDefault
import io.smallrye.config.WithName import io.smallrye.config.WithName
import java.util.* import java.util.*
interface ScrapeTargetFieldConfig : AbstractScrapeTargetFieldConfig { interface ScrapeTargetFieldConfig : AbstractScrapeTargetFieldConfig {
@WithName("type") @WithName("type")
fun getType(): String fun getType(): String
@WithName("nullable")
@WithDefault("false")
fun isNullable(): Boolean
@WithName("root") @WithName("root")
fun getRootConfig(): Optional<ExtractConfig> fun getRootConfig(): Optional<ExtractConfig>
@WithName("extractors") @WithName("extractors")

View File

@@ -1,9 +1,7 @@
package com.rak.model.card package com.rak.model.card
import com.rak.model.set.RegionalSet
data class CardPrint( data class CardPrint(
val id: String, var id: Int,
val name: String, val name: String,
val regionalName: String? = null, val regionalName: String? = null,
val rarity: String val rarity: String
@@ -11,10 +9,17 @@ data class CardPrint(
companion object { companion object {
fun fromMap(map: Map<String, String>): CardPrint { fun fromMap(map: Map<String, String>): CardPrint {
val regionalNameValue = map["regionalName"]
val regionalName = if (regionalNameValue == "") {
null
} else {
regionalNameValue
}
return CardPrint( return CardPrint(
map["id"] ?: throw IllegalStateException("Parameter 'prefix' not found"), map["id"]?.toInt() ?: throw IllegalStateException("Parameter 'prefix' not found"),
map["name"] ?: throw IllegalStateException("Parameter 'region' not found"), map["name"] ?: throw IllegalStateException("Parameter 'region' not found"),
map["regionalName"], regionalName,
map["rarity"] ?: throw IllegalStateException("Parameter 'regionCode' not found"), map["rarity"] ?: throw IllegalStateException("Parameter 'regionCode' not found"),
) )
} }

View File

@@ -22,28 +22,6 @@ data class RegionalSet(
) )
} }
fun flattenFromMemberLists(
idList: List<String>,
languageList: List<String>,
regionKeyAliasList: List<String>,
): MutableSet<RegionalSet> {
if (idList.size != languageList.size && idList.size != regionKeyAliasList.size) {
throw IllegalArgumentException("Lists have to be the same size")
}
val regionalSetList: MutableSet<RegionalSet> = mutableSetOf()
for (index in 0..idList.size - 1) {
regionalSetList.add(RegionalSet(
prefix = idList[index],
region = languageList[index],
regionCode = regionKeyAliasList[index],
listOf(),
numberOfCards = -1
))
}
return regionalSetList
}
} }
} }

View File

@@ -11,7 +11,7 @@ class TransformationRegistry {
init { init {
register("trim") { it.trim() } register("trim") { it.trim() }
register("removeInnerQuotes") { it.replace("\"", "") } register("removeInnerQuotes") { it.replace(Regex("^\""), "").replace(Regex("\"$"), "") }
register("replace") { input, parameters -> register("replace") { input, parameters ->
require(parameters.size == 1 || parameters.size == 2) { require(parameters.size == 1 || parameters.size == 2) {
"'replace' requires either 1 or 2 parameters" "'replace' requires either 1 or 2 parameters"

View File

@@ -130,7 +130,11 @@ abstract class AbstractExtractionService<E, T : AbstractScrapeTargetConfig> {
val extractedText = extractTextFromElementByTargetFieldConfig( val extractedText = extractTextFromElementByTargetFieldConfig(
rootElement, rootElement,
fieldConfig fieldConfig
) ?: throw ElementNotFoundException("Could not find element for '$identifier'") ) ?: if (fieldConfig.isNullable()) {
""
} else {
throw ElementNotFoundException("Could not find element for '$identifier'")
}
val mapToModify: MutableMap<String, String> = try { val mapToModify: MutableMap<String, String> = try {
resultList[index] resultList[index]
@@ -224,14 +228,8 @@ abstract class AbstractExtractionService<E, T : AbstractScrapeTargetConfig> {
} catch (ex: RuntimeException) { } catch (ex: RuntimeException) {
when (ex) { when (ex) {
is ElementNotFoundException, is ElementNotFoundException,
is IllegalStateException -> { is IllegalStateException,
// if (extractionConfig.getFallbackConfiguration().isPresent) { is ValueValidationException -> Log.debug(ex.message)
// intermediateResult = extractionConfig.getFallbackConfiguration().get().getOptionalDefaultValue()
// } else {
// throw ex
// }
}
is ValueValidationException -> Log.warn(ex.message)
else -> throw ex else -> throw ex
} }
} }