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