From c322879fcbcad35d31e65da5597dd935d797b049 Mon Sep 17 00:00:00 2001 From: Balduin Landolt <33053745+BalduinLandolt@users.noreply.github.com> Date: Sun, 22 Dec 2024 17:36:43 +0100 Subject: [PATCH] make standoff entities in cache private and expose through methods --- .../responders/v2/OntologyResponderV2.scala | 20 +++++++++---------- .../repo/model/OntologyCacheData.scala | 8 +++++++- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/responders/v2/OntologyResponderV2.scala b/webapi/src/main/scala/org/knora/webapi/responders/v2/OntologyResponderV2.scala index f0917addd3..650b949b5f 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/v2/OntologyResponderV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/v2/OntologyResponderV2.scala @@ -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 @@ -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. diff --git a/webapi/src/main/scala/org/knora/webapi/slice/ontology/repo/model/OntologyCacheData.scala b/webapi/src/main/scala/org/knora/webapi/slice/ontology/repo/model/OntologyCacheData.scala index 54c24bab7d..ce81aafd4c 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/ontology/repo/model/OntologyCacheData.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/ontology/repo/model/OntologyCacheData.scala @@ -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. @@ -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(