From 43b342e6642bc5985e5df87084fe5b27e8865ea2 Mon Sep 17 00:00:00 2001 From: Balduin Landolt <33053745+BalduinLandolt@users.noreply.github.com> Date: Sat, 15 Jun 2024 10:05:18 +0200 Subject: [PATCH] refactor: Replace reused datastructures with specific ones for createNewResource.scala.txt template (#3277) --- .../twirl/SparqlTemplateLinkUpdate.scala | 91 ++++- .../resources/CreateResourceV2Handler.scala | 161 ++++++++- .../sparql/v2/createNewResource.scala.txt | 310 +++++++----------- .../repo/service/ResourcesRepoLiveSpec.scala | 22 +- 4 files changed, 377 insertions(+), 207 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/messages/twirl/SparqlTemplateLinkUpdate.scala b/webapi/src/main/scala/org/knora/webapi/messages/twirl/SparqlTemplateLinkUpdate.scala index 68248028ec..04e1614589 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/twirl/SparqlTemplateLinkUpdate.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/twirl/SparqlTemplateLinkUpdate.scala @@ -10,7 +10,8 @@ import java.util.UUID import org.knora.webapi.IRI import org.knora.webapi.messages.SmartIri -import org.knora.webapi.messages.v2.responder.valuemessages.ValueContentV2 +import org.knora.webapi.messages.util.CalendarNameV2 +import org.knora.webapi.messages.util.DatePrecisionV2 /** * Contains instructions that can be given to a SPARQL template for updating direct links and `knora-base:LinkValue` @@ -64,11 +65,91 @@ final case class NewLinkValueInfo( final case class NewValueInfo( resourceIri: IRI, propertyIri: IRI, - value: ValueContentV2, - newValueIri: IRI, - newValueUUID: UUID, - valueCreator: IRI, + valueIri: IRI, + valueTypeIri: IRI, + valueUUID: UUID, + value: TypeSpecificValueInfo, valuePermissions: String, + valueCreator: IRI, creationDate: Instant, valueHasOrder: Int, + valueHasString: String, + comment: Option[String], +) + +final case class StandoffAttribute( + propertyIri: IRI, + value: String, +) + +final case class StandoffTagInfo( + standoffTagClassIri: IRI, + standoffTagInstanceIri: IRI, + startParentIri: Option[IRI], + endParentIri: Option[IRI], + uuid: UUID, + originalXMLID: Option[String], + startIndex: Int, + endIndex: Option[Int], + startPosition: Int, + endPosition: Int, + attributes: Seq[StandoffAttribute], ) + +enum TypeSpecificValueInfo { + case LinkValueInfo(referredResourceIri: IRI) + case UnformattedTextValueInfo(valueHasLanguage: Option[String]) + case FormattedTextValueInfo( + valueHasLanguage: Option[String], + mappingIri: IRI, + maxStandoffStartIndex: Int, + standoff: Seq[StandoffTagInfo], + ) + case IntegerValueInfo(valueHasInteger: Int) + case DecimalValueInfo(valueHasDecimal: BigDecimal) + case BooleanValueInfo(valueHasBoolean: Boolean) + case UriValueInfo(valueHasUri: String) + case DateValueInfo( + valueHasStartJDN: Int, + valueHasEndJDN: Int, + valueHasStartPrecision: DatePrecisionV2, + valueHasEndPrecision: DatePrecisionV2, + valueHasCalendar: CalendarNameV2, + ) + case ColorValueInfo(valueHasColor: String) + case GeomValueInfo(valueHasGeometry: String) + case StillImageFileValueInfo( + internalFilename: String, + internalMimeType: String, + originalFilename: Option[String], + originalMimeType: Option[String], + dimX: Int, + dimY: Int, + ) + case StillImageExternalFileValueInfo( + internalFilename: String, + internalMimeType: String, + originalFilename: Option[String], + originalMimeType: Option[String], + externalUrl: String, + ) + case DocumentFileValueInfo( + internalFilename: String, + internalMimeType: String, + originalFilename: Option[String], + originalMimeType: Option[String], + dimX: Option[Int], + dimY: Option[Int], + pageCount: Option[Int], + ) + case OtherFileValueInfo( + internalFilename: String, + internalMimeType: String, + originalFilename: Option[String], + originalMimeType: Option[String], + ) + case HierarchicalListValueInfo(valueHasListNode: IRI) + case IntervalValueInfo(valueHasIntervalStart: BigDecimal, valueHasIntervalEnd: BigDecimal) + case TimeValueInfo(valueHasTimeStamp: Instant) + case GeonameValueInfo(valueHasGeonameCode: String) +} diff --git a/webapi/src/main/scala/org/knora/webapi/responders/v2/resources/CreateResourceV2Handler.scala b/webapi/src/main/scala/org/knora/webapi/responders/v2/resources/CreateResourceV2Handler.scala index c418d7f235..c9411c859f 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/v2/resources/CreateResourceV2Handler.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/v2/resources/CreateResourceV2Handler.scala @@ -16,7 +16,6 @@ import org.knora.webapi.* import org.knora.webapi.config.AppConfig import org.knora.webapi.core.MessageRelay import org.knora.webapi.messages.* -import org.knora.webapi.messages.IriConversions.* import org.knora.webapi.messages.admin.responder.permissionsmessages.DefaultObjectAccessPermissionsStringForResourceClassGetADM import org.knora.webapi.messages.admin.responder.permissionsmessages.DefaultObjectAccessPermissionsStringResponseADM import org.knora.webapi.messages.admin.responder.permissionsmessages.PermissionADM @@ -24,6 +23,9 @@ import org.knora.webapi.messages.admin.responder.permissionsmessages.PermissionT import org.knora.webapi.messages.admin.responder.permissionsmessages.ResourceCreateOperation import org.knora.webapi.messages.twirl.NewLinkValueInfo import org.knora.webapi.messages.twirl.NewValueInfo +import org.knora.webapi.messages.twirl.StandoffAttribute +import org.knora.webapi.messages.twirl.StandoffTagInfo +import org.knora.webapi.messages.twirl.TypeSpecificValueInfo.* import org.knora.webapi.messages.util.* import org.knora.webapi.messages.util.PermissionUtilADM.AGreaterThanB import org.knora.webapi.messages.util.PermissionUtilADM.PermissionComparisonResult @@ -449,16 +451,167 @@ final case class CreateResourceV2Handler( // Make a creation date for the value. If a custom creation date is given for a value, consider that otherwise // use resource creation date for the value. valueCreationDate: Instant = valueToCreate.customValueCreationDate.getOrElse(creationDate) + + valueInfo <- + valueToCreate.valueContent match + case DateValueContentV2( + _, + valueHasStartJDN, + valueHasEndJDN, + valueHasStartPrecision, + valueHasEndPrecision, + valueHasCalendar, + _, + ) => + ZIO.succeed( + DateValueInfo( + valueHasStartJDN = valueHasStartJDN, + valueHasEndJDN = valueHasEndJDN, + valueHasStartPrecision = valueHasStartPrecision, + valueHasEndPrecision = valueHasEndPrecision, + valueHasCalendar = valueHasCalendar, + ), + ) + case TextValueContentV2(_, _, valueHasLanguage, _, None, _, _, _) => + ZIO.succeed(UnformattedTextValueInfo(valueHasLanguage)) + case tv @ TextValueContentV2(_, _, valueHasLanguage, _, Some(mappingIri), _, _, _) => + val standoffInfo = tv + .prepareForSparqlInsert(newValueIri) + .map(standoffTag => + StandoffTagInfo( + standoffTagClassIri = standoffTag.standoffNode.standoffTagClassIri.toString(), + standoffTagInstanceIri = standoffTag.standoffTagInstanceIri, + startParentIri = standoffTag.startParentIri, + endParentIri = standoffTag.endParentIri, + uuid = standoffTag.standoffNode.uuid, + originalXMLID = standoffTag.standoffNode.originalXMLID, + startIndex = standoffTag.standoffNode.startIndex, + endIndex = standoffTag.standoffNode.endIndex, + startPosition = standoffTag.standoffNode.startPosition, + endPosition = standoffTag.standoffNode.endPosition, + attributes = standoffTag.standoffNode.attributes + .map(attr => StandoffAttribute(attr.standoffPropertyIri.toString(), attr.rdfValue)), + ), + ) + ZIO + .fromOption(tv.computedMaxStandoffStartIndex) + .orElseFail(StandoffInternalException("Max standoff start index not computed")) + .map(standoffStartIndex => + FormattedTextValueInfo(valueHasLanguage, mappingIri, standoffStartIndex, standoffInfo), + ) + case IntegerValueContentV2(_, valueHasInteger, _) => + ZIO.succeed(IntegerValueInfo(valueHasInteger)) + case DecimalValueContentV2(_, valueHasDecimal, _) => + ZIO.succeed(DecimalValueInfo(valueHasDecimal)) + case BooleanValueContentV2(_, valueHasBoolean, _) => + ZIO.succeed(BooleanValueInfo(valueHasBoolean)) + case GeomValueContentV2(_, valueHasGeometry, _) => + ZIO.succeed(GeomValueInfo(valueHasGeometry)) + case IntervalValueContentV2(_, valueHasIntervalStart, valueHasIntervalEnd, _) => + ZIO.succeed(IntervalValueInfo(valueHasIntervalStart, valueHasIntervalEnd)) + case TimeValueContentV2(_, valueHasTimeStamp, _) => + ZIO.succeed(TimeValueInfo(valueHasTimeStamp)) + case HierarchicalListValueContentV2(_, valueHasListNode, listNodeLabel, _) => + ZIO.succeed(HierarchicalListValueInfo(valueHasListNode)) + case ColorValueContentV2(_, valueHasColor, _) => + ZIO.succeed(ColorValueInfo(valueHasColor)) + case UriValueContentV2(_, valueHasUri, _) => + ZIO.succeed(UriValueInfo(valueHasUri)) + case GeonameValueContentV2(_, valueHasGeonameCode, _) => + ZIO.succeed(GeonameValueInfo(valueHasGeonameCode)) + case StillImageFileValueContentV2(_, fileValue, dimX, dimY, _) => + ZIO.succeed( + StillImageFileValueInfo( + internalFilename = fileValue.internalFilename, + internalMimeType = fileValue.internalMimeType, + originalFilename = fileValue.originalFilename, + originalMimeType = fileValue.originalMimeType, + dimX = dimX, + dimY = dimY, + ), + ) + case StillImageExternalFileValueContentV2(_, fileValue, externalUrl, _) => + ZIO.succeed( + StillImageExternalFileValueInfo( + internalFilename = fileValue.internalFilename, + internalMimeType = fileValue.internalMimeType, + originalFilename = fileValue.originalFilename, + originalMimeType = fileValue.originalMimeType, + externalUrl = externalUrl.value.toString(), + ), + ) + case DocumentFileValueContentV2(_, fileValue, pageCount, dimX, dimY, _) => + ZIO.succeed( + DocumentFileValueInfo( + internalFilename = fileValue.internalFilename, + internalMimeType = fileValue.internalMimeType, + originalFilename = fileValue.originalFilename, + originalMimeType = fileValue.originalMimeType, + dimX = dimX, + dimY = dimY, + pageCount = pageCount, + ), + ) + case ArchiveFileValueContentV2(_, fileValue, _) => + ZIO.succeed( + OtherFileValueInfo( + internalFilename = fileValue.internalFilename, + internalMimeType = fileValue.internalMimeType, + originalFilename = fileValue.originalFilename, + originalMimeType = fileValue.originalMimeType, + ), + ) + case TextFileValueContentV2(_, fileValue, _) => + ZIO.succeed( + OtherFileValueInfo( + internalFilename = fileValue.internalFilename, + internalMimeType = fileValue.internalMimeType, + originalFilename = fileValue.originalFilename, + originalMimeType = fileValue.originalMimeType, + ), + ) + case AudioFileValueContentV2(_, fileValue, _) => + ZIO.succeed( + OtherFileValueInfo( + internalFilename = fileValue.internalFilename, + internalMimeType = fileValue.internalMimeType, + originalFilename = fileValue.originalFilename, + originalMimeType = fileValue.originalMimeType, + ), + ) + case MovingImageFileValueContentV2(_, fileValue, _) => + ZIO.succeed( + OtherFileValueInfo( + internalFilename = fileValue.internalFilename, + internalMimeType = fileValue.internalMimeType, + originalFilename = fileValue.originalFilename, + originalMimeType = fileValue.originalMimeType, + ), + ) + case LinkValueContentV2( + _, + referredResourceIri, + referredResourceExists, + isIncomingLink, + nestedResource, + _, + ) => + ZIO.succeed(LinkValueInfo(referredResourceIri)) + case _: DeletedValueContentV2 => ZIO.fail(BadRequestException("Deleted values cannot be created")) + } yield NewValueInfo( resourceIri = resourceIri, propertyIri = propertyIri.toIri, - value = valueToCreate.valueContent, - newValueIri = newValueIri, - newValueUUID = newValueUUID, + value = valueInfo, + valueIri = newValueIri, + valueTypeIri = valueToCreate.valueContent.valueType.toString(), + valueUUID = newValueUUID, valueCreator = requestingUser.id, valuePermissions = valueToCreate.permissions, creationDate = valueCreationDate, valueHasOrder = valueHasOrder, + valueHasString = valueToCreate.valueContent.valueHasString, + comment = valueToCreate.valueContent.comment, ) } } yield ResourceReadyToCreate( diff --git a/webapi/src/main/twirl/org/knora/webapi/messages/twirl/queries/sparql/v2/createNewResource.scala.txt b/webapi/src/main/twirl/org/knora/webapi/messages/twirl/queries/sparql/v2/createNewResource.scala.txt index f09e9782d9..01362fb2e6 100644 --- a/webapi/src/main/twirl/org/knora/webapi/messages/twirl/queries/sparql/v2/createNewResource.scala.txt +++ b/webapi/src/main/twirl/org/knora/webapi/messages/twirl/queries/sparql/v2/createNewResource.scala.txt @@ -5,12 +5,9 @@ @import java.time.Instant @import org.knora.webapi.IRI -@import org.knora.webapi.messages.v2.responder.valuemessages._ -@import org.knora.webapi.messages.twirl.NewLinkValueInfo -@import org.knora.webapi.messages.twirl.NewValueInfo +@import org.knora.webapi.messages.twirl._ +@import org.knora.webapi.messages.twirl.TypeSpecificValueInfo._ @import dsp.valueobjects.UuidUtil -@import dsp.errors.SparqlGenerationException -@import java.util.UUID @** * Creates a new resource. @@ -44,254 +41,195 @@ INSERT DATA { knora-base:creationDate "@creationDate"^^xsd:dateTime . @for(newValueInfo <- newValueInfos) { - # Value: @newValueInfo.newValueIri + # Value: @newValueInfo.valueIri # Property: @newValueInfo.propertyIri @* Construct the value. *@ - <@newValueInfo.newValueIri> rdf:type <@newValueInfo.value.valueType> ; + <@newValueInfo.valueIri> rdf:type <@newValueInfo.valueTypeIri> ; knora-base:isDeleted false ; - knora-base:valueHasString """@newValueInfo.value.valueHasString""" ; - knora-base:valueHasUUID "@{UuidUtil.base64Encode(newValueInfo.newValueUUID)}" . - + knora-base:valueHasString """@newValueInfo.valueHasString""" ; + knora-base:valueHasUUID "@{UuidUtil.base64Encode(newValueInfo.valueUUID)}" . @newValueInfo.value match { - case linkValueContentV2: LinkValueContentV2 => { - - <@newValueInfo.resourceIri> <@newValueInfo.propertyIri.stripSuffix("Value")> <@linkValueContentV2.referredResourceIri> . + case linkValue: LinkValueInfo => { + <@newValueInfo.resourceIri> <@newValueInfo.propertyIri.stripSuffix("Value")> <@linkValue.referredResourceIri> . - <@newValueInfo.newValueIri> rdf:subject <@newValueInfo.resourceIri> ; + <@newValueInfo.valueIri> rdf:subject <@newValueInfo.resourceIri> ; rdf:predicate <@newValueInfo.propertyIri.stripSuffix("Value")> ; - rdf:object <@linkValueContentV2.referredResourceIri> ; + rdf:object <@linkValue.referredResourceIri> ; knora-base:valueHasRefCount 1 . - } - case textValue: TextValueContentV2 => { - - @if(!textValue.valueHasLanguage.isEmpty) { - <@newValueInfo.newValueIri> knora-base:valueHasLanguage """@textValue.valueHasLanguage.get""" . + case textValue: UnformattedTextValueInfo => { + @textValue.valueHasLanguage.map { language => + <@newValueInfo.valueIri> knora-base:valueHasLanguage """@language""" . } + } - @if(textValue.standoff.nonEmpty) { - - @* Create a Standoff node for each standoff tag. *@ - - @textValue.mappingIri match { - case Some(definedMappingIri) => { - <@newValueInfo.newValueIri> knora-base:valueHasMapping <@definedMappingIri> . - } - - case None => {} - } - - <@newValueInfo.newValueIri> knora-base:valueHasMaxStandoffStartIndex @textValue.computedMaxStandoffStartIndex.get . - - @for((createStandoff: CreateStandoffTagV2InTriplestore, standoffNodeIndex) <- textValue.prepareForSparqlInsert(newValueInfo.newValueIri).zipWithIndex) { - - <@newValueInfo.newValueIri> knora-base:valueHasStandoff <@createStandoff.standoffTagInstanceIri> . - - <@createStandoff.standoffTagInstanceIri> - - @* - - Check for optional standoff properties - - *@ - - @if(createStandoff.standoffNode.endIndex.isDefined) { - knora-base:standoffTagHasEndIndex @createStandoff.standoffNode.endIndex.get ; - } - - @if(createStandoff.startParentIri.isDefined) { - knora-base:standoffTagHasStartParent <@createStandoff.startParentIri.get> ; - } - - @if(createStandoff.endParentIri.isDefined) { - knora-base:standoffTagHasEndParent <@createStandoff.endParentIri.get> ; - } - - @if(createStandoff.standoffNode.originalXMLID.isDefined) { - knora-base:standoffTagHasOriginalXMLID """@createStandoff.standoffNode.originalXMLID.get""" ; - } - - @* - - Handle standoff class specific standoff properties - - *@ - @for(createProperty <- createStandoff.standoffNode.attributes) { + case textValue: FormattedTextValueInfo => { + @textValue.valueHasLanguage.map { language => + <@newValueInfo.valueIri> knora-base:valueHasLanguage """@language""" . + } + <@newValueInfo.valueIri> knora-base:valueHasMapping <@textValue.mappingIri> . + <@newValueInfo.valueIri> knora-base:valueHasMaxStandoffStartIndex @textValue.maxStandoffStartIndex . - <@createProperty.standoffPropertyIri> @createProperty.rdfValue ; + @* Create a Standoff node for each standoff tag. *@ + @for(createStandoff: StandoffTagInfo <- textValue.standoff) { - } + <@newValueInfo.valueIri> knora-base:valueHasStandoff <@createStandoff.standoffTagInstanceIri> . - knora-base:standoffTagHasStartIndex @createStandoff.standoffNode.startIndex ; - knora-base:standoffTagHasUUID "@{UuidUtil.base64Encode(createStandoff.standoffNode.uuid)}" ; - knora-base:standoffTagHasStart @createStandoff.standoffNode.startPosition ; - knora-base:standoffTagHasEnd @createStandoff.standoffNode.endPosition ; - rdf:type <@createStandoff.standoffNode.standoffTagClassIri> . + <@createStandoff.standoffTagInstanceIri> + @* + Check for optional standoff properties + *@ + @createStandoff.endIndex.map { index => + knora-base:standoffTagHasEndIndex @index ; + } + @createStandoff.startParentIri.map { iri => + knora-base:standoffTagHasStartParent <@iri> ; + } + @createStandoff.endParentIri.map { iri => + knora-base:standoffTagHasEndParent <@iri> ; + } + @createStandoff.originalXMLID.map { id => + knora-base:standoffTagHasOriginalXMLID """@id""" ; + } - } + @* + Handle standoff class specific standoff properties + *@ + @for(createProperty <- createStandoff.attributes) { + <@createProperty.propertyIri> @createProperty.value ; + } + knora-base:standoffTagHasStartIndex @createStandoff.startIndex ; + knora-base:standoffTagHasUUID "@{UuidUtil.base64Encode(createStandoff.uuid)}" ; + knora-base:standoffTagHasStart @createStandoff.startPosition ; + knora-base:standoffTagHasEnd @createStandoff.endPosition ; + rdf:type <@createStandoff.standoffTagClassIri> . } } - case intValue: IntegerValueContentV2 => { - - <@newValueInfo.newValueIri> knora-base:valueHasInteger @intValue.valueHasInteger . - + case intValue: IntegerValueInfo => { + <@newValueInfo.valueIri> knora-base:valueHasInteger @intValue.valueHasInteger . } - case decimalValue: DecimalValueContentV2 => { - - <@newValueInfo.newValueIri> knora-base:valueHasDecimal "@decimalValue.valueHasDecimal"^^xsd:decimal . - + case decimalValue: DecimalValueInfo => { + <@newValueInfo.valueIri> knora-base:valueHasDecimal "@decimalValue.valueHasDecimal"^^xsd:decimal . } - case booleanValue: BooleanValueContentV2 => { - - <@newValueInfo.newValueIri> knora-base:valueHasBoolean @booleanValue.valueHasBoolean . - + case booleanValue: BooleanValueInfo => { + <@newValueInfo.valueIri> knora-base:valueHasBoolean @booleanValue.valueHasBoolean . } - case uriValue: UriValueContentV2 => { - - <@newValueInfo.newValueIri> knora-base:valueHasUri """@uriValue.valueHasUri"""^^xsd:anyURI . - + case uriValue: UriValueInfo => { + <@newValueInfo.valueIri> knora-base:valueHasUri """@uriValue.valueHasUri"""^^xsd:anyURI . } - case dateValue: DateValueContentV2 => { - - <@newValueInfo.newValueIri> knora-base:valueHasStartJDN @dateValue.valueHasStartJDN ; + case dateValue: DateValueInfo => { + <@newValueInfo.valueIri> knora-base:valueHasStartJDN @dateValue.valueHasStartJDN ; knora-base:valueHasEndJDN @dateValue.valueHasEndJDN ; knora-base:valueHasStartPrecision "@dateValue.valueHasStartPrecision" ; knora-base:valueHasEndPrecision "@dateValue.valueHasEndPrecision" ; knora-base:valueHasCalendar "@dateValue.valueHasCalendar" . - } - case colorValue: ColorValueContentV2 => { - - <@newValueInfo.newValueIri> knora-base:valueHasColor """@colorValue.valueHasColor""" . - + case colorValue: ColorValueInfo => { + <@newValueInfo.valueIri> knora-base:valueHasColor """@colorValue.valueHasColor""" . } - case geometryValue: GeomValueContentV2 => { - - <@newValueInfo.newValueIri> knora-base:valueHasGeometry """@geometryValue.valueHasGeometry""" . - + case geometryValue: GeomValueInfo => { + <@newValueInfo.valueIri> knora-base:valueHasGeometry """@geometryValue.valueHasGeometry""" . } - case fileValueContentV2: FileValueContentV2 => { - <@newValueInfo.newValueIri> knora-base:internalFilename """@fileValueContentV2.fileValue.internalFilename""" ; - knora-base:internalMimeType """@fileValueContentV2.fileValue.internalMimeType""" . - - @fileValueContentV2.fileValue.originalFilename match { - case Some(definedOriginalFilename) => { - <@newValueInfo.newValueIri> knora-base:originalFilename """@definedOriginalFilename""" . - } - - case None => {} + case fileValue: StillImageFileValueInfo => { + <@newValueInfo.valueIri> knora-base:internalFilename """@fileValue.internalFilename""" ; + knora-base:internalMimeType """@fileValue.internalMimeType""" ; + knora-base:dimX @fileValue.dimX ; + knora-base:dimY @fileValue.dimY . + @fileValue.originalFilename.map { originalFilename => + <@newValueInfo.valueIri> knora-base:originalFilename """@originalFilename""" . } - - @fileValueContentV2.fileValue.originalMimeType match { - case Some(definedOriginalMimeType) => { - <@newValueInfo.newValueIri> knora-base:originalMimeType """@definedOriginalMimeType""" . - } - - case None => {} + @fileValue.originalMimeType.map { originalMimeType => + <@newValueInfo.valueIri> knora-base:originalMimeType """@originalMimeType""" . } + } - @fileValueContentV2 match { - case stillImageFileValue: StillImageFileValueContentV2 => { - <@newValueInfo.newValueIri> knora-base:dimX @stillImageFileValue.dimX ; - knora-base:dimY @stillImageFileValue.dimY . - } - - case stillImageFileValue: StillImageExternalFileValueContentV2 => { - <@newValueInfo.newValueIri> knora-base:externalUrl """@stillImageFileValue.externalUrl.value.toString""" . - } - - case documentFileValue: DocumentFileValueContentV2 => { - @documentFileValue.dimX match { - case Some(definedDimX) => { - <@newValueInfo.newValueIri> knora-base:dimX @definedDimX . - } - - case None => {} - } - - @documentFileValue.dimY match { - case Some(definedDimY) => { - <@newValueInfo.newValueIri> knora-base:dimY @definedDimY . - } - - case None => {} - } - - @documentFileValue.pageCount match { - case Some(definedPageCount) => { - <@newValueInfo.newValueIri> knora-base:pageCount @definedPageCount . - } - - case None => {} - } - } - - case _ => {} + case fileValue: StillImageExternalFileValueInfo => { + <@newValueInfo.valueIri> knora-base:internalFilename """@fileValue.internalFilename""" ; + knora-base:internalMimeType """@fileValue.internalMimeType""" ; + knora-base:externalUrl """@fileValue.externalUrl""" . + @fileValue.originalFilename.map { originalFilename => + <@newValueInfo.valueIri> knora-base:originalFilename """@originalFilename""" . + } + @fileValue.originalMimeType.map { originalMimeType => + <@newValueInfo.valueIri> knora-base:originalMimeType """@originalMimeType""" . } } - case listValue: HierarchicalListValueContentV2 => { - - <@newValueInfo.newValueIri> knora-base:valueHasListNode <@listValue.valueHasListNode> . - + case fileValue: DocumentFileValueInfo => { + <@newValueInfo.valueIri> knora-base:internalFilename """@fileValue.internalFilename""" ; + knora-base:internalMimeType """@fileValue.internalMimeType""" . + @fileValue.originalFilename.map { originalFilename => + <@newValueInfo.valueIri> knora-base:originalFilename """@originalFilename""" . + } + @fileValue.originalMimeType.map { originalMimeType => + <@newValueInfo.valueIri> knora-base:originalMimeType """@originalMimeType""" . + } + @fileValue.dimX.map { dimX => + <@newValueInfo.valueIri> knora-base:dimX @dimX . + } + @fileValue.dimY.map { dimY => + <@newValueInfo.valueIri> knora-base:dimY @dimY . + } + @fileValue.pageCount.map { pageCount => + <@newValueInfo.valueIri> knora-base:pageCount @pageCount . + } } - case intervalValue: IntervalValueContentV2 => { - - <@newValueInfo.newValueIri> knora-base:valueHasIntervalStart "@intervalValue.valueHasIntervalStart"^^xsd:decimal ; - knora-base:valueHasIntervalEnd "@intervalValue.valueHasIntervalEnd"^^xsd:decimal . - + case fileValue: OtherFileValueInfo => { + <@newValueInfo.valueIri> knora-base:internalFilename """@fileValue.internalFilename""" ; + knora-base:internalMimeType """@fileValue.internalMimeType""" . + @fileValue.originalFilename.map { originalFilename => + <@newValueInfo.valueIri> knora-base:originalFilename """@originalFilename""" . + } + @fileValue.originalMimeType.map { originalMimeType => + <@newValueInfo.valueIri> knora-base:originalMimeType """@originalMimeType""" . + } } - case timeValue: TimeValueContentV2 => { - - <@newValueInfo.newValueIri> knora-base:valueHasTimeStamp "@timeValue.valueHasTimeStamp"^^xsd:dateTime . - + case listValue: HierarchicalListValueInfo => { + <@newValueInfo.valueIri> knora-base:valueHasListNode <@listValue.valueHasListNode> . } - case geonameValue: GeonameValueContentV2 => { - - <@newValueInfo.newValueIri> knora-base:valueHasGeonameCode """@geonameValue.valueHasGeonameCode""" . + case intervalValue: IntervalValueInfo => { + <@newValueInfo.valueIri> knora-base:valueHasIntervalStart "@intervalValue.valueHasIntervalStart"^^xsd:decimal ; + knora-base:valueHasIntervalEnd "@intervalValue.valueHasIntervalEnd"^^xsd:decimal . + } + case timeValue: TimeValueInfo => { + <@newValueInfo.valueIri> knora-base:valueHasTimeStamp "@timeValue.valueHasTimeStamp"^^xsd:dateTime . } - case other => { - @{throw SparqlGenerationException(s"Value object $other is not supported in this SPARQL template"); ()} + case geonameValue: GeonameValueInfo => { + <@newValueInfo.valueIri> knora-base:valueHasGeonameCode """@geonameValue.valueHasGeonameCode""" . } } @* Insert the value's comment, if given. *@ - @newValueInfo.value.comment match { - case Some(commentStr) => { - <@newValueInfo.newValueIri> knora-base:valueHasComment """@commentStr""" . - } - - case None => {} + @newValueInfo.comment.map { commentStr => + <@newValueInfo.valueIri> knora-base:valueHasComment """@commentStr""" . } - <@newValueInfo.newValueIri> knora-base:attachedToUser <@newValueInfo.valueCreator> ; + <@newValueInfo.valueIri> knora-base:attachedToUser <@newValueInfo.valueCreator> ; knora-base:hasPermissions "@newValueInfo.valuePermissions"^^xsd:string ; knora-base:valueHasOrder @newValueInfo.valueHasOrder ; knora-base:valueCreationDate "@newValueInfo.creationDate"^^xsd:dateTime . - - @* Attach the value to the resource. *@ - <@newValueInfo.resourceIri> <@newValueInfo.propertyIri> <@newValueInfo.newValueIri> . + <@newValueInfo.resourceIri> <@newValueInfo.propertyIri> <@newValueInfo.valueIri> . } diff --git a/webapi/src/test/scala/org/knora/webapi/slice/resources/repo/service/ResourcesRepoLiveSpec.scala b/webapi/src/test/scala/org/knora/webapi/slice/resources/repo/service/ResourcesRepoLiveSpec.scala index 2839995b21..28833bf13f 100644 --- a/webapi/src/test/scala/org/knora/webapi/slice/resources/repo/service/ResourcesRepoLiveSpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/slice/resources/repo/service/ResourcesRepoLiveSpec.scala @@ -12,11 +12,11 @@ import java.time.Instant import java.util.UUID import dsp.valueobjects.UuidUtil -import org.knora.webapi.ApiV2Complex +import org.knora.webapi.messages.OntologyConstants import org.knora.webapi.messages.StringFormatter import org.knora.webapi.messages.twirl.NewLinkValueInfo import org.knora.webapi.messages.twirl.NewValueInfo -import org.knora.webapi.messages.v2.responder.valuemessages.IntegerValueContentV2 +import org.knora.webapi.messages.twirl.TypeSpecificValueInfo import org.knora.webapi.slice.resourceinfo.domain.InternalIri import org.knora.webapi.store.triplestore.api.TriplestoreService.Queries.Update @@ -109,13 +109,16 @@ object ResourcesRepoLiveSpec extends ZIOSpecDefault { NewValueInfo( resourceIri = resourceIri, propertyIri = "fooProperty", - value = IntegerValueContentV2(ApiV2Complex, 42), - newValueIri = valueIri, - newValueUUID = uuid, - valueCreator = valueCreator, + valueIri = valueIri, + valueTypeIri = OntologyConstants.KnoraBase.IntValue, + valueUUID = uuid, + value = TypeSpecificValueInfo.IntegerValueInfo(42), valuePermissions = valuePermissions, + valueCreator = valueCreator, creationDate = valueCreationDate, valueHasOrder = 1, + valueHasString = "42", + comment = None, ), ), linkUpdates = Seq.empty, @@ -144,16 +147,13 @@ object ResourcesRepoLiveSpec extends ZIOSpecDefault { | # Property: fooProperty | | - | rdf:type ; + | rdf:type ; | knora-base:isDeleted false ; | knora-base:valueHasString \"\"\"42\"\"\" ; | knora-base:valueHasUUID \"$uuidEncoded\" . | - | | - | | knora-base:valueHasInteger 42 . - | | | | @@ -164,8 +164,6 @@ object ResourcesRepoLiveSpec extends ZIOSpecDefault { | knora-base:valueHasOrder 1 ; | knora-base:valueCreationDate \"2024-01-01T10:00:00.673298Z\"^^xsd:dateTime . | - | - | | | . |