diff --git a/integration/src/test/scala/org/knora/webapi/e2e/v2/OntologyV2R2RSpec.scala b/integration/src/test/scala/org/knora/webapi/e2e/v2/OntologyV2R2RSpec.scala index 9b4ddba982..b69c9aa149 100644 --- a/integration/src/test/scala/org/knora/webapi/e2e/v2/OntologyV2R2RSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/e2e/v2/OntologyV2R2RSpec.scala @@ -155,10 +155,8 @@ class OntologyV2R2RSpec extends R2RSpec { */ def storeClientTestData(responseStr: String): Unit = maybeClientTestDataBasename match { - case Some(clientTestDataBasename) => - CollectClientTestData(clientTestDataBasename, responseStr) - - case None => () + case Some(clientTestDataBasename) => CollectClientTestData(clientTestDataBasename, responseStr) + case None => () } /** diff --git a/integration/src/test/scala/org/knora/webapi/util/cache/CacheUtilSpec.scala b/integration/src/test/scala/org/knora/webapi/util/cache/CacheUtilSpec.scala index f08926ac1a..0fdbe00252 100644 --- a/integration/src/test/scala/org/knora/webapi/util/cache/CacheUtilSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/util/cache/CacheUtilSpec.scala @@ -28,12 +28,5 @@ class CacheUtilSpec extends CoreSpec { CacheUtil.createCaches(appConfig.cacheConfigs) CacheUtil.get(cacheName, 213.toString) should be(None) } - - "allow to delete a set value " in { - CacheUtil.removeAllCaches() - CacheUtil.createCaches(appConfig.cacheConfigs) - CacheUtil.remove(cacheName, sessionId) - CacheUtil.get(cacheName, sessionId) should be(None) - } } } diff --git a/webapi/src/main/scala/org/knora/webapi/messages/admin/responder/permissionsmessages/PermissionsMessagesUtilADM.scala b/webapi/src/main/scala/org/knora/webapi/messages/admin/responder/permissionsmessages/PermissionsMessagesUtilADM.scala index 23c93d438a..36013a2821 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/admin/responder/permissionsmessages/PermissionsMessagesUtilADM.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/admin/responder/permissionsmessages/PermissionsMessagesUtilADM.scala @@ -119,7 +119,7 @@ object PermissionsMessagesUtilADM { } } - def checkPermissionIri(iri: IRI): Unit = { + def checkPermissionIri(iri: IRI): IRI = { implicit val sf: StringFormatter = StringFormatter.getInstanceForConstantOntologies sf.validatePermissionIri(iri).fold(e => throw BadRequestException(e), v => v) } diff --git a/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/jenaimpl/JenaModel.scala b/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/jenaimpl/JenaModel.scala index 83ea10895f..cb49574248 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/jenaimpl/JenaModel.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/jenaimpl/JenaModel.scala @@ -231,7 +231,7 @@ class JenaModel(private val dataset: jena.query.Dataset, private val nodeFactory override def setNamespace(prefix: String, namespace: IRI): Unit = { def setNamespaceInGraph(graph: jena.graph.Graph): Unit = { val prefixMapping: jena.shared.PrefixMapping = graph.getPrefixMapping - prefixMapping.setNsPrefix(prefix, namespace) + val _ = prefixMapping.setNsPrefix(prefix, namespace) } // Add the namespace to the default graph. diff --git a/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/GravsearchParser.scala b/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/GravsearchParser.scala index dc3c792b10..c72740bbf2 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/GravsearchParser.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/GravsearchParser.scala @@ -164,7 +164,7 @@ object GravsearchParser { if (smartIri.isKnoraEntityIri) { smartIri.getOntologySchema match { - case Some(_: ApiV2Schema) => allIris.add(smartIri) + case Some(_: ApiV2Schema) => val _ = allIris.add(smartIri) case _ => throw GravsearchException(s"Ontology schema not allowed in Gravsearch query: $smartIri") } } @@ -470,7 +470,7 @@ object GravsearchParser { if (node.getName.startsWith("_const_")) { // This is a parser-generated constant used in the CONSTRUCT clause. Just save it so we can // build the CONSTRUCT clause correctly later. - valueConstants.put(node.getName, valueConstant) + val _ = valueConstants.put(node.getName, valueConstant) } else { // It's a BIND. Accept it if it refers to a Knora data IRI. valueConstant.getValue match { 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 9a5ea91ef4..12aba1b6c5 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/IriLocker.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/IriLocker.scala @@ -6,6 +6,7 @@ package org.knora.webapi.responders import zio.Task +import zio.UIO import zio.ZIO import java.util.UUID @@ -99,15 +100,10 @@ object IriLocker { * @param task The [[Task]] that performs the update. * @return the result of the task. */ - def runWithIriLock[T](apiRequestID: UUID, iri: IRI, task: Task[T]): Task[T] = { - val acquireLock: Task[Unit] = ZIO.attemptBlocking(this.acquireLock(iri, apiRequestID)).logError - def releaseLock(ignored: Unit) = ZIO.attempt(decrementOrReleaseLock(iri, apiRequestID)).logError.ignore - ZIO.scoped { - for { - _ <- ZIO.acquireRelease(acquireLock)(releaseLock) - taskResult <- task - } yield taskResult - } + def runWithIriLock[A](apiRequestID: UUID, iri: IRI, task: Task[A]): Task[A] = { + val acquire: Task[Unit] = ZIO.attemptBlocking(this.acquireLock(iri, apiRequestID)).logError + val release: Unit => UIO[Unit] = _ => ZIO.attempt(decrementOrReleaseLock(iri, apiRequestID)).logError.ignore + ZIO.scoped(ZIO.acquireRelease(acquire)(release) *> task) } /** @@ -177,8 +173,8 @@ object IriLocker { * @param iri the IRI that is locked. * @param apiRequestID the ID of the API request that has the lock. */ - private def decrementOrReleaseLock(iri: IRI, apiRequestID: UUID): Unit = - lockMap.compute( + private def decrementOrReleaseLock(iri: IRI, apiRequestID: UUID): Unit = { + val _ = lockMap.compute( iri, JavaUtil.biFunction({ (_, maybeCurrentLock) => Option(maybeCurrentLock) match { @@ -209,4 +205,5 @@ object IriLocker { } }) ) + } } diff --git a/webapi/src/main/scala/org/knora/webapi/responders/admin/ProjectsResponderADM.scala b/webapi/src/main/scala/org/knora/webapi/responders/admin/ProjectsResponderADM.scala index cf5e952527..53b2812527 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/admin/ProjectsResponderADM.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/admin/ProjectsResponderADM.scala @@ -626,7 +626,7 @@ final case class ProjectsResponderADMLive( } if (projectUpdatePayload.status.nonEmpty) { - projectUpdatePayload.status + val _ = projectUpdatePayload.status .map(_.value) .filter(_ == updatedProject.status) .getOrElse( @@ -637,7 +637,7 @@ final case class ProjectsResponderADMLive( } if (projectUpdatePayload.selfjoin.nonEmpty) { - projectUpdatePayload.selfjoin + val _ = projectUpdatePayload.selfjoin .map(_.value) .filter(_ == updatedProject.selfjoin) .getOrElse( diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectExportService.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectExportService.scala index ae75726668..2b746ce275 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectExportService.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectExportService.scala @@ -109,7 +109,7 @@ private object TriGCombiner { override def prefix(prefix: String, iri: String): Unit = if (!prefixes.contains(prefix)) { writer.prefix(prefix, iri) - prefixes.add(prefix) + val _ = prefixes.add(prefix) } override def triple(triple: Triple): Unit = writer.triple(triple) override def quad(quad: Quad): Unit = writer.quad(quad) diff --git a/webapi/src/main/scala/org/knora/webapi/util/ActorUtil.scala b/webapi/src/main/scala/org/knora/webapi/util/ActorUtil.scala index 5e1ace658a..394050bf4d 100644 --- a/webapi/src/main/scala/org/knora/webapi/util/ActorUtil.scala +++ b/webapi/src/main/scala/org/knora/webapi/util/ActorUtil.scala @@ -9,6 +9,7 @@ import akka.actor.ActorRef import zio._ import dsp.errors._ +import org.knora.webapi.routing.UnsafeZioRun object ActorUtil { @@ -16,11 +17,9 @@ object ActorUtil { * _Unsafely_ runs a ZIO workflow and sends the result to the `sender` actor as a message or a failure. * Used mainly during the refactoring phase, to be able to return ZIO inside an Actor. */ - def zio2Message[R, A](sender: ActorRef, zioTask: ZIO[R, Throwable, A])(implicit runtime: Runtime[R]): Unit = - Unsafe.unsafe { implicit u => - runtime.unsafe.run( - zioTask.foldCause(cause => sender ! akka.actor.Status.Failure(cause.squash), success => sender ! success) - ) + def zio2Message[R, A](sender: ActorRef, zio: ZIO[R, Throwable, A])(implicit runtime: Runtime[R]): Unit = + UnsafeZioRun.runOrThrow { + zio.foldCause(cause => sender ! akka.actor.Status.Failure(cause.squash), success => sender ! success) } /** diff --git a/webapi/src/main/scala/org/knora/webapi/util/FileUtil.scala b/webapi/src/main/scala/org/knora/webapi/util/FileUtil.scala index 17bd78e795..9e6134603b 100644 --- a/webapi/src/main/scala/org/knora/webapi/util/FileUtil.scala +++ b/webapi/src/main/scala/org/knora/webapi/util/FileUtil.scala @@ -36,7 +36,7 @@ object FileUtil { * @param file the destination file. * @param content the string to write. */ - def writeTextFile(file: Path, content: String): Unit = + def writeTextFile(file: Path, content: String): Path = writeBinaryFile(file, content.getBytes(StandardCharsets.UTF_8)) /** @@ -93,8 +93,7 @@ object FileUtil { * @param file the destination file. * @param content the binary data to write. */ - def writeBinaryFile(file: Path, content: Array[Byte]): Unit = - Files.write(file, content) + private def writeBinaryFile(file: Path, content: Array[Byte]) = Files.write(file, content) /** * Generates a byte array representing a Zip file containing the specified data. The Zip file data is diff --git a/webapi/src/main/scala/org/knora/webapi/util/cache/CacheUtil.scala b/webapi/src/main/scala/org/knora/webapi/util/cache/CacheUtil.scala index 9edc6db718..71588268fb 100644 --- a/webapi/src/main/scala/org/knora/webapi/util/cache/CacheUtil.scala +++ b/webapi/src/main/scala/org/knora/webapi/util/cache/CacheUtil.scala @@ -138,24 +138,6 @@ object CacheUtil { } } - - /** - * Tries to remove a value from a cache. - * - * @param cacheName the name of the cache. - * @param key the cache key as a [[String]] - */ - def remove(cacheName: String, key: String): Unit = { - val cacheManager = CacheManager.getInstance() - val cacheOption = Option(cacheManager.getCache(cacheName)) - - cacheOption match { - case Some(cache) => cache.remove(key) - case None => - throw ApplicationCacheException(s"Can't find application cache '$cacheName'") - } - } - } class LoggingCacheEventListener(log: Logger) extends CacheEventListener {