Skip to content

Commit

Permalink
chore: Remove unused code from standoff responder (DEV-3264) (#3085)
Browse files Browse the repository at this point in the history
  • Loading branch information
BalduinLandolt authored Mar 6, 2024
1 parent 70ea9ba commit 56815a3
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
*
Expand Down

0 comments on commit 56815a3

Please sign in to comment.