Skip to content

Commit

Permalink
make standoff entities in cache private and expose through methods
Browse files Browse the repository at this point in the history
  • Loading branch information
BalduinLandolt committed Dec 22, 2024
1 parent b70f381 commit c322879
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,12 @@ final case class OntologyResponderV2(
}
}.toMap

propertyDefsAvailable = propertyOntologies.flatMap { ontology =>
ontology.properties.filter { case (propertyIri, _) =>
standoffPropertyIris.contains(propertyIri) && cacheData.standoffProperties.contains(
propertyIri,
)
}
}.toMap
propertyDefsAvailable =
propertyOntologies.flatMap { ontology =>
ontology.properties.filter { case (propertyIri, _) =>
standoffPropertyIris.contains(propertyIri) && cacheData.containsStandoffProperty(propertyIri)
}
}.toMap

missingClassDefs = classIrisForCache -- classDefsAvailable.keySet
missingPropertyDefs = propertyIrisForCache -- propertyDefsAvailable.keySet
Expand Down Expand Up @@ -248,10 +247,9 @@ final case class OntologyResponderV2(
* @return a [[StandoffAllPropertyEntitiesGetResponseV2]].
*/
private def getAllStandoffPropertyEntitiesV2: Task[StandoffAllPropertyEntitiesGetResponseV2] =
ontologyCache.getCacheData.map { data =>
val ontologies: Iterable[ReadOntologyV2] = data.ontologies.values
ontologies.flatMap(_.properties.view.filterKeys(data.standoffProperties)).toMap
}.map(StandoffAllPropertyEntitiesGetResponseV2.apply)
ontologyCache.getCacheData
.map(_.getAllStandoffPropertyEntities)
.map(StandoffAllPropertyEntitiesGetResponseV2.apply)

/**
* Checks whether a certain Knora resource or value class is a subclass of another class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package org.knora.webapi.slice.ontology.repo.model
import org.knora.webapi.messages.SmartIri
import org.knora.webapi.messages.v2.responder.ontologymessages.PropertyInfoContentV2
import org.knora.webapi.messages.v2.responder.ontologymessages.ReadOntologyV2
import org.knora.webapi.messages.v2.responder.ontologymessages.ReadPropertyInfoV2

/**
* The in-memory cache of ontologies.
Expand All @@ -30,13 +31,18 @@ case class OntologyCacheData(
classDefinedInOntology: Map[SmartIri, SmartIri],
propertyDefinedInOntology: Map[SmartIri, SmartIri],
entityDefinedInOntology: Map[SmartIri, SmartIri],
standoffProperties: Set[SmartIri],
private val standoffProperties: Set[SmartIri],
) {
lazy val allPropertyDefs: Map[SmartIri, PropertyInfoContentV2] = ontologies.values
.flatMap(_.properties.map { case (propertyIri, readPropertyInfo) =>
propertyIri -> readPropertyInfo.entityInfoContent
})
.toMap

def containsStandoffProperty(propertyIri: SmartIri): Boolean = standoffProperties.contains(propertyIri)

def getAllStandoffPropertyEntities: Map[SmartIri, ReadPropertyInfoV2] =
ontologies.values.flatMap(_.properties.view.filterKeys(standoffProperties)).toMap
}
object OntologyCacheData {
val Empty = OntologyCacheData(
Expand Down

0 comments on commit c322879

Please sign in to comment.