diff --git a/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueMessagesV2.scala b/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueMessagesV2.scala index 2d8d08f6eb..a1638ce0e6 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueMessagesV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueMessagesV2.scala @@ -14,7 +14,6 @@ import java.time.Instant import java.util.UUID import scala.language.implicitConversions import scala.util.Try - import dsp.errors.AssertionException import dsp.errors.BadRequestException import dsp.errors.NotFoundException @@ -39,6 +38,7 @@ import org.knora.webapi.messages.v2.responder.* import org.knora.webapi.messages.v2.responder.resourcemessages.ReadResourceV2 import org.knora.webapi.messages.v2.responder.standoffmessages.* import org.knora.webapi.messages.v2.responder.valuemessages.ValueContentV2.FileInfo +import org.knora.webapi.messages.v2.responder.valuemessages.ValueMessagesV2Optics.FileValueContentV2Optics import org.knora.webapi.routing.RouteUtilZ import org.knora.webapi.routing.v2.AssetIngestState import org.knora.webapi.routing.v2.AssetIngestState.* @@ -680,6 +680,18 @@ sealed trait ValueContentV2 extends KnoraContentV2[ValueContentV2] with WithAsIs * Generates instances of value content classes (subclasses of [[ValueContentV2]]) from JSON-LD input. */ object ValueContentV2 { + def replaceCopyrightAndLicenceIfMissing( + license: Option[License], + copyrightAttribution: Option[CopyrightAttribution], + vc: ValueContentV2, + ): ValueContentV2 = vc match { + case fvc: FileValueContentV2 => + FileValueContentV2Optics.licenseOption + .filter(_.isEmpty) + .replace(license) + .andThen(FileValueContentV2Optics.copyRightAttributionOption.filter(_.isEmpty).replace(copyrightAttribution))(fvc) + case other => other + } final case class FileInfo(filename: IRI, metadata: FileMetadataSipiResponse) diff --git a/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueMessagesV2Optics.scala b/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueMessagesV2Optics.scala index 30d95edc97..0919d18093 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueMessagesV2Optics.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueMessagesV2Optics.scala @@ -6,10 +6,8 @@ package org.knora.webapi.messages.v2.responder.valuemessages import monocle.* -import monocle.Optional import monocle.macros.* -import org.knora.webapi.messages.v2.responder.resourcemessages.ReadResourceV2 import org.knora.webapi.slice.admin.domain.model.KnoraProject.CopyrightAttribution import org.knora.webapi.slice.admin.domain.model.KnoraProject.License diff --git a/webapi/src/main/scala/org/knora/webapi/responders/v2/ValuesResponderV2.scala b/webapi/src/main/scala/org/knora/webapi/responders/v2/ValuesResponderV2.scala index 852f48e14c..ffa189cdbf 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/v2/ValuesResponderV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/v2/ValuesResponderV2.scala @@ -5,12 +5,10 @@ package org.knora.webapi.responders.v2 -import monocle.PLens import zio.* import java.time.Instant import java.util.UUID - import dsp.errors.* import dsp.valueobjects.UuidUtil import org.knora.webapi.* @@ -34,13 +32,10 @@ import org.knora.webapi.messages.v2.responder.ontologymessages.* import org.knora.webapi.messages.v2.responder.resourcemessages.* import org.knora.webapi.messages.v2.responder.valuemessages.* import org.knora.webapi.messages.v2.responder.valuemessages.FileValueContentV2 -import org.knora.webapi.messages.v2.responder.valuemessages.ValueMessagesV2Optics.FileValueContentV2Optics +import org.knora.webapi.messages.v2.responder.valuemessages.ValueMessagesV2Optics.FileValueContentV2Optics.* import org.knora.webapi.responders.IriLocker import org.knora.webapi.responders.IriService import org.knora.webapi.responders.admin.PermissionsResponder -import org.knora.webapi.slice.admin.domain.model.KnoraProject -import org.knora.webapi.slice.admin.domain.model.KnoraProject.CopyrightAttribution -import org.knora.webapi.slice.admin.domain.model.KnoraProject.License import org.knora.webapi.slice.admin.domain.model.Permission import org.knora.webapi.slice.admin.domain.model.User import org.knora.webapi.slice.admin.domain.service.KnoraGroupRepo @@ -69,19 +64,6 @@ final case class ValuesResponderV2( permissionsResponder: PermissionsResponder, )(implicit val stringFormatter: StringFormatter) { - private def setCopyrightAndLicenceIfMissing( - license: Option[License], - copyrightAttribution: Option[CopyrightAttribution], - ): FileValueContentV2 => FileValueContentV2 = - FileValueContentV2Optics.licenseOption - .filter(_.isEmpty) - .replace(license) - .andThen( - FileValueContentV2Optics.copyRightAttributionOption - .filter(_.isEmpty) - .replace(copyrightAttribution), - ) - /** * Creates a new value in an existing resource. * @@ -109,11 +91,13 @@ final case class ValuesResponderV2( submittedInternalPropertyIri <- ZIO.attempt(valueToCreate.propertyIri.toOntologySchema(InternalSchema)) - submittedInternalValueContent: ValueContentV2 = - valueToCreate.valueContent.toOntologySchema(InternalSchema) match - case fileValueContent: FileValueContentV2 => - setCopyrightAndLicenceIfMissing(project.license, project.copyrightAttribution)(fileValueContent) - case other => other + submittedInternalValueContent = ValueContentV2 + .replaceCopyrightAndLicenceIfMissing( + project.license, + project.copyrightAttribution, + valueToCreate.valueContent, + ) + .toOntologySchema(InternalSchema) // Get ontology information about the submitted property. propertyInfoRequestForSubmittedProperty = @@ -742,12 +726,10 @@ final case class ValuesResponderV2( // Convert the submitted value content to the internal schema. project = resourceInfo.projectADM - submittedInternalValueContent: ValueContentV2 = - (updateValue.valueContent match - case fv: FileValueContentV2 => - setCopyrightAndLicenceIfMissing(project.license, project.copyrightAttribution)(fv) - case other => other - ).toOntologySchema(InternalSchema) + submittedInternalValueContent = + ValueContentV2 + .replaceCopyrightAndLicenceIfMissing(project.license, project.copyrightAttribution, updateValue.valueContent) + .toOntologySchema(InternalSchema) // Check that the object of the adjusted property (the value to be created, or the target of the link to be created) will have // the correct type for the adjusted property's knora-base:objectClassConstraint. @@ -1057,6 +1039,11 @@ final case class ValuesResponderV2( currentTime: Instant = valueCreationDate.getOrElse(Instant.now) // Generate a SPARQL update. + newValue: ValueContentV2 = ValueContentV2.replaceCopyrightAndLicenceIfMissing( + resourceInfo.projectADM.license, + resourceInfo.projectADM.copyrightAttribution, + newValueVersion, + ) sparqlUpdate = sparql.v2.txt.addValueVersion( dataNamedGraph = dataNamedGraph, resourceIri = resourceInfo.resourceIri, @@ -1064,10 +1051,10 @@ final case class ValuesResponderV2( currentValueIri = currentValue.valueIri, newValueIri = newValueIri, valueTypeIri = currentValue.valueContent.valueType, - value = newValueVersion, + value = newValue, valueCreator = valueCreator, valuePermissions = valuePermissions, - maybeComment = newValueVersion.comment, + maybeComment = newValue.comment, linkUpdates = standoffLinkUpdates, currentTime = currentTime, requestingUser = requestingUser.id,