Amend naming schema
This commit is contained in:
@@ -2,7 +2,7 @@ package com.rak.config.model
|
||||
|
||||
import io.smallrye.config.WithName
|
||||
|
||||
interface RegionalSetScrapeTargetConfig : AbstractScrapeTargetConfig {
|
||||
interface SetScrapeTargetConfig : AbstractScrapeTargetConfig {
|
||||
@WithName("id")
|
||||
fun getIdConfig(): ScrapeTargetFieldConfig
|
||||
@WithName("language")
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.rak.config.model
|
||||
|
||||
import io.smallrye.config.WithName
|
||||
import java.util.*
|
||||
|
||||
interface TargetsConfig {
|
||||
fun card(): Optional<CardScrapeTargetConfig>
|
||||
fun regionalSet(): Optional<RegionalSetScrapeTargetConfig>
|
||||
@WithName("card")
|
||||
fun getCardConfig(): Optional<CardScrapeTargetConfig>
|
||||
@WithName("set")
|
||||
fun getSetConfig(): Optional<SetScrapeTargetConfig>
|
||||
}
|
||||
@@ -30,21 +30,21 @@ class ExtractionService(
|
||||
|
||||
fun extractRegionalSet(root: Element, provider: String): RegionalSet {
|
||||
val source = sourceService.getSourceById(provider) ?: throw IllegalArgumentException("Provider $provider not found")
|
||||
val regionalSetSelector = source.getTargets().regionalSet().get()
|
||||
val setExtractionConfig = source.getTargets().getSetConfig().get()
|
||||
|
||||
if (regionalSetSelector.getRootConfig().isPresent) {
|
||||
if (setExtractionConfig.getRootConfig().isPresent) {
|
||||
val setId: String = extractTextFromElementByTargetFieldConfig(
|
||||
root,
|
||||
regionalSetSelector.getIdConfig(),
|
||||
setExtractionConfig.getIdConfig(),
|
||||
|
||||
) ?: throw IllegalStateException("Parameter 'id' could not be found")
|
||||
val setLanguage: String = extractTextFromElementByTargetFieldConfig(
|
||||
root,
|
||||
regionalSetSelector.getLanguageConfig()
|
||||
setExtractionConfig.getLanguageConfig()
|
||||
) ?: throw IllegalStateException("Parameter 'language' could not be found")
|
||||
val setKey: String = extractTextFromElementByTargetFieldConfig(
|
||||
root,
|
||||
regionalSetSelector.getRegionKeyConfig()
|
||||
setExtractionConfig.getRegionKeyConfig()
|
||||
) ?: throw IllegalStateException("Parameter 'key' could not be found")
|
||||
|
||||
return RegionalSet(
|
||||
@@ -53,7 +53,7 @@ class ExtractionService(
|
||||
setKey
|
||||
)
|
||||
} else {
|
||||
val setIdConfiguration = regionalSetSelector.getIdConfig()
|
||||
val setIdConfiguration = setExtractionConfig.getIdConfig()
|
||||
if (!setIdConfiguration.getRootConfig().isPresent) {
|
||||
throw RuntimeException("as[po") // TODO fix me
|
||||
}
|
||||
@@ -66,7 +66,7 @@ class ExtractionService(
|
||||
) ?: throw IllegalStateException("Parameter 'id' could not be found")
|
||||
|
||||
|
||||
val setLanguageConfiguration = regionalSetSelector.getIdConfig()
|
||||
val setLanguageConfiguration = setExtractionConfig.getIdConfig()
|
||||
val setLanguageRoot = getElementFromDocumentByExtractConfig(root, rootConfiguration) ?: throw ElementNotFoundException("TODO fix this")
|
||||
val setLanguage: String = extractTextFromElementByTargetFieldConfig(
|
||||
setLanguageRoot,
|
||||
@@ -74,7 +74,7 @@ class ExtractionService(
|
||||
) ?: throw IllegalStateException("Parameter 'language' could not be found")
|
||||
|
||||
|
||||
val setKeyConfiguration = regionalSetSelector.getIdConfig()
|
||||
val setKeyConfiguration = setExtractionConfig.getIdConfig()
|
||||
val setKeyRoot = getElementFromDocumentByExtractConfig(root, rootConfiguration) ?: throw ElementNotFoundException("TODO fix this")
|
||||
val setKey: String = extractTextFromElementByTargetFieldConfig(
|
||||
setKeyRoot,
|
||||
@@ -91,10 +91,10 @@ class ExtractionService(
|
||||
|
||||
fun extractRegionalSets(root: Element, provider: String): Set<RegionalSet> {
|
||||
val source = sourceService.getSourceById(provider) ?: throw IllegalArgumentException("Provider $provider not found")
|
||||
val regionalSetSelector = source.getTargets().regionalSet().get()
|
||||
val setExtractionConfig = source.getTargets().getSetConfig().get()
|
||||
|
||||
if (regionalSetSelector.getRootConfig().isPresent) {
|
||||
val rootConfiguration = regionalSetSelector.getRootConfig().get()
|
||||
if (setExtractionConfig.getRootConfig().isPresent) {
|
||||
val rootConfiguration = setExtractionConfig.getRootConfig().get()
|
||||
val regionalSetRoots: Elements = getElementsFromDocumentByExtractConfig(
|
||||
root,
|
||||
rootConfiguration
|
||||
@@ -108,7 +108,7 @@ class ExtractionService(
|
||||
}.toSet()
|
||||
} else {
|
||||
try {
|
||||
val setIdConfiguration = regionalSetSelector.getIdConfig()
|
||||
val setIdConfiguration = setExtractionConfig.getIdConfig()
|
||||
val setIdRoot = getElementsFromDocumentByExtractConfig(root, setIdConfiguration.getRootConfig().get())
|
||||
val setIds = setIdRoot.map {
|
||||
extractTextFromElementByTargetFieldConfig(
|
||||
@@ -117,7 +117,7 @@ class ExtractionService(
|
||||
) ?: throw IllegalStateException("Parameter 'id' could not be found")
|
||||
}
|
||||
|
||||
val languageConfiguration = regionalSetSelector.getLanguageConfig()
|
||||
val languageConfiguration = setExtractionConfig.getLanguageConfig()
|
||||
val languageRoot = getElementsFromDocumentByExtractConfig(root, languageConfiguration.getRootConfig().get())
|
||||
val languages = languageRoot.map {
|
||||
extractTextFromElementByTargetFieldConfig(
|
||||
@@ -126,7 +126,7 @@ class ExtractionService(
|
||||
) ?: throw IllegalStateException("Parameter 'id' could not be found")
|
||||
}
|
||||
|
||||
val setKeyConfiguration = regionalSetSelector.getRegionKeyConfig()
|
||||
val setKeyConfiguration = setExtractionConfig.getRegionKeyConfig()
|
||||
val setKeyRoot = getElementsFromDocumentByExtractConfig(root, setKeyConfiguration.getRootConfig().get())
|
||||
val setKeys = setKeyRoot.map {
|
||||
extractTextFromElementByTargetFieldConfig(
|
||||
@@ -148,7 +148,7 @@ class ExtractionService(
|
||||
|
||||
fun extractCard(root: Document, provider: String): Card? {
|
||||
val source = sourceService.getSourceById(provider) ?: throw IllegalArgumentException("Provider $provider not found")
|
||||
val cardSelector = source.getTargets().card().get()
|
||||
val cardSelector = source.getTargets().getCardConfig().get()
|
||||
|
||||
val rootConfigurationOptional = cardSelector.getRootConfig()
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.rak.service
|
||||
|
||||
import com.rak.config.model.CardScrapeTargetConfig
|
||||
import com.rak.config.model.RegionalSetScrapeTargetConfig
|
||||
import com.rak.config.model.SetScrapeTargetConfig
|
||||
import com.rak.config.model.ProviderConfig
|
||||
import com.rak.config.model.SourcesConfig
|
||||
import com.rak.model.exception.InvalidConfigurationException
|
||||
@@ -21,8 +21,8 @@ class SourceService(
|
||||
}
|
||||
|
||||
private fun validateSource(providerConfig: ProviderConfig) {
|
||||
val optionalRegionalSetConfig = providerConfig.getTargets().regionalSet()
|
||||
val optionalCardConfig = providerConfig.getTargets().card()
|
||||
val optionalRegionalSetConfig = providerConfig.getTargets().getSetConfig()
|
||||
val optionalCardConfig = providerConfig.getTargets().getCardConfig()
|
||||
|
||||
if (optionalRegionalSetConfig.isPresent) {
|
||||
validateSetExtractConfig(optionalRegionalSetConfig.get())
|
||||
@@ -33,7 +33,7 @@ class SourceService(
|
||||
}
|
||||
}
|
||||
|
||||
private fun validateSetExtractConfig(setExtractConfig: RegionalSetScrapeTargetConfig) {
|
||||
private fun validateSetExtractConfig(setExtractConfig: SetScrapeTargetConfig) {
|
||||
val selectors = listOf(
|
||||
setExtractConfig.getLanguageConfig(),
|
||||
setExtractConfig.getIdConfig(),
|
||||
|
||||
Reference in New Issue
Block a user