From 56815a38febac3d3acd990b3b10b1045463644b3 Mon Sep 17 00:00:00 2001 From: Balduin Landolt <33053745+BalduinLandolt@users.noreply.github.com> Date: Wed, 6 Mar 2024 16:35:41 +0100 Subject: [PATCH] chore: Remove unused code from standoff responder (DEV-3264) (#3085) --- .../standoffmessages/StandoffMessagesV2.scala | 65 ------------------- .../responders/v2/StandoffResponderV2.scala | 65 ------------------- 2 files changed, 130 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/standoffmessages/StandoffMessagesV2.scala b/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/standoffmessages/StandoffMessagesV2.scala index 584352a1d6..49a387fa78 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/standoffmessages/StandoffMessagesV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/standoffmessages/StandoffMessagesV2.scala @@ -38,71 +38,6 @@ import org.knora.webapi.slice.admin.domain.model.User */ sealed trait StandoffResponderRequestV2 extends KnoraRequestV2 with RelayedMessage -/** - * Requests all standoff markup from a text value. A successful response will be a [[GetStandoffResponseV2]]. - * - * @param resourceIri the IRI of the resource containing the value. - * @param valueIri the IRI of the value. - * @param targetSchema the schema of the response. - * @param requestingUser the user making the request. - */ -case class GetStandoffRequestV2( - resourceIri: IRI, - valueIri: IRI, - targetSchema: ApiV2Schema, - requestingUser: User, -) extends StandoffResponderRequestV2 - -/** - * A response to a [[GetStandoffPageRequestV2]] or a [[GetRemainingStandoffFromTextValueRequestV2]], representing standoff - * tags from a text value. - * - * @param valueIri the IRI of the value. - * @param standoff standoff tags from the value. - * @param nextOffset the next available offset, if any. - */ -case class GetStandoffResponseV2(valueIri: IRI, standoff: Seq[StandoffTagV2]) extends KnoraJsonLDResponseV2 { - - /** - * Converts the response to a data structure that can be used to generate JSON-LD. - * - * @param targetSchema the Knora API schema to be used in the JSON-LD document. - * @return a [[JsonLDDocument]] representing the response. - */ - override def toJsonLDDocument( - targetSchema: ApiV2Schema, - appConfig: AppConfig, - schemaOptions: Set[Rendering], - ): JsonLDDocument = { - if (targetSchema != ApiV2Complex) { - throw AssertionException(s"Standoff is available only in the complex schema") - } - - val standoffInTargetSchema: Seq[StandoffTagV2] = standoff.map(_.toOntologySchema(targetSchema)) - val projectSpecificOntologiesUsed: Set[SmartIri] = - standoffInTargetSchema.flatMap(_.getOntologyIrisUsed).toSet.filter(!_.isKnoraBuiltInDefinitionIri) - val standoffAsJsonLD: Seq[JsonLDValue] = standoffInTargetSchema.map(_.toJsonLDValue(targetSchema = targetSchema)) - - val body: JsonLDObject = JsonLDObject( - Map( - JsonLDKeywords.GRAPH -> JsonLDArray(standoffAsJsonLD), - ), - ) - - val context: JsonLDObject = JsonLDUtil.makeContext( - fixedPrefixes = Map( - "rdf" -> OntologyConstants.Rdf.RdfPrefixExpansion, - "rdfs" -> OntologyConstants.Rdfs.RdfsPrefixExpansion, - "xsd" -> OntologyConstants.Xsd.XsdPrefixExpansion, - OntologyConstants.KnoraApi.KnoraApiOntologyLabel -> OntologyConstants.KnoraApiV2Complex.KnoraApiV2PrefixExpansion, - ), - knoraOntologiesNeedingPrefixes = projectSpecificOntologiesUsed, - ) - - JsonLDDocument(body = body, context = context) - } -} - /** * Represents a request to create a mapping between XML elements and attributes and standoff classes and properties. * A successful response will be a [[CreateMappingResponseV2]]. diff --git a/webapi/src/main/scala/org/knora/webapi/responders/v2/StandoffResponderV2.scala b/webapi/src/main/scala/org/knora/webapi/responders/v2/StandoffResponderV2.scala index 54276abd12..b45a7a4cd0 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/v2/StandoffResponderV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/v2/StandoffResponderV2.scala @@ -83,7 +83,6 @@ final case class StandoffResponderV2Live( * Receives a message of type [[StandoffResponderRequestV2]], and returns an appropriate response message. */ override def handle(msg: ResponderRequest): Task[Any] = msg match { - case getStandoffPageRequestV2: GetStandoffRequestV2 => getStandoffV2(getStandoffPageRequestV2) case CreateMappingRequestV2(metadata, xml, requestingUser, uuid) => createMappingV2( xml.xml, @@ -100,70 +99,6 @@ final case class StandoffResponderV2Live( case other => Responder.handleUnexpectedMessage(other, this.getClass.getName) } - private def getStandoffV2(getStandoffRequestV2: GetStandoffRequestV2): Task[GetStandoffResponseV2] = { - val resourceRequestSparql = - Construct( - sparql.v2.txt.getResourcePropertiesAndValues( - resourceIris = Seq(getStandoffRequestV2.resourceIri), - preview = false, - withDeleted = false, - maybePropertyIri = None, - maybeVersionDate = None, - queryAllNonStandoff = false, - queryStandoff = true, - maybeValueIri = Some(getStandoffRequestV2.valueIri), - ), - ) - - for { - resourceRequestResponse <- triplestore.query(resourceRequestSparql).flatMap(_.asExtended) - - // separate resources and values - mainResourcesAndValueRdfData = - constructResponseUtilV2.splitMainResourcesAndValueRdfData( - resourceRequestResponse, - getStandoffRequestV2.requestingUser, - ) - - readResourcesSequenceV2 <- - constructResponseUtilV2.createApiResponse( - mainResourcesAndValueRdfData = mainResourcesAndValueRdfData, - orderByResourceIri = Seq(getStandoffRequestV2.resourceIri), - pageSizeBeforeFiltering = 1, // doesn't matter because we're not doing paging - mappings = Map.empty, - queryStandoff = false, - calculateMayHaveMoreResults = false, - versionDate = None, - targetSchema = getStandoffRequestV2.targetSchema, - requestingUser = getStandoffRequestV2.requestingUser, - ) - - readResourceV2 = readResourcesSequenceV2.toResource(getStandoffRequestV2.resourceIri) - - valueObj = - readResourceV2.values.values.flatten - .find(_.valueIri == getStandoffRequestV2.valueIri) - .getOrElse( - throw NotFoundException( - s"Value <${getStandoffRequestV2.valueIri}> not found in resource <${getStandoffRequestV2.resourceIri}> (maybe you do not have permission to see it, or it is marked as deleted)", - ), - ) - - textValueObj = - valueObj match { - case textVal: ReadTextValueV2 => textVal - case _ => - throw BadRequestException( - s"Value <${getStandoffRequestV2.valueIri}> not found in resource <${getStandoffRequestV2.resourceIri}> is not a text value", - ) - } - - } yield GetStandoffResponseV2( - valueIri = textValueObj.valueIri, - standoff = textValueObj.valueContent.standoff, - ) - } - /** * If not already in the cache, retrieves a `knora-base:XSLTransformation` in the triplestore and requests the corresponding XSL transformation file from Sipi. *