diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index b2ace26545..7bb4d8b458 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -6,3 +6,6 @@ # Scala Steward: Reformat with scalafmt 3.8.3 a5523a0b097ee63e511bff6abf018d5ac6740288 + +# Scala Steward: Reformat with scalafmt 3.8.4 +fb8d6ba614e93997749443355c7e59cdb12edf58 diff --git a/.scalafmt.conf b/.scalafmt.conf index 9b020a3a98..f9ae3a4f77 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version = "3.8.3" +version = "3.8.4" runner.dialect = scala3 maxColumn = 120 align.preset = most diff --git a/integration/src/test/scala/org/knora/webapi/models/filemodels/FileModelUtil.scala b/integration/src/test/scala/org/knora/webapi/models/filemodels/FileModelUtil.scala index d081fbbb97..0f4c3b7fc3 100644 --- a/integration/src/test/scala/org/knora/webapi/models/filemodels/FileModelUtil.scala +++ b/integration/src/test/scala/org/knora/webapi/models/filemodels/FileModelUtil.scala @@ -207,7 +207,7 @@ object FileModelUtil { } val lines = ontologies.toList .map(x => s""" "${x._1}": "${x._2}\"""") - .reduce({ (a, b) => a + ",\n" + b }) + .reduce((a, b) => a + ",\n" + b) s"""|"@context" : { |$lines | } diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 2f3ad71520..1983e7a194 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -16,25 +16,22 @@ object Dependencies { val ScalaVersion = "3.3.4" - val PekkoActorVersion = "1.1.2" + val PekkoActorVersion = "1.1.3" val PekkoHttpVersion = "1.1.0" val MonocleVersion = "3.3.0" - // rdf and graph libraries - // topbraid/shacl is not yet compatible with jena 5 so we need to use jena 4 for now - // see: https://github.com/TopQuadrant/shacl/pull/177 - val JenaVersion = "4.10.0" val Rdf4jVersion = "5.1.0" - val TopbraidShaclVersion = "1.4.3" + val TopbraidShaclVersion = "1.4.4" + val JenaVersion = "5.2.0" // should be aligned with the version topbraid-shacl uses - val ZioConfigVersion = "4.0.2" + val ZioConfigVersion = "4.0.3" val ZioLoggingVersion = "2.4.0" val ZioNioVersion = "2.0.2" val ZioMetricsConnectorsVersion = "2.3.1" val ZioPreludeVersion = "1.0.0-RC36" val ZioSchemaVersion = "0.2.0" - val ZioVersion = "2.1.13" + val ZioVersion = "2.1.14" // ZIO val zio = "dev.zio" %% "zio" % ZioVersion @@ -47,7 +44,7 @@ object Dependencies { val zioNio = "dev.zio" %% "zio-nio" % ZioNioVersion val zioMacros = "dev.zio" %% "zio-macros" % ZioVersion val zioPrelude = "dev.zio" %% "zio-prelude" % ZioPreludeVersion - val zioSttp = "com.softwaremill.sttp.client3" %% "zio" % "3.10.1" + val zioSttp = "com.softwaremill.sttp.client3" %% "zio" % "3.10.2" // refined val refined = Seq( @@ -75,6 +72,7 @@ object Dependencies { val pekkoStream = "org.apache.pekko" %% "pekko-stream" % PekkoActorVersion // rdf and graph libraries + val jenaCore = "org.apache.jena" % "jena-core" % JenaVersion val jenaText = "org.apache.jena" % "jena-text" % JenaVersion val rdf4jClient = "org.eclipse.rdf4j" % "rdf4j-client" % Rdf4jVersion val rdf4jShacl = "org.eclipse.rdf4j" % "rdf4j-shacl" % Rdf4jVersion @@ -96,7 +94,7 @@ object Dependencies { val jwtSprayJson = "com.github.jwt-scala" %% "jwt-zio-json" % "10.0.1" // jwtSprayJson -> 9.0.2 is the latest version that's compatible with spray-json; if it wasn't for spray, this would be Scala 3 compatible val springSecurityCore = - "org.springframework.security" % "spring-security-core" % "6.3.5" exclude ( + "org.springframework.security" % "spring-security-core" % "6.3.6" exclude ( "commons-logging", "commons-logging", ) exclude ("org.springframework", "spring-aop") @@ -129,7 +127,7 @@ object Dependencies { // found/added by the plugin but deleted anyway val commonsLang3 = "org.apache.commons" % "commons-lang3" % "3.17.0" - val tapirVersion = "1.11.10" + val tapirVersion = "1.11.12" val tapir = Seq( "com.softwaremill.sttp.tapir" %% "tapir-pekko-http-server" % tapirVersion, diff --git a/project/build.properties b/project/build.properties index e88a0d817d..73df629ac1 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.10.6 +sbt.version=1.10.7 diff --git a/project/plugins.sbt b/project/plugins.sbt index 88ef40922d..6d1af783f3 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -9,6 +9,6 @@ addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.3.0") addSbtPlugin("com.github.sbt" % "sbt-javaagent" % "0.1.8") addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.2.2") addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.12.0") -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.3") addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.1") addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.10.0") diff --git a/webapi/src/main/scala/org/knora/webapi/messages/StringFormatter.scala b/webapi/src/main/scala/org/knora/webapi/messages/StringFormatter.scala index 5252be2210..a9051c3402 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/StringFormatter.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/StringFormatter.scala @@ -260,7 +260,7 @@ object StringFormatter { private def getOrCacheSmartIri(iriStr: IRI, creationFun: () => SmartIri): SmartIri = smartIriCache.computeIfAbsent( iriStr, - JavaUtil.function({ (_: Object) => creationFun() }), + JavaUtil.function((_: Object) => creationFun()), ) val live: ZLayer[AppConfig, Nothing, StringFormatter] = ZLayer.fromFunction { (appConfig: AppConfig) => diff --git a/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/JenaModel.scala b/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/JenaModel.scala index d9ba3e65ce..7b0ad48b23 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/JenaModel.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/JenaModel.scala @@ -21,7 +21,7 @@ sealed trait JenaNode extends RdfNode { } case class JenaBlankNode(node: jena.graph.Node) extends JenaNode with BlankNode { - override def id: String = node.getBlankNodeId.getLabelString + override def id: String = node.getBlankNodeLabel override def stringValue: String = id } @@ -126,7 +126,7 @@ object JenaContextFactory { /** * Converts a named graph IRI to a [[jena.graph.Node]]. */ - def contextIriToNode(context: IRI): jena.graph.Node = + private def contextIriToNode(context: IRI): jena.graph.Node = jena.graph.NodeFactory.createURI(context) /** @@ -359,7 +359,7 @@ object JenaNodeFactory { * @return a [[DatatypeLiteral]]. */ def makeDatatypeLiteral(value: String, datatype: IRI): DatatypeLiteral = - JenaDatatypeLiteral(jena.graph.NodeFactory.createLiteral(value, typeMapper.getTypeByName(datatype))) + JenaDatatypeLiteral(jena.graph.NodeFactory.createLiteralDT(value, typeMapper.getTypeByName(datatype))) /** * Constructs a string with a language tag. @@ -368,7 +368,7 @@ object JenaNodeFactory { * @param language the language tag. */ def makeStringWithLanguage(value: String, language: String): StringWithLanguage = - JenaStringWithLanguage(jena.graph.NodeFactory.createLiteral(value, language)) + JenaStringWithLanguage(jena.graph.NodeFactory.createLiteralLang(value, language)) /** * Constructs a statement. diff --git a/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/ontologymessages/OntologyMessagesV2.scala b/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/ontologymessages/OntologyMessagesV2.scala index 1699faa39f..74a0000210 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/ontologymessages/OntologyMessagesV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/ontologymessages/OntologyMessagesV2.scala @@ -96,41 +96,40 @@ object CreateOntologyRequestV2 { apiRequestID: UUID, requestingUser: User, ): ZIO[StringFormatter, Throwable, CreateOntologyRequestV2] = ZIO.serviceWithZIO[StringFormatter] { - implicit sf: StringFormatter => - for { - isShared <- ZIO - .fromEither(jsonLDDocument.body.getBoolean(KnoraApiV2Complex.IsShared)) - .mapBoth(BadRequestException(_), _.exists(identity)) - ontologyName <- - ZIO.attempt { - jsonLDDocument.body.requireStringWithValidation( - KnoraApiV2Complex.OntologyName, - ValuesValidator.validateProjectSpecificOntologyName(_).getOrElse(_), - ) - } - label <- - ZIO.attempt( - jsonLDDocument.body.requireStringWithValidation(Rdfs.Label, Iri.toSparqlEncodedString(_).getOrElse(_)), - ) - comment <- - ZIO.attempt( - jsonLDDocument.body.maybeStringWithValidation(Rdfs.Comment, Iri.toSparqlEncodedString(_).getOrElse(_)), + implicit sf: StringFormatter => for { + isShared <- ZIO + .fromEither(jsonLDDocument.body.getBoolean(KnoraApiV2Complex.IsShared)) + .mapBoth(BadRequestException(_), _.exists(identity)) + ontologyName <- + ZIO.attempt { + jsonLDDocument.body.requireStringWithValidation( + KnoraApiV2Complex.OntologyName, + ValuesValidator.validateProjectSpecificOntologyName(_).getOrElse(_), ) - projectIri <- ZIO.attempt { - jsonLDDocument.body.requireIriInObject( - KnoraApiV2Complex.AttachedToProject, - sf.toSmartIriWithErr, - ) - } - } yield CreateOntologyRequestV2( - ontologyName = ontologyName, - projectIri = projectIri, - isShared = isShared, - label = label, - comment = comment, - apiRequestID = apiRequestID, - requestingUser = requestingUser, - ) + } + label <- + ZIO.attempt( + jsonLDDocument.body.requireStringWithValidation(Rdfs.Label, Iri.toSparqlEncodedString(_).getOrElse(_)), + ) + comment <- + ZIO.attempt( + jsonLDDocument.body.maybeStringWithValidation(Rdfs.Comment, Iri.toSparqlEncodedString(_).getOrElse(_)), + ) + projectIri <- ZIO.attempt { + jsonLDDocument.body.requireIriInObject( + KnoraApiV2Complex.AttachedToProject, + sf.toSmartIriWithErr, + ) + } + } yield CreateOntologyRequestV2( + ontologyName = ontologyName, + projectIri = projectIri, + isShared = isShared, + label = label, + comment = comment, + apiRequestID = apiRequestID, + requestingUser = requestingUser, + ) } } 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 38c3409e28..f779c2b359 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 @@ -2186,14 +2186,11 @@ case class StillImageExternalFileValueContentV2( case ApiV2Complex => JsonLDObject( toJsonLDObjectMapInComplexSchema(makeFileUrl) ++ Map( - StillImageFileValueHasIIIFBaseUrl -> JsonLDUtil - .makeUriObject( - { - val uri = externalUrl.value.toURI - if (uri.getPort == -1) URI.create(s"${uri.getScheme}://${uri.getHost}").toURL - else URI.create(s"${uri.getScheme}://${uri.getHost}:${uri.getPort}").toURL - }, - ), + StillImageFileValueHasIIIFBaseUrl -> JsonLDUtil.makeUriObject { + val uri = externalUrl.value.toURI + if (uri.getPort == -1) URI.create(s"${uri.getScheme}://${uri.getHost}").toURL + else URI.create(s"${uri.getScheme}://${uri.getHost}:${uri.getPort}").toURL + }, StillImageFileValueHasExternalUrl -> JsonLDUtil.makeUriObject(externalUrl.value), ), ) diff --git a/webapi/src/main/scala/org/knora/webapi/responders/IriLocker.scala b/webapi/src/main/scala/org/knora/webapi/responders/IriLocker.scala index bc4468e24a..c9f0c3be86 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/IriLocker.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/IriLocker.scala @@ -134,7 +134,7 @@ object IriLocker { val newLock = lockMap.merge( iri, IriLock(apiRequestID, 1), - JavaUtil.biFunction({ (currentLock, _) => + JavaUtil.biFunction((currentLock, _) => // The lock is already in use. Who has it? if (currentLock.apiRequestID == apiRequestID) { // We already have it, so increment the entry count. @@ -142,8 +142,8 @@ object IriLocker { } else { // Another API request has it, so leave it as is. currentLock - } - }), + }, + ), ) // Do we have the lock? if (newLock.apiRequestID == apiRequestID) { @@ -174,7 +174,7 @@ object IriLocker { private def decrementOrReleaseLock(iri: IRI, apiRequestID: UUID): Unit = { val _ = lockMap.compute( iri, - JavaUtil.biFunction({ (_, maybeCurrentLock) => + JavaUtil.biFunction((_, maybeCurrentLock) => Option(maybeCurrentLock) match { case Some(currentLock) => if (currentLock.apiRequestID == apiRequestID) { @@ -198,8 +198,8 @@ object IriLocker { throw ApplicationLockException( s"API request $apiRequestID was supposed to have an update lock on $iri, but the lock is unused", ) - } - }), + }, + ), ) } } diff --git a/webapi/src/main/scala/org/knora/webapi/responders/v2/ResourcesResponderV2.scala b/webapi/src/main/scala/org/knora/webapi/responders/v2/ResourcesResponderV2.scala index 38e96d2003..cfa585bb24 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/v2/ResourcesResponderV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/v2/ResourcesResponderV2.scala @@ -1628,14 +1628,13 @@ final case class ResourcesResponderV2( ) // If there is a version history for deletion of the event, create a delete resource event for it. - (deletionRep, resourceAtValueChanges) = fullReps.tail.partition { case (resHist, resource) => - resource - .asInstanceOf[ReadResourceV2] - .deletionInfo - .exists(deletionInfo => - deletionInfo.deleteDate == resHist.versionDate, - ) - } + (deletionRep, resourceAtValueChanges) = + fullReps.tail.partition { case (resHist, resource) => + resource + .asInstanceOf[ReadResourceV2] + .deletionInfo + .exists(deletionInfo => deletionInfo.deleteDate == resHist.versionDate) + } resourceDeleteEvent = getResourceDeletionEvents(deletionRep) // For each value version, form an event diff --git a/webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala b/webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala index fa9edf8aaa..cb27b911c5 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala @@ -997,10 +997,9 @@ final case class SearchResponderV2Live( mainResourceVar: QueryVariable, ): SparqlSelectResult = { // Make a Map of merged results per main resource IRI. - val prequeryRowsMergedMap: Map[IRI, VariableResultsRow] = prequeryResponseNotMerged.results.bindings.groupBy { - row => - // Get the rows for each main resource IRI. - row.rowMap(mainResourceVar.variableName) + val prequeryRowsMergedMap: Map[IRI, VariableResultsRow] = prequeryResponseNotMerged.results.bindings.groupBy { row => + // Get the rows for each main resource IRI. + row.rowMap(mainResourceVar.variableName) }.map { case (resourceIri: IRI, rows: Seq[VariableResultsRow]) => // Make a Set of all the column names in the rows to be merged. val columnNamesToMerge: Set[String] = rows.flatMap(_.rowMap.keySet).toSet diff --git a/webapi/src/main/scala/org/knora/webapi/responders/v2/ontology/OntologyHelpers.scala b/webapi/src/main/scala/org/knora/webapi/responders/v2/ontology/OntologyHelpers.scala index 0875bca89d..be2b99dafa 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/v2/ontology/OntologyHelpers.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/v2/ontology/OntologyHelpers.scala @@ -778,8 +778,7 @@ object OntologyHelpers { OntologyConstants.KnoraBase.IsAudioSegmentOfValue.toSmartIri case subProps if subProps.contains(OntologyConstants.KnoraBase.IsVideoSegmentOf.toSmartIri) => OntologyConstants.KnoraBase.IsVideoSegmentOfValue.toSmartIri - case subProps - if subProps.size == 1 => // if subPropertyOf is neither isPartOf nor HasLinkTo it inherits from a custom link property + case subProps if subProps.size == 1 => // if subPropertyOf is neither isPartOf nor HasLinkTo it inherits from a custom link property internalPropertyDef.subPropertyOf.head.fromLinkPropToLinkValueProp case _ => throw BadRequestException( diff --git a/webapi/src/main/scala/org/knora/webapi/routing/v2/OntologiesRouteV2.scala b/webapi/src/main/scala/org/knora/webapi/routing/v2/OntologiesRouteV2.scala index 059af3c67b..f1c86417af 100644 --- a/webapi/src/main/scala/org/knora/webapi/routing/v2/OntologiesRouteV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/routing/v2/OntologiesRouteV2.scala @@ -152,16 +152,14 @@ final case class OntologiesRouteV2()( path(ontologiesBasePath / "metadata") { put { entity(as[String]) { jsonRequest => requestContext => - { - val requestTask = for { - requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) - apiRequestId <- RouteUtilZ.randomUuid() - requestMessage <- - requestParser(_.changeOntologyMetadataRequestV2(jsonRequest, apiRequestId, requestingUser)) - .mapError(BadRequestException.apply) - } yield requestMessage - RouteUtilV2.runRdfRouteZ(requestTask, requestContext) - } + val requestTask = for { + requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) + apiRequestId <- RouteUtilZ.randomUuid() + requestMessage <- + requestParser(_.changeOntologyMetadataRequestV2(jsonRequest, apiRequestId, requestingUser)) + .mapError(BadRequestException.apply) + } yield requestMessage + RouteUtilV2.runRdfRouteZ(requestTask, requestContext) } } } @@ -199,15 +197,13 @@ final case class OntologiesRouteV2()( post { // Create a new class. entity(as[String]) { jsonRequest => requestContext => - { - val requestMessageTask = for { - requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) - requestDoc <- RouteUtilV2.parseJsonLd(jsonRequest) - apiRequestId <- RouteUtilZ.randomUuid() - requestMessage <- ZIO.attempt(CreateClassRequestV2.fromJsonLd(requestDoc, apiRequestId, requestingUser)) - } yield requestMessage - RouteUtilV2.runRdfRouteZ(requestMessageTask, requestContext) - } + val requestMessageTask = for { + requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) + requestDoc <- RouteUtilV2.parseJsonLd(jsonRequest) + apiRequestId <- RouteUtilZ.randomUuid() + requestMessage <- ZIO.attempt(CreateClassRequestV2.fromJsonLd(requestDoc, apiRequestId, requestingUser)) + } yield requestMessage + RouteUtilV2.runRdfRouteZ(requestMessageTask, requestContext) } } } @@ -217,18 +213,16 @@ final case class OntologiesRouteV2()( put { // Change the labels or comments of a class. entity(as[String]) { jsonRequest => requestContext => - { - val requestMessageTask = for { - requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) - requestDoc <- RouteUtilV2.parseJsonLd(jsonRequest) - apiRequestId <- RouteUtilZ.randomUuid() - requestMessage <- - ZIO.attempt( - ChangeClassLabelsOrCommentsRequestV2.fromJsonLd(requestDoc, apiRequestId, requestingUser), - ) - } yield requestMessage - RouteUtilV2.runRdfRouteZ(requestMessageTask, requestContext) - } + val requestMessageTask = for { + requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) + requestDoc <- RouteUtilV2.parseJsonLd(jsonRequest) + apiRequestId <- RouteUtilZ.randomUuid() + requestMessage <- + ZIO.attempt( + ChangeClassLabelsOrCommentsRequestV2.fromJsonLd(requestDoc, apiRequestId, requestingUser), + ) + } yield requestMessage + RouteUtilV2.runRdfRouteZ(requestMessageTask, requestContext) } } } @@ -256,16 +250,14 @@ final case class OntologiesRouteV2()( post { // Add cardinalities to a class. entity(as[String]) { jsonRequest => requestContext => - { - val requestMessageTask = for { - requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) - requestDoc <- RouteUtilV2.parseJsonLd(jsonRequest) - apiRequestId <- RouteUtilZ.randomUuid() - requestMessage <- - ZIO.attempt(AddCardinalitiesToClassRequestV2.fromJsonLd(requestDoc, apiRequestId, requestingUser)) - } yield requestMessage - RouteUtilV2.runRdfRouteZ(requestMessageTask, requestContext) - } + val requestMessageTask = for { + requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) + requestDoc <- RouteUtilV2.parseJsonLd(jsonRequest) + apiRequestId <- RouteUtilZ.randomUuid() + requestMessage <- + ZIO.attempt(AddCardinalitiesToClassRequestV2.fromJsonLd(requestDoc, apiRequestId, requestingUser)) + } yield requestMessage + RouteUtilV2.runRdfRouteZ(requestMessageTask, requestContext) } } } @@ -290,15 +282,13 @@ final case class OntologiesRouteV2()( path(ontologiesBasePath / "cardinalities") { put { entity(as[String]) { reqBody => requestContext => - { - val messageTask = for { - user <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) - document <- RouteUtilV2.parseJsonLd(reqBody) - apiRequestId <- RouteUtilZ.randomUuid() - msg <- ZIO.attempt(ReplaceClassCardinalitiesRequestV2.fromJsonLd(document, apiRequestId, user)) - } yield msg - RouteUtilV2.runRdfRouteZ(messageTask, requestContext) - } + val messageTask = for { + user <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) + document <- RouteUtilV2.parseJsonLd(reqBody) + apiRequestId <- RouteUtilZ.randomUuid() + msg <- ZIO.attempt(ReplaceClassCardinalitiesRequestV2.fromJsonLd(document, apiRequestId, user)) + } yield msg + RouteUtilV2.runRdfRouteZ(messageTask, requestContext) } } } @@ -307,17 +297,15 @@ final case class OntologiesRouteV2()( path(ontologiesBasePath / "candeletecardinalities") { post { entity(as[String]) { jsonRequest => requestContext => - { - val messageTask = for { - requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) - requestDoc <- RouteUtilV2.parseJsonLd(jsonRequest) - apiRequestId <- RouteUtilZ.randomUuid() - msg <- ZIO.attempt( - CanDeleteCardinalitiesFromClassRequestV2.fromJsonLd(requestDoc, apiRequestId, requestingUser), - ) - } yield msg - RouteUtilV2.runRdfRouteZ(messageTask, requestContext) - } + val messageTask = for { + requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) + requestDoc <- RouteUtilV2.parseJsonLd(jsonRequest) + apiRequestId <- RouteUtilZ.randomUuid() + msg <- ZIO.attempt( + CanDeleteCardinalitiesFromClassRequestV2.fromJsonLd(requestDoc, apiRequestId, requestingUser), + ) + } yield msg + RouteUtilV2.runRdfRouteZ(messageTask, requestContext) } } } @@ -328,16 +316,14 @@ final case class OntologiesRouteV2()( path(ontologiesBasePath / "cardinalities") { patch { entity(as[String]) { jsonRequest => requestContext => - { - val requestMessageTask = for { - requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) - requestDoc <- RouteUtilV2.parseJsonLd(jsonRequest) - apiRequestId <- RouteUtilZ.randomUuid() - msg <- - ZIO.attempt(DeleteCardinalitiesFromClassRequestV2.fromJsonLd(requestDoc, apiRequestId, requestingUser)) - } yield msg - RouteUtilV2.runRdfRouteZ(requestMessageTask, requestContext) - } + val requestMessageTask = for { + requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) + requestDoc <- RouteUtilV2.parseJsonLd(jsonRequest) + apiRequestId <- RouteUtilZ.randomUuid() + msg <- + ZIO.attempt(DeleteCardinalitiesFromClassRequestV2.fromJsonLd(requestDoc, apiRequestId, requestingUser)) + } yield msg + RouteUtilV2.runRdfRouteZ(requestMessageTask, requestContext) } } } @@ -347,15 +333,13 @@ final case class OntologiesRouteV2()( put { // Change a class's cardinalities. entity(as[String]) { jsonRequest => requestContext => - { - val requestMessageTask = for { - requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) - requestDoc <- RouteUtilV2.parseJsonLd(jsonRequest) - apiRequestId <- RouteUtilZ.randomUuid() - msg <- ZIO.attempt(ChangeGuiOrderRequestV2.fromJsonLd(requestDoc, apiRequestId, requestingUser)) - } yield msg - RouteUtilV2.runRdfRouteZ(requestMessageTask, requestContext) - } + val requestMessageTask = for { + requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) + requestDoc <- RouteUtilV2.parseJsonLd(jsonRequest) + apiRequestId <- RouteUtilZ.randomUuid() + msg <- ZIO.attempt(ChangeGuiOrderRequestV2.fromJsonLd(requestDoc, apiRequestId, requestingUser)) + } yield msg + RouteUtilV2.runRdfRouteZ(requestMessageTask, requestContext) } } } @@ -461,142 +445,140 @@ final case class OntologiesRouteV2()( post { // Create a new property. entity(as[String]) { jsonRequest => requestContext => - { - val requestMessageTask = for { - requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) - requestDoc <- RouteUtilV2.parseJsonLd(jsonRequest) - inputOntology <- getInputOntology(requestDoc) - propertyUpdateInfo <- getPropertyDef(inputOntology) - propertyInfoContent: PropertyInfoContentV2 = propertyUpdateInfo.propertyInfoContent - _ <- PropertyIri.make(propertyInfoContent.propertyIri.toString).toZIO - - // get gui related values from request and validate them by making value objects from it - // get the (optional) gui element from the request - maybeGuiElement <- getGuiElement(propertyInfoContent) - // get the gui attribute(s) from the request - maybeGuiAttributes <- getGuiAttributes(propertyInfoContent) - _ <- GuiObject - .makeFromStrings(maybeGuiAttributes, maybeGuiElement) - .toZIO - .mapError(error => BadRequestException(error.msg)) - - apiRequestId <- RouteUtilZ.randomUuid() - requestMessage <- - ZIO.attempt(CreatePropertyRequestV2.fromJsonLd(requestDoc, apiRequestId, requestingUser)) - - // get gui related values from request and validate them by making value objects from it - - // get ontology info from request - inputOntology <- getInputOntology(requestDoc) - propertyInfoContent <- getPropertyDef(inputOntology).map(_.propertyInfoContent) - - // get the (optional) gui element - // get the (optional) gui element from the request - maybeGuiElement <- getGuiElement(propertyInfoContent) - - // validate the gui element by creating value object - validatedGuiElement = maybeGuiElement match { - case Some(guiElement) => GuiElement.make(guiElement).map(Some(_)) - case None => Validation.succeed(None) - } - maybeGuiAttributes <- getGuiAttributes(propertyInfoContent) - - // validate the gui attributes by creating value objects - guiAttributes = maybeGuiAttributes.map(guiAttribute => GuiAttribute.make(guiAttribute)) - - validatedGuiAttributes = Validation.validateAll(guiAttributes).map(_.toSet) - - // validate the combination of gui element and gui attribute by creating a GuiObject value object - guiObject = Validation - .validate(validatedGuiAttributes, validatedGuiElement) - .flatMap(values => GuiObject.make(values._1, values._2)) - - ontologyIri <- - ZIO.serviceWithZIO[IriConverter](_.asSmartIri(inputOntology.ontologyMetadata.ontologyIri.toString)) - lastModificationDate = Validation.succeed(propertyUpdateInfo.lastModificationDate) - propertyIri <- ZIO - .serviceWithZIO[IriConverter](_.asSmartIri(propertyInfoContent.propertyIri.toString)) - subClassConstraintSmartIri <- - RouteUtilZ.toSmartIri(OntologyConstants.KnoraBase.SubjectClassConstraint, "Should not happen") - subjectType <- - propertyInfoContent.predicates.get(subClassConstraintSmartIri) match { - case None => ZIO.succeed(None) - case Some(value) => - value.objects.head match { - case objectType: SmartIriLiteralV2 => - ZIO - .serviceWithZIO[IriConverter]( - _.asSmartIri(objectType.value.toOntologySchema(InternalSchema).toString), - ) - .map(Some(_)) - case other => - ZIO.fail(ValidationException(s"Unexpected subject type for $other")) - } - } - objectTypeSmartIri <- RouteUtilZ - .toSmartIri(OntologyConstants.KnoraApiV2Complex.ObjectType, "Should not happen") - objectType <- - propertyInfoContent.predicates.get(objectTypeSmartIri) match { - case None => - ZIO.fail(ValidationException(s"Object type cannot be empty.")) - case Some(value) => - value.objects.head match { - case objectType: SmartIriLiteralV2 => - ZIO - .serviceWithZIO[IriConverter]( - _.asSmartIri(objectType.value.toOntologySchema(InternalSchema).toString), - ) - case other => - ZIO.fail(ValidationException(s"Unexpected object type for $other")) + val requestMessageTask = for { + requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) + requestDoc <- RouteUtilV2.parseJsonLd(jsonRequest) + inputOntology <- getInputOntology(requestDoc) + propertyUpdateInfo <- getPropertyDef(inputOntology) + propertyInfoContent: PropertyInfoContentV2 = propertyUpdateInfo.propertyInfoContent + _ <- PropertyIri.make(propertyInfoContent.propertyIri.toString).toZIO + + // get gui related values from request and validate them by making value objects from it + // get the (optional) gui element from the request + maybeGuiElement <- getGuiElement(propertyInfoContent) + // get the gui attribute(s) from the request + maybeGuiAttributes <- getGuiAttributes(propertyInfoContent) + _ <- GuiObject + .makeFromStrings(maybeGuiAttributes, maybeGuiElement) + .toZIO + .mapError(error => BadRequestException(error.msg)) + + apiRequestId <- RouteUtilZ.randomUuid() + requestMessage <- + ZIO.attempt(CreatePropertyRequestV2.fromJsonLd(requestDoc, apiRequestId, requestingUser)) + + // get gui related values from request and validate them by making value objects from it + + // get ontology info from request + inputOntology <- getInputOntology(requestDoc) + propertyInfoContent <- getPropertyDef(inputOntology).map(_.propertyInfoContent) + + // get the (optional) gui element + // get the (optional) gui element from the request + maybeGuiElement <- getGuiElement(propertyInfoContent) + + // validate the gui element by creating value object + validatedGuiElement = maybeGuiElement match { + case Some(guiElement) => GuiElement.make(guiElement).map(Some(_)) + case None => Validation.succeed(None) + } + maybeGuiAttributes <- getGuiAttributes(propertyInfoContent) + + // validate the gui attributes by creating value objects + guiAttributes = maybeGuiAttributes.map(guiAttribute => GuiAttribute.make(guiAttribute)) + + validatedGuiAttributes = Validation.validateAll(guiAttributes).map(_.toSet) + + // validate the combination of gui element and gui attribute by creating a GuiObject value object + guiObject = Validation + .validate(validatedGuiAttributes, validatedGuiElement) + .flatMap(values => GuiObject.make(values._1, values._2)) + + ontologyIri <- + ZIO.serviceWithZIO[IriConverter](_.asSmartIri(inputOntology.ontologyMetadata.ontologyIri.toString)) + lastModificationDate = Validation.succeed(propertyUpdateInfo.lastModificationDate) + propertyIri <- ZIO + .serviceWithZIO[IriConverter](_.asSmartIri(propertyInfoContent.propertyIri.toString)) + subClassConstraintSmartIri <- + RouteUtilZ.toSmartIri(OntologyConstants.KnoraBase.SubjectClassConstraint, "Should not happen") + subjectType <- + propertyInfoContent.predicates.get(subClassConstraintSmartIri) match { + case None => ZIO.succeed(None) + case Some(value) => + value.objects.head match { + case objectType: SmartIriLiteralV2 => + ZIO + .serviceWithZIO[IriConverter]( + _.asSmartIri(objectType.value.toOntologySchema(InternalSchema).toString), + ) + .map(Some(_)) + case other => + ZIO.fail(ValidationException(s"Unexpected subject type for $other")) + } + } + objectTypeSmartIri <- RouteUtilZ + .toSmartIri(OntologyConstants.KnoraApiV2Complex.ObjectType, "Should not happen") + objectType <- + propertyInfoContent.predicates.get(objectTypeSmartIri) match { + case None => + ZIO.fail(ValidationException(s"Object type cannot be empty.")) + case Some(value) => + value.objects.head match { + case objectType: SmartIriLiteralV2 => + ZIO + .serviceWithZIO[IriConverter]( + _.asSmartIri(objectType.value.toOntologySchema(InternalSchema).toString), + ) + case other => + ZIO.fail(ValidationException(s"Unexpected object type for $other")) + } + } + labelSmartIri <- RouteUtilZ.toSmartIri(OntologyConstants.Rdfs.Label, "Should not happen") + label = propertyInfoContent.predicates.get(labelSmartIri) match { + case None => Validation.fail(ValidationException("Label missing")) + case Some(value) => + value.objects.head match { + case StringLiteralV2(value, Some(language)) => LangString.makeFromStrings(language, value) + case StringLiteralV2(_, None) => + Validation.fail(ValidationException("Label missing the language tag")) + case _ => Validation.fail(ValidationException("Unexpected Type for Label")) + } } - } - labelSmartIri <- RouteUtilZ.toSmartIri(OntologyConstants.Rdfs.Label, "Should not happen") - label = propertyInfoContent.predicates.get(labelSmartIri) match { - case None => Validation.fail(ValidationException("Label missing")) + commentSmartIri <- RouteUtilZ.toSmartIri(OntologyConstants.Rdfs.Comment, "Should not happen") + comment = propertyInfoContent.predicates.get(commentSmartIri) match { + case None => Validation.succeed(None) case Some(value) => value.objects.head match { - case StringLiteralV2(value, Some(language)) => LangString.makeFromStrings(language, value) + case StringLiteralV2(value, Some(language)) => + LangString.makeFromStrings(language, value).map(Some(_)) case StringLiteralV2(_, None) => - Validation.fail(ValidationException("Label missing the language tag")) - case _ => Validation.fail(ValidationException("Unexpected Type for Label")) + Validation.fail(ValidationException("Comment missing the language tag")) + case _ => Validation.fail(ValidationException("Unexpected Type for Comment")) } } - commentSmartIri <- RouteUtilZ.toSmartIri(OntologyConstants.Rdfs.Comment, "Should not happen") - comment = propertyInfoContent.predicates.get(commentSmartIri) match { - case None => Validation.succeed(None) - case Some(value) => - value.objects.head match { - case StringLiteralV2(value, Some(language)) => - LangString.makeFromStrings(language, value).map(Some(_)) - case StringLiteralV2(_, None) => - Validation.fail(ValidationException("Comment missing the language tag")) - case _ => Validation.fail(ValidationException("Unexpected Type for Comment")) - } - } - superProperties = - propertyInfoContent.subPropertyOf.toList match { - case Nil => Validation.fail(ValidationException("SuperProperties cannot be empty.")) - case superProps => Validation.succeed(superProps) - } - - _ <- - Validation - .validate( - lastModificationDate, - label, - comment, - superProperties, - guiObject, - ) - .flatMap(v => - CreatePropertyCommand - .make(ontologyIri, v._1, propertyIri, subjectType, objectType, v._2, v._3, v._4, v._5), - ) - .toZIO - } yield requestMessage - - RouteUtilV2.runRdfRouteZ(requestMessageTask, requestContext) - } + superProperties = + propertyInfoContent.subPropertyOf.toList match { + case Nil => Validation.fail(ValidationException("SuperProperties cannot be empty.")) + case superProps => Validation.succeed(superProps) + } + + _ <- + Validation + .validate( + lastModificationDate, + label, + comment, + superProperties, + guiObject, + ) + .flatMap(v => + CreatePropertyCommand + .make(ontologyIri, v._1, propertyIri, subjectType, objectType, v._2, v._3, v._4, v._5), + ) + .toZIO + } yield requestMessage + + RouteUtilV2.runRdfRouteZ(requestMessageTask, requestContext) } } } @@ -643,18 +625,16 @@ final case class OntologiesRouteV2()( put { // Change the labels or comments of a property. entity(as[String]) { jsonRequest => requestContext => - { - val requestMessageTask = for { - requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) - requestDoc <- RouteUtilV2.parseJsonLd(jsonRequest) - apiRequestId <- RouteUtilZ.randomUuid() - requestMessage <- - ZIO.attempt( - ChangePropertyLabelsOrCommentsRequestV2.fromJsonLd(requestDoc, apiRequestId, requestingUser), - ) - } yield requestMessage - RouteUtilV2.runRdfRouteZ(requestMessageTask, requestContext) - } + val requestMessageTask = for { + requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) + requestDoc <- RouteUtilV2.parseJsonLd(jsonRequest) + apiRequestId <- RouteUtilZ.randomUuid() + requestMessage <- + ZIO.attempt( + ChangePropertyLabelsOrCommentsRequestV2.fromJsonLd(requestDoc, apiRequestId, requestingUser), + ) + } yield requestMessage + RouteUtilV2.runRdfRouteZ(requestMessageTask, requestContext) } } } @@ -680,32 +660,30 @@ final case class OntologiesRouteV2()( put { // Change the salsah-gui:guiElement and/or salsah-gui:guiAttribute of a property. entity(as[String]) { jsonRequest => requestContext => - { - val requestTask = for { - requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) - requestDoc <- RouteUtilV2.parseJsonLd(jsonRequest) - inputOntology <- getInputOntology(requestDoc) - propertyUpdateInfo <- getPropertyDef(inputOntology) - propertyInfoContent = propertyUpdateInfo.propertyInfoContent - lastModificationDate = propertyUpdateInfo.lastModificationDate - propertyIri <- PropertyIri.make(propertyInfoContent.propertyIri.toString).toZIO - newGuiElement <- getGuiElement(propertyInfoContent) - newGuiAttributes <- getGuiAttributes(propertyInfoContent) - guiObject <- - GuiObject - .makeFromStrings(newGuiAttributes, newGuiElement) - .toZIO - .mapError(e => BadRequestException(e.msg)) - apiRequestId <- RouteUtilZ.randomUuid() - } yield ChangePropertyGuiElementRequest( - propertyIri, - guiObject, - lastModificationDate, - apiRequestId, - requestingUser, - ) - RouteUtilV2.runRdfRouteZ(requestTask, requestContext) - } + val requestTask = for { + requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) + requestDoc <- RouteUtilV2.parseJsonLd(jsonRequest) + inputOntology <- getInputOntology(requestDoc) + propertyUpdateInfo <- getPropertyDef(inputOntology) + propertyInfoContent = propertyUpdateInfo.propertyInfoContent + lastModificationDate = propertyUpdateInfo.lastModificationDate + propertyIri <- PropertyIri.make(propertyInfoContent.propertyIri.toString).toZIO + newGuiElement <- getGuiElement(propertyInfoContent) + newGuiAttributes <- getGuiAttributes(propertyInfoContent) + guiObject <- + GuiObject + .makeFromStrings(newGuiAttributes, newGuiElement) + .toZIO + .mapError(e => BadRequestException(e.msg)) + apiRequestId <- RouteUtilZ.randomUuid() + } yield ChangePropertyGuiElementRequest( + propertyIri, + guiObject, + lastModificationDate, + apiRequestId, + requestingUser, + ) + RouteUtilV2.runRdfRouteZ(requestTask, requestContext) } } } @@ -783,15 +761,13 @@ final case class OntologiesRouteV2()( // Create a new, empty ontology. post { entity(as[String]) { jsonRequest => requestContext => - { - val t = for { - requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) - requestDoc <- RouteUtilV2.parseJsonLd(jsonRequest) - apiRequestId <- RouteUtilZ.randomUuid() - requestMessage <- CreateOntologyRequestV2.fromJsonLd(requestDoc, apiRequestId, requestingUser) - } yield requestMessage - RouteUtilV2.runRdfRouteZ(t, requestContext) - } + val t = for { + requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) + requestDoc <- RouteUtilV2.parseJsonLd(jsonRequest) + apiRequestId <- RouteUtilZ.randomUuid() + requestMessage <- CreateOntologyRequestV2.fromJsonLd(requestDoc, apiRequestId, requestingUser) + } yield requestMessage + RouteUtilV2.runRdfRouteZ(t, requestContext) } } } diff --git a/webapi/src/main/scala/org/knora/webapi/routing/v2/ResourcesRouteV2.scala b/webapi/src/main/scala/org/knora/webapi/routing/v2/ResourcesRouteV2.scala index 374c625405..891eb014c9 100644 --- a/webapi/src/main/scala/org/knora/webapi/routing/v2/ResourcesRouteV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/routing/v2/ResourcesRouteV2.scala @@ -100,18 +100,16 @@ final case class ResourcesRouteV2(appConfig: AppConfig)( private def createResource(): Route = path(resourcesBasePath) { post { entity(as[String]) { jsonRequest => requestContext => - { - val requestTask = for { - requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) - apiRequestId <- RouteUtilZ.randomUuid() - requestMessage <- jsonLdRequestParser( - _.createResourceRequestV2(jsonRequest, requestingUser, apiRequestId), - ).mapError(BadRequestException.apply) - // check for each value which represents a file value if the file's MIME type is allowed - _ <- checkMimeTypesForFileValueContents(requestMessage.createResource.flatValues) - } yield requestMessage - RouteUtilV2.runRdfRouteZ(requestTask, requestContext) - } + val requestTask = for { + requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) + apiRequestId <- RouteUtilZ.randomUuid() + requestMessage <- jsonLdRequestParser( + _.createResourceRequestV2(jsonRequest, requestingUser, apiRequestId), + ).mapError(BadRequestException.apply) + // check for each value which represents a file value if the file's MIME type is allowed + _ <- checkMimeTypesForFileValueContents(requestMessage.createResource.flatValues) + } yield requestMessage + RouteUtilV2.runRdfRouteZ(requestTask, requestContext) } } } @@ -119,16 +117,14 @@ final case class ResourcesRouteV2(appConfig: AppConfig)( private def updateResourceMetadata(): Route = path(resourcesBasePath) { put { entity(as[String]) { jsonRequest => requestContext => - { - val requestMessageFuture = for { - requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) - apiRequestId <- RouteUtilZ.randomUuid() - requestMessage <- - jsonLdRequestParser(_.updateResourceMetadataRequestV2(jsonRequest, requestingUser, apiRequestId)) - .mapError(BadRequestException.apply) - } yield requestMessage - RouteUtilV2.runRdfRouteZ(requestMessageFuture, requestContext) - } + val requestMessageFuture = for { + requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) + apiRequestId <- RouteUtilZ.randomUuid() + requestMessage <- + jsonLdRequestParser(_.updateResourceMetadataRequestV2(jsonRequest, requestingUser, apiRequestId)) + .mapError(BadRequestException.apply) + } yield requestMessage + RouteUtilV2.runRdfRouteZ(requestMessageFuture, requestContext) } } } @@ -380,15 +376,13 @@ final case class ResourcesRouteV2(appConfig: AppConfig)( private def deleteResource(): Route = path(resourcesBasePath / "delete") { post { entity(as[String]) { jsonRequest => requestContext => - { - val requestTask = for { - apiRequestId <- RouteUtilZ.randomUuid() - requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) - msg <- jsonLdRequestParser(_.deleteOrEraseResourceRequestV2(jsonRequest, requestingUser, apiRequestId)) - .mapError(BadRequestException.apply) - } yield msg - RouteUtilV2.runRdfRouteZ(requestTask, requestContext) - } + val requestTask = for { + apiRequestId <- RouteUtilZ.randomUuid() + requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) + msg <- jsonLdRequestParser(_.deleteOrEraseResourceRequestV2(jsonRequest, requestingUser, apiRequestId)) + .mapError(BadRequestException.apply) + } yield msg + RouteUtilV2.runRdfRouteZ(requestTask, requestContext) } } } @@ -396,16 +390,14 @@ final case class ResourcesRouteV2(appConfig: AppConfig)( private def eraseResource(): Route = path(resourcesBasePath / "erase") { post { entity(as[String]) { jsonRequest => requestContext => - { - val requestTask = for { - apiRequestId <- RouteUtilZ.randomUuid() - requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) - requestMessage <- - jsonLdRequestParser(_.deleteOrEraseResourceRequestV2(jsonRequest, requestingUser, apiRequestId)) - .mapError(BadRequestException.apply) - } yield requestMessage.copy(erase = true) - RouteUtilV2.runRdfRouteZ(requestTask, requestContext) - } + val requestTask = for { + apiRequestId <- RouteUtilZ.randomUuid() + requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) + requestMessage <- + jsonLdRequestParser(_.deleteOrEraseResourceRequestV2(jsonRequest, requestingUser, apiRequestId)) + .mapError(BadRequestException.apply) + } yield requestMessage.copy(erase = true) + RouteUtilV2.runRdfRouteZ(requestTask, requestContext) } } } diff --git a/webapi/src/main/scala/org/knora/webapi/routing/v2/ValuesRouteV2.scala b/webapi/src/main/scala/org/knora/webapi/routing/v2/ValuesRouteV2.scala index 89a1b3bd0f..64bbe0394f 100644 --- a/webapi/src/main/scala/org/knora/webapi/routing/v2/ValuesRouteV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/routing/v2/ValuesRouteV2.scala @@ -81,19 +81,17 @@ final case class ValuesRouteV2()( private def createValue(): Route = path(valuesBasePath) { post { entity(as[String]) { jsonLdString => ctx => - { - RouteUtilV2.completeResponse( - for { - requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(ctx)) - apiRequestId <- Random.nextUUID - valueToCreate <- jsonLdRequestParser( - _.createValueV2FromJsonLd(jsonLdString).mapError(BadRequestException(_)), - ) - response <- responder(_.createValueV2(valueToCreate, requestingUser, apiRequestId)) - } yield response, - ctx, - ) - } + RouteUtilV2.completeResponse( + for { + requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(ctx)) + apiRequestId <- Random.nextUUID + valueToCreate <- jsonLdRequestParser( + _.createValueV2FromJsonLd(jsonLdString).mapError(BadRequestException(_)), + ) + response <- responder(_.createValueV2(valueToCreate, requestingUser, apiRequestId)) + } yield response, + ctx, + ) } } } @@ -101,19 +99,17 @@ final case class ValuesRouteV2()( private def updateValue(): Route = path(valuesBasePath) { put { entity(as[String]) { jsonLdString => ctx => - { - RouteUtilV2.completeResponse( - for { - requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(ctx)) - apiRequestId <- Random.nextUUID - updateValue <- jsonLdRequestParser( - _.updateValueV2fromJsonLd(jsonLdString).mapError(BadRequestException(_)), - ) - response <- responder(_.updateValueV2(updateValue, requestingUser, apiRequestId)) - } yield response, - ctx, - ) - } + RouteUtilV2.completeResponse( + for { + requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(ctx)) + apiRequestId <- Random.nextUUID + updateValue <- jsonLdRequestParser( + _.updateValueV2fromJsonLd(jsonLdString).mapError(BadRequestException(_)), + ) + response <- responder(_.updateValueV2(updateValue, requestingUser, apiRequestId)) + } yield response, + ctx, + ) } } } @@ -121,18 +117,16 @@ final case class ValuesRouteV2()( private def deleteValue(): Route = path(valuesBasePath / "delete") { post { entity(as[String]) { jsonLdString => requestContext => - { - RouteUtilV2.completeResponse( - for { - requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) - apiRequestId <- RouteUtilZ.randomUuid() - deleteValue <- - jsonLdRequestParser(_.deleteValueV2FromJsonLd(jsonLdString).mapError(BadRequestException(_))) - response <- responder(_.deleteValueV2(deleteValue, requestingUser, apiRequestId)) - } yield response, - requestContext, - ) - } + RouteUtilV2.completeResponse( + for { + requestingUser <- ZIO.serviceWithZIO[Authenticator](_.getUserADM(requestContext)) + apiRequestId <- RouteUtilZ.randomUuid() + deleteValue <- + jsonLdRequestParser(_.deleteValueV2FromJsonLd(jsonLdString).mapError(BadRequestException(_))) + response <- responder(_.deleteValueV2(deleteValue, requestingUser, apiRequestId)) + } yield response, + requestContext, + ) } } } diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/model/User.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/model/User.scala index 419a889fdc..59dcb12727 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/model/User.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/model/User.scala @@ -203,7 +203,7 @@ object Username extends StringValueCompanion[Username] { "[a-zA-Z0-9._-]+" + // Only contains alphanumeric characters, underscore, hyphen and dot. "(? in => { runToFuture(handlerAndEndpoint.handler(user)(in)) }) + handlerAndEndpoint.endpoint.serverLogic(user => in => runToFuture(handlerAndEndpoint.handler(user)(in))) def mapPublicEndpointHandler[INPUT, OUTPUT]( handlerAndEndpoint: PublicEndpointHandler[INPUT, OUTPUT], diff --git a/webapi/src/test/scala/org/knora/webapi/store/triplestore/api/TriplestoreServiceInMemory.scala b/webapi/src/test/scala/org/knora/webapi/store/triplestore/api/TriplestoreServiceInMemory.scala index 7ec92b16ee..3e8e3145d4 100644 --- a/webapi/src/test/scala/org/knora/webapi/store/triplestore/api/TriplestoreServiceInMemory.scala +++ b/webapi/src/test/scala/org/knora/webapi/store/triplestore/api/TriplestoreServiceInMemory.scala @@ -99,8 +99,9 @@ final case class TriplestoreServiceInMemory(datasetRef: Ref[Dataset])(implicit v private def getDataSetWithTransaction(readWrite: ReadWrite): URIO[Scope, Dataset] = { val acquire = getDataset.tap(ds => ZIO.succeed(ds.begin(readWrite))) - def release(ds: Dataset) = ZIO.succeed(try { ds.commit() } - finally { ds.end() }) + def release(ds: Dataset) = ZIO.succeed(try { + ds.commit() + } finally { ds.end() }) ZIO.acquireRelease(acquire)(release) } diff --git a/webapi/src/test/scala/org/knora/webapi/store/triplestore/api/TriplestoreServiceInMemorySpec.scala b/webapi/src/test/scala/org/knora/webapi/store/triplestore/api/TriplestoreServiceInMemorySpec.scala index 69cfb51be6..2272a74943 100644 --- a/webapi/src/test/scala/org/knora/webapi/store/triplestore/api/TriplestoreServiceInMemorySpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/store/triplestore/api/TriplestoreServiceInMemorySpec.scala @@ -303,7 +303,7 @@ object TriplestoreServiceInMemorySpec extends ZIOSpecDefault { TriG, ), ) - } yield assertTrue({ val fileExists = Files.exists(testFile.toFile.toPath); fileExists }) + } yield assertTrue { val fileExists = Files.exists(testFile.toFile.toPath); fileExists } } }), ).provide(TriplestoreServiceInMemory.layer, datasetLayerFromTurtle(testDataSet), StringFormatter.test)