Commit 812e958d authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Rename KEYS to Constants

parent 346ddef1
......@@ -20,7 +20,7 @@ package org.memobase
import ch.memobase.settings.SettingsLoader
import kotlin.system.exitProcess
import org.apache.logging.log4j.LogManager
import org.memobase.helpers.KEYS.SettingsProps
import org.memobase.helpers.Constants.SettingsProps
class App {
companion object {
......
......@@ -36,7 +36,7 @@ import org.memobase.helpers.FacetBuildHelpers
import org.memobase.helpers.Filter
import org.memobase.helpers.InstitutionAndRecordSetExtractionHelper.extractInstitution
import org.memobase.helpers.InstitutionAndRecordSetExtractionHelper.extractRecordSet
import org.memobase.helpers.KEYS
import org.memobase.helpers.Constants
import org.memobase.helpers.TranslationMappers
import org.memobase.model.DocumentsSearchDoc
import org.memobase.model.EnrichedDigitalMetadata
......@@ -59,39 +59,39 @@ class DocumentsSearchDocBuilder(
val physicalObject =
input.values.firstOrNull { it["@type"] == NS.rico + "Instantiation" && it["type"] == "physicalObject" }
val keywordIds = Extract.identifiers(record[KEYS.hasSubject])
val genreIds = Extract.identifiers(record[KEYS.hasGenre])
val publishedByIds = Extract.identifiers(record[KEYS.publishedBy])
val producerIds = Extract.identifiers(record[KEYS.producer])
val spatialIds = Extract.identifiers(record[KEYS.spatial])
val placeOfCaptureIds = Extract.identifiers(record[KEYS.placeOfCapture])
val dateCreatedIds = Extract.identifiers(record[KEYS.created])
val dateIssuedIds = Extract.identifiers(record[KEYS.issued])
val temporalIds = Extract.identifiers(record[KEYS.temporal])
val keywordIds = Extract.identifiers(record[Constants.hasSubject])
val genreIds = Extract.identifiers(record[Constants.hasGenre])
val publishedByIds = Extract.identifiers(record[Constants.publishedBy])
val producerIds = Extract.identifiers(record[Constants.producer])
val spatialIds = Extract.identifiers(record[Constants.spatial])
val placeOfCaptureIds = Extract.identifiers(record[Constants.placeOfCapture])
val dateCreatedIds = Extract.identifiers(record[Constants.created])
val dateIssuedIds = Extract.identifiers(record[Constants.issued])
val temporalIds = Extract.identifiers(record[Constants.temporal])
val personFacetBuilder = PersonFacetBuilder()
val subjectPersonBuilder = AgentContainerBuilder(keywordIds, KEYS.Person, null, input)
val publisherPersonBuilder = AgentContainerBuilder(publishedByIds, KEYS.Person, null, input)
val producersPersonBuilder = AgentContainerBuilder(producerIds, KEYS.Person, null, input)
val contributorPersonBuilder = AgentContainerBuilder(emptyList(), KEYS.Person, KEYS.contributor, input)
val creatorPersonBuilder = AgentContainerBuilder(emptyList(), KEYS.Person, KEYS.creator, input)
val subjectCorporateBodyBuilder = AgentContainerBuilder(keywordIds, KEYS.CorporateBody, null, input)
val publisherCorporateBodyBuilder = AgentContainerBuilder(publishedByIds, KEYS.CorporateBody, null, input)
val producersCorporateBodyBuilder = AgentContainerBuilder(producerIds, KEYS.CorporateBody, null, input)
val subjectPersonBuilder = AgentContainerBuilder(keywordIds, Constants.Person, null, input)
val publisherPersonBuilder = AgentContainerBuilder(publishedByIds, Constants.Person, null, input)
val producersPersonBuilder = AgentContainerBuilder(producerIds, Constants.Person, null, input)
val contributorPersonBuilder = AgentContainerBuilder(emptyList(), Constants.Person, Constants.contributor, input)
val creatorPersonBuilder = AgentContainerBuilder(emptyList(), Constants.Person, Constants.creator, input)
val subjectCorporateBodyBuilder = AgentContainerBuilder(keywordIds, Constants.CorporateBody, null, input)
val publisherCorporateBodyBuilder = AgentContainerBuilder(publishedByIds, Constants.CorporateBody, null, input)
val producersCorporateBodyBuilder = AgentContainerBuilder(producerIds, Constants.CorporateBody, null, input)
val contributorCorporateBodyBuilder =
AgentContainerBuilder(emptyList(), KEYS.CorporateBody, KEYS.contributor, input)
val creatorCorporateBodyBuilder = AgentContainerBuilder(emptyList(), KEYS.CorporateBody, KEYS.creator, input)
AgentContainerBuilder(emptyList(), Constants.CorporateBody, Constants.contributor, input)
val creatorCorporateBodyBuilder = AgentContainerBuilder(emptyList(), Constants.CorporateBody, Constants.creator, input)
val subjectAgentBuilder = AgentContainerBuilder(keywordIds, KEYS.Agent, null, input)
val publisherAgentBuilder = AgentContainerBuilder(publishedByIds, KEYS.Agent, null, input)
val producersAgentBuilder = AgentContainerBuilder(producerIds, KEYS.Agent, null, input)
val contributorAgentBuilder = AgentContainerBuilder(emptyList(), KEYS.Agent, KEYS.contributor, input)
val creatorAgentBuilder = AgentContainerBuilder(emptyList(), KEYS.Agent, KEYS.creator, input)
val subjectAgentBuilder = AgentContainerBuilder(keywordIds, Constants.Agent, null, input)
val publisherAgentBuilder = AgentContainerBuilder(publishedByIds, Constants.Agent, null, input)
val producersAgentBuilder = AgentContainerBuilder(producerIds, Constants.Agent, null, input)
val contributorAgentBuilder = AgentContainerBuilder(emptyList(), Constants.Agent, Constants.contributor, input)
val creatorAgentBuilder = AgentContainerBuilder(emptyList(), Constants.Agent, Constants.creator, input)
val placesRelatedBuilder = FacettedContainerBuilder(spatialIds, KEYS.Place, KEYS.name, FacetBuildHelpers::place)
val placesRelatedBuilder = FacettedContainerBuilder(spatialIds, Constants.Place, Constants.name, FacetBuildHelpers::place)
val placeCapturedBuilder =
FacettedContainerBuilder(placeOfCaptureIds, KEYS.Place, KEYS.name, FacetBuildHelpers::place)
FacettedContainerBuilder(placeOfCaptureIds, Constants.Place, Constants.name, FacetBuildHelpers::place)
val placeFacetBuilder = PlaceFacetBuilder()
......@@ -104,9 +104,9 @@ class DocumentsSearchDocBuilder(
val digitalIdentifierReferences = Extract.identifiers(digitalObject?.get("identifiedBy"))
val digitalIdentifierEntities = mutableListOf<JsonObject>()
val formats = EnrichedFacetContainerBuilder(emptyList(), NS.rico + KEYS.CarrierType, KEYS.name, input)
val languages = EnrichedFacetContainerBuilder(emptyList(), NS.rico + KEYS.Language, KEYS.name, input)
val genres = EnrichedFacetContainerBuilder(genreIds, NS.skos + KEYS.Concept, KEYS.prefLabel, input)
val formats = EnrichedFacetContainerBuilder(emptyList(), NS.rico + Constants.CarrierType, Constants.name, input)
val languages = EnrichedFacetContainerBuilder(emptyList(), NS.rico + Constants.Language, Constants.name, input)
val genres = EnrichedFacetContainerBuilder(genreIds, NS.skos + Constants.Concept, Constants.prefLabel, input)
for (item in input.entries) {
for (builder: IFieldBuilder in listOf(
......@@ -166,7 +166,7 @@ class DocumentsSearchDocBuilder(
val usageDigital = Extract.typedEntityByType(digitalRules, "type", "usage", "sameAs").flatMap { it.toList() }
val locator = try {
val value = Extract.extractIdValue(digitalIdentifierEntities, KEYS.IdentifierType.main)
val value = Extract.extractIdValue(digitalIdentifierEntities, Constants.IdentifierType.main)
if (value == null)
""
else
......@@ -208,7 +208,7 @@ class DocumentsSearchDocBuilder(
}
}
val type = record[KEYS.ricoType].let {
val type = record[Constants.ricoType].let {
if (it == null) {
translationMappers.getDocumentType("Andere")
} else {
......@@ -224,13 +224,13 @@ class DocumentsSearchDocBuilder(
broadcastTitle = Extract.typedEntityByType(recordTitles, "type", "broadcast", "title"),
type = type,
sourceID = try {
Extract.extractIdValue(recordIdentifiers, KEYS.IdentifierType.original) ?: "NoSourceIdFound"
Extract.extractIdValue(recordIdentifiers, Constants.IdentifierType.original) ?: "NoSourceIdFound"
} catch (ex: NoSuchElementException) {
log.error("No source id found for record $key.")
"NoSourceIdFound"
},
oldMemobaseId = try {
Extract.extractIdValue(recordIdentifiers, KEYS.IdentifierType.oldMemobase) ?: ""
Extract.extractIdValue(recordIdentifiers, Constants.IdentifierType.oldMemobase) ?: ""
} catch (ex: NoSuchElementException) {
log.warn("No old memobase id found for record $key.")
""
......@@ -263,9 +263,9 @@ class DocumentsSearchDocBuilder(
rightsHolder = Extract.typedEntityByType(recordRules, "type", "holder", "name"),
conditionsOfUse = Extract.languageContainer(
"conditionsOfUse (record id: $key)",
record[KEYS.conditionsOfUse]
record[Constants.conditionsOfUse]
),
memoriavClaim = record[KEYS.sponsoredBy] != null,
memoriavClaim = record[Constants.sponsoredBy] != null,
format = formats.build(),
language = languages.build(),
......@@ -274,7 +274,7 @@ class DocumentsSearchDocBuilder(
keywords = subjects.flatMap {
Extract.languageContainer(
"hasSubject (record id: $key)",
it[KEYS.prefLabel]
it[Constants.prefLabel]
)
}.let {
if (it.isEmpty())
......@@ -309,7 +309,7 @@ class DocumentsSearchDocBuilder(
// DIGITAL
accessDigital = accessDigital,
durationDigital = Extract.listOfStrings(digitalObject?.get("duration")),
colourDigital = Extract.listOfStrings(digitalObject?.get(KEYS.color)),
colourDigital = Extract.listOfStrings(digitalObject?.get(Constants.color)),
digitalObjectNote = Extract.languageContainer("descriptiveNote", digitalObject?.get("descriptiveNote")),
locator = if (addLocator) locator else null,
mediaLocation = mediaLocation,
......@@ -346,7 +346,7 @@ class DocumentsSearchDocBuilder(
originalInstitution = elasticSearchWrapper.getExtraInstitutionsFromRecordSet(recordSetId, "original"),
masterInstitution = elasticSearchWrapper.getExtraInstitutionsFromRecordSet(recordSetId, "master"),
published = (record[KEYS.isPublished] as Boolean?) ?: false,
published = (record[Constants.isPublished] as Boolean?) ?: false,
suggest = suggestContainerBuilder.build()[0]
)
}
......
......@@ -26,7 +26,7 @@ import org.apache.logging.log4j.LogManager
import org.memobase.helpers.Date
import org.memobase.helpers.ElasticSearchWrapper
import org.memobase.helpers.Extract
import org.memobase.helpers.KEYS
import org.memobase.helpers.Constants
import org.memobase.helpers.TranslationMappers
import org.memobase.model.FacetContainer
import org.memobase.model.InstitutionSearchDoc
......@@ -51,23 +51,23 @@ class InstitutionSearchDocBuilder(
input.values.forEach {
when {
it[KEYS.ricoType] == KEYS.LocationType.canton -> {
it[Constants.ricoType] == Constants.LocationType.canton -> {
cantons.add(FacetContainer(extractAdminUnit(it, "canton", "NoCantonFound"), null, emptyList()))
}
it[KEYS.ricoType] == KEYS.LocationType.municipality -> {
it[Constants.ricoType] == Constants.LocationType.municipality -> {
municipalities.add(extractAdminUnit(it, "municipality", "NoCityFound"))
}
it[KEYS.ricoType] == KEYS.IdentifierType.main -> {
it[Constants.ricoType] == Constants.IdentifierType.main -> {
identifiers.add(it)
}
it[KEYS.atType] == NS.rico + KEYS.Place -> {
addresses.addAll(Extract.listOfStrings(it[KEYS.wikidataAddresses]))
postalCodes.addAll(Extract.listOfStrings(it[KEYS.wikidataPostalCodes]))
it[Constants.atType] == NS.rico + Constants.Place -> {
addresses.addAll(Extract.listOfStrings(it[Constants.wikidataAddresses]))
postalCodes.addAll(Extract.listOfStrings(it[Constants.wikidataPostalCodes]))
}
}
}
val type = institution[KEYS.wikidataInstance].let {
val type = institution[Constants.wikidataInstance].let {
when (it) {
is String -> listOf(translationMappers.getInstitutionType(it))
is JsonArray<*> -> it.map { any -> translationMappers.getInstitutionType(any as String) }
......@@ -78,15 +78,15 @@ class InstitutionSearchDocBuilder(
}
}
val name = extractLanguageContainer(institution[KEYS.name], "NoNameFound")
val description = extractLanguageContainer(institution[KEYS.descriptiveNote], "NoDescriptionFound")
val id = Extract.extractIdValue(identifiers, KEYS.IdentifierType.main) ?: "NoIdentifierFound"
val recordSetUris = Extract.listOfStrings(institution[KEYS.isHolderOf])
val name = extractLanguageContainer(institution[Constants.name], "NoNameFound")
val description = extractLanguageContainer(institution[Constants.descriptiveNote], "NoDescriptionFound")
val id = Extract.extractIdValue(identifiers, Constants.IdentifierType.main) ?: "NoIdentifierFound"
val recordSetUris = Extract.listOfStrings(institution[Constants.isHolderOf])
val recordSetIds = recordSetUris.map { it.substringAfterLast("/") }
return InstitutionSearchDoc(
institutionId = id,
published = institution[KEYS.isPublished].let {
published = institution[Constants.isPublished].let {
when (it) {
is Boolean -> it
is String -> it.toBoolean()
......@@ -102,10 +102,10 @@ class InstitutionSearchDocBuilder(
documentType = recordSetIds.flatMap {
elasticSearchWrapper.getDocumentTypesFromRecords(
it,
KEYS.QueryFields.recordSetFacet
Constants.QueryFields.recordSetFacet
)
}.distinctBy { it.filter },
keyVisualLink = institution[KEYS.wikidataImage].let { if (it != null) it as String else "NoKeyVisualLinkDefined" },
keyVisualLink = institution[Constants.wikidataImage].let { if (it != null) it as String else "NoKeyVisualLinkDefined" },
canton = cantons,
city = municipalities,
address = addresses,
......@@ -149,7 +149,7 @@ class InstitutionSearchDocBuilder(
}
private fun extractAdminUnit(item: JsonObject, parent: String, placeholder: String): LanguageContainer {
return item[KEYS.name].let { name ->
return item[Constants.name].let { name ->
Extract.languageContainer(parent, name).let {
when {
it.isEmpty() -> LanguageContainer.placeholder(placeholder)
......
......@@ -32,7 +32,7 @@ import org.apache.kafka.streams.kstream.Predicate
import org.apache.logging.log4j.LogManager
import org.memobase.helpers.ElasticSearchWrapper
import org.memobase.helpers.JSON
import org.memobase.helpers.KEYS.SettingsProps
import org.memobase.helpers.Constants.SettingsProps
import org.memobase.helpers.TranslationMappers
import org.memobase.helpers.UpdateQueryBuilder
import org.memobase.model.DocumentsSearchDoc
......
......@@ -31,7 +31,7 @@ import org.memobase.helpers.Date
import org.memobase.helpers.ElasticSearchWrapper
import org.memobase.helpers.Extract
import org.memobase.helpers.JSON
import org.memobase.helpers.KEYS
import org.memobase.helpers.Constants
import org.memobase.model.FacetContainer
import org.memobase.model.IntegerRange
import org.memobase.model.LanguageContainer
......@@ -60,48 +60,48 @@ class RecordSetSearchDocBuilder(private val elasticSearchWrapper: ElasticSearchW
val originalInstitutions = mutableListOf<FacetContainer>()
input.values.forEach {
when {
it[RICO.type.localName] == KEYS.LanguageType.metadata -> {
it[RICO.type.localName] == Constants.LanguageType.metadata -> {
metadataLanguages.add(it)
}
it[KEYS.atType] == RICO.Identifier.uri && it[RICO.type.localName] == KEYS.IdentifierType.callNumber -> {
it[Constants.atType] == RICO.Identifier.uri && it[RICO.type.localName] == Constants.IdentifierType.callNumber -> {
originalCallNumbers.add(it[RICO.identifier.localName] as String)
}
it[KEYS.atType] == RICO.Identifier.uri && it[RICO.type.localName] == KEYS.IdentifierType.original -> {
it[Constants.atType] == RICO.Identifier.uri && it[RICO.type.localName] == Constants.IdentifierType.original -> {
originalIdNumbers.add(it[RICO.identifier.localName] as String)
}
it[KEYS.atType] == RICO.Title.uri &&
it[RICO.type.localName] == KEYS.TitleTypes.original -> {
it[Constants.atType] == RICO.Title.uri &&
it[RICO.type.localName] == Constants.TitleTypes.original -> {
originalTitles = originalTitles.add(it[RICO.title.localName])
}
it[KEYS.atType] == RICO.CorporateBody.uri &&
it[RICO.type.localName] == KEYS.CorporateBodyType.memoriavProject -> {
it[Constants.atType] == RICO.CorporateBody.uri &&
it[RICO.type.localName] == Constants.CorporateBodyType.memoriavProject -> {
projectTitles = projectTitles.add(it[RICO.title.localName])
}
it[KEYS.atType] == RICO.RecordSet.uri && it[RICO.type.localName] == RecordSet.related -> {
it[Constants.atType] == RICO.RecordSet.uri && it[RICO.type.localName] == RecordSet.related -> {
relatedRecordSets = relatedRecordSets.add(it[RICO.title.localName])
}
it[KEYS.atType] == RICO.Record.uri -> {
it[Constants.atType] == RICO.Record.uri -> {
if (it[RICO.type.localName] == RICO.Types.Record.publication) {
publicationTitles = publicationTitles.add(it[RICO.title.localName])
} else if (it[RICO.type.localName] == RICO.Types.Record.related) {
relatedDocumentTitles = relatedDocumentTitles.add(it[RICO.title.localName])
}
}
it[KEYS.atType] == RICO.RecordResourceHoldingRelation.uri
it[Constants.atType] == RICO.RecordResourceHoldingRelation.uri
&& it[RICO.type.localName] == RICO.Types.RecordResourceHoldingRelation.access -> {
val value = it[RICO.recordResourceHoldingRelationHasSource.localName] as String
val id = value.substringAfterLast("/")
val names = elasticSearchWrapper.getInstitutionName(id)
accessInstitutions.add(names)
}
it[KEYS.atType] == RICO.RecordResourceHoldingRelation.uri
it[Constants.atType] == RICO.RecordResourceHoldingRelation.uri
&& it[RICO.type.localName] == RICO.Types.RecordResourceHoldingRelation.master -> {
val value = it[RICO.recordResourceHoldingRelationHasSource.localName] as String
val id = value.substringAfterLast("/")
val names = elasticSearchWrapper.getInstitutionName(id)
masterInstitutions.add(names)
}
it[KEYS.atType] == RICO.RecordResourceHoldingRelation.uri
it[Constants.atType] == RICO.RecordResourceHoldingRelation.uri
&& it[RICO.type.localName] == RICO.Types.RecordResourceHoldingRelation.original -> {
val value = it[RICO.recordResourceHoldingRelationHasSource.localName] as String
val id = value.substringAfterLast("/")
......@@ -137,7 +137,7 @@ class RecordSetSearchDocBuilder(private val elasticSearchWrapper: ElasticSearchW
} else {
null
}
val uri = recordSet[KEYS.entityId] as String
val uri = recordSet[Constants.entityId] as String
val id = uri.substringAfterLast("/")
val institutions = when (val value = recordSet[RICO.heldBy.localName]) {
is String -> listOf(value)
......@@ -163,7 +163,7 @@ class RecordSetSearchDocBuilder(private val elasticSearchWrapper: ElasticSearchW
return RecordSetSearchDoc(
recordSetId = id,
published = recordSet[KEYS.isPublished].let {
published = recordSet[Constants.isPublished].let {
when (it) {
is Boolean -> it
is String -> it.toBoolean()
......@@ -175,16 +175,16 @@ class RecordSetSearchDocBuilder(private val elasticSearchWrapper: ElasticSearchW
},
periodOfTimeAsYear = date,
institution = institutionIds.map { elasticSearchWrapper.getInstitutionName(it) },
supportedByMemoriav = recordSet[KEYS.sponsoredBy] != null,
supportedByMemoriav = recordSet[Constants.sponsoredBy] != null,
name = name,
documentType = elasticSearchWrapper.getDocumentTypesFromRecords(id, KEYS.QueryFields.recordSetFacet),
keyVisualLink = recordSet[KEYS.wikidataImage].let { if (it != null) it as String else "NoKeyVisualLinkDefined" },
documentType = elasticSearchWrapper.getDocumentTypesFromRecords(id, Constants.QueryFields.recordSetFacet),
keyVisualLink = recordSet[Constants.wikidataImage].let { if (it != null) it as String else "NoKeyVisualLinkDefined" },
numberOfDocuments = elasticSearchWrapper.countNumberOfDocuments(id),
lastUpdatedDate = Date.now,
languageOfMetadata = metadataLanguages.map {
FacetContainer(
extractLanguageContainer(it[KEYS.name], "NoMetadataLanguageSet"),
it[KEYS.sameAs].let { wikidataUri ->
extractLanguageContainer(it[Constants.name], "NoMetadataLanguageSet"),
it[Constants.sameAs].let { wikidataUri ->
when (wikidataUri) {
is String -> wikidataUri.substringAfterLast("/")
else -> null
......
......@@ -32,7 +32,7 @@ import org.elasticsearch.client.RestClient
import org.elasticsearch.client.RestHighLevelClient
import org.elasticsearch.client.indices.GetIndexRequest
import org.memobase.helpers.ElasticSearchWrapper
import org.memobase.helpers.KEYS.SettingsProps
import org.memobase.helpers.Constants.SettingsProps
import org.memobase.helpers.TranslationMappers
class Service(settings: SettingsLoader) {
......@@ -40,7 +40,7 @@ class Service(settings: SettingsLoader) {
const val name = "search-doc-service"
}
private val log = LogManager.getLogger("SearchDocServiceService")
private val log = LogManager.getLogger("SearchDocService")
private val appSettings = settings.appSettings
private val documentMapperPath = appSettings.getProperty(SettingsProps.documentTypeLabelsPath)
......
......@@ -23,7 +23,7 @@ import com.beust.klaxon.JsonObject
import org.apache.logging.log4j.LogManager
import org.memobase.helpers.Extract
import org.memobase.helpers.FacetBuildHelpers
import org.memobase.helpers.KEYS
import org.memobase.helpers.Constants
import org.memobase.model.AgentWithRelationContainer
import org.memobase.model.LanguageContainer
......@@ -37,30 +37,30 @@ class AgentContainerBuilder(
private val containers = mutableListOf<AgentWithRelationContainer>()
override fun filter(jsonObject: JsonObject): Boolean {
if (jsonObject[KEYS.atType] != NS.rico + agentType) return false
if (jsonObject[Constants.atType] != NS.rico + agentType) return false
return if (creationRelationType != null) {
jsonObject[KEYS.agentIsTargetOfCreationRelation].let {
jsonObject[Constants.agentIsTargetOfCreationRelation].let {
if (it != null)
inputMap[it].let { creationRelation ->
creationRelation?.get(KEYS.ricoType) == creationRelationType
creationRelation?.get(Constants.ricoType) == creationRelationType
}
else
false
}
} else {
identifiers.contains(jsonObject[KEYS.entityId])
identifiers.contains(jsonObject[Constants.entityId])
}
}
override fun append(key: String, jsonObject: JsonObject): String {
val names = Extract.languageContainer("agent-name", jsonObject[KEYS.name])
val names = Extract.languageContainer("agent-name", jsonObject[Constants.name])
val name = if (names.isNotEmpty())
names.reduce { acc, languageContainer -> acc.merge(languageContainer) }
else
LanguageContainer(emptyList(), emptyList(), emptyList(), listOf("NoNameFound"))
log.warn("Creation relation without names in agent ${jsonObject["@id"]}")
val relation = if (jsonObject.containsKey(KEYS.agentIsTargetOfCreationRelation)) {
val creationRelation = inputMap[jsonObject[KEYS.agentIsTargetOfCreationRelation]]
val relation = if (jsonObject.containsKey(Constants.agentIsTargetOfCreationRelation)) {
val creationRelation = inputMap[jsonObject[Constants.agentIsTargetOfCreationRelation]]
creationRelation.let {
if (it != null) {
val languages = Extract.languageContainer("creation-relation-name", it["name"])
......@@ -76,7 +76,7 @@ class AgentContainerBuilder(
} else {
null
}
val filterAndFacet = if (agentType == KEYS.Person) {
val filterAndFacet = if (agentType == Constants.Person) {
FacetBuildHelpers.person(jsonObject)
} else {
Pair(null, null)
......@@ -89,7 +89,7 @@ class AgentContainerBuilder(
facet = filterAndFacet.second
)
)
return "Created person container for person ${jsonObject[KEYS.entityId]}"
return "Created person container for person ${jsonObject[Constants.entityId]}"
}
override fun build(): List<AgentWithRelationContainer> {
......
......@@ -22,7 +22,7 @@ import com.beust.klaxon.JsonArray
import com.beust.klaxon.JsonObject
import org.apache.logging.log4j.LogManager
import org.memobase.helpers.DateFacetBuildHelpers
import org.memobase.helpers.KEYS
import org.memobase.helpers.Constants
import org.memobase.model.DateContainer
class DateContainerBuilder(private val containedIds: List<String>) : IFieldBuilder {
......@@ -31,8 +31,8 @@ class DateContainerBuilder(private val containedIds: List<String>) : IFieldBuild
private val dateContainers = mutableListOf<DateContainer>()
override fun filter(jsonObject: JsonObject): Boolean {
return if (containedIds.contains(jsonObject[KEYS.entityId]))
listOf(NS.rico + KEYS.DateRange, NS.rico + KEYS.SingleDate).contains(jsonObject[KEYS.atType])
return if (containedIds.contains(jsonObject[Constants.entityId]))
listOf(NS.rico + Constants.DateRange, NS.rico + Constants.SingleDate).contains(jsonObject[Constants.atType])
else
false
}
......
......@@ -18,13 +18,11 @@
package org.memobase.builders
import ch.memobase.rdf.RICO
import com.beust.klaxon.JsonObject
import org.apache.logging.log4j.LogManager
import org.memobase.helpers.Extract
import org.memobase.helpers.KEYS
import org.memobase.helpers.Constants
import org.memobase.model.EnrichedFacetContainer
import org.memobase.model.LanguageContainer
/**
*
......@@ -39,25 +37,25 @@ class EnrichedFacetContainerBuilder(
private val containers = mutableListOf<EnrichedFacetContainer>()
override fun filter(jsonObject: JsonObject): Boolean {
if (jsonObject[KEYS.atType] != targetType) return false
if (jsonObject[Constants.atType] != targetType) return false
// Filter any values of this type which were not enriched. These will be found via the resultsFrom link.
if (!jsonObject.containsKey(KEYS.resultsFrom)) return false
if (identifiers.isNotEmpty()) return identifiers.contains(jsonObject[KEYS.entityId])
if (!jsonObject.containsKey(Constants.resultsFrom)) return false
if (identifiers.isNotEmpty()) return identifiers.contains(jsonObject[Constants.entityId])
return true
}
override fun append(key: String, jsonObject: JsonObject): String {
val names = Extract.languageContainer(targetType, jsonObject[nameProperty])
.reduce { acc, languageContainer -> acc.merge(languageContainer) }.fillInEmpty()
val ricoType = jsonObject[KEYS.ricoType] as String?
val activityId = jsonObject[KEYS.resultsFrom]
val ricoType = jsonObject[Constants.ricoType] as String?
val activityId = jsonObject[Constants.resultsFrom]
if (!fullGraph.containsKey(activityId)) {
log.error("Could not find activity with id $activityId in record $key.")
return "Could not find activity with id $activityId in record $key."
}
val activity = fullGraph[activityId] as JsonObject
return if (activity.containsKey(KEYS.affects)) {
val sourceObjectId = activity[KEYS.affects]
return if (activity.containsKey(Constants.affects)) {
val sourceObjectId = activity[Constants.affects]
val sourceObject = fullGraph[sourceObjectId] as JsonObject
val displayNames = Extract.languageContainer("source entity", sourceObject[nameProperty])
.reduce { acc, languageContainer -> acc.merge(languageContainer) }
......
......@@ -21,7 +21,7 @@ package org.memobase.builders
import ch.memobase.rdf.NS
import com.beust.klaxon.JsonObject
import org.memobase.helpers.Extract
import org.memobase.helpers.KEYS
import org.memobase.helpers.Constants
import org.memobase.model.FacetContainer
/**
......@@ -37,8 +37,8 @@ class FacettedContainerBuilder(
private val containers = mutableListOf<FacetContainer>()
override fun filter(jsonObject: JsonObject): Boolean {
if (jsonObject[KEYS.atType] != NS.rico + targetType) return false
return identifiers.contains(jsonObject[KEYS.entityId])
if (jsonObject[Constants.atType] != NS.rico + targetType) return false
return identifiers.contains(jsonObject[Constants.entityId])
}
override fun append(key: String, jsonObject: JsonObject): String {
......
......@@ -22,7 +22,7 @@ import ch.memobase.rdf.NS
import com.beust.klaxon.JsonObject
import org.apache.logging.log4j.LogManager
import org.memobase.helpers.FacetBuildHelpers
import org.memobase.helpers.KEYS
import org.memobase.helpers.Constants
import org.memobase.model.SimpleFacetContainer
class PersonFacetBuilder : IFieldBuilder {
......@@ -32,9 +32,9 @@ class PersonFacetBuilder : IFieldBuilder {
private val personsNames = mutableSetOf<String>()
override fun filter(jsonObject: JsonObject): Boolean {
return jsonObject[KEYS.atType].let {
return jsonObject[Constants.atType].let {
when (it) {
is String -> it == NS.rico + KEYS.Person