|
|
|
|
@@ -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()
|
|
|
|
|
|
|
|
|
|
|