From a79812fc24dca44d95c4e0e2244b465093c70a27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinb=C3=B6lting?= Date: Thu, 11 Apr 2024 13:05:06 +0200 Subject: [PATCH] chore: Scala3 preparation (introduce at least one parameter list without implicits) (#3184) --- ...searchToCountPrequeryTransformerSpec.scala | 2 +- .../GravsearchToPrequeryTransformerSpec.scala | 2 +- .../types/GravsearchTypeInspectorSpec.scala | 2 +- .../org/knora/webapi/core/AppRouter.scala | 2 +- .../webapi/core/actors/RoutingActor.scala | 5 ++--- .../util/ConstructResponseUtilV2.scala | 4 ++-- .../messages/util/search/QueryTraverser.scala | 7 ++----- .../search/gravsearch/GravsearchParser.scala | 2 +- .../InferenceOptimizationService.scala | 3 +-- .../transformers/OntologyInferencer.scala | 8 +++---- .../GravsearchTypeInspectionRunner.scala | 6 ++---- .../util/standoff/StandoffTagUtilV2.scala | 10 +++------ .../admin/AssetPermissionsResponder.scala | 3 +-- .../responders/admin/GroupsResponderADM.scala | 6 +++--- .../responders/admin/ListsResponder.scala | 3 +-- .../admin/PermissionsResponder.scala | 6 +++--- .../responders/v2/OntologyResponderV2.scala | 6 +++--- .../responders/v2/ResourcesResponderV2.scala | 7 +++---- .../responders/v2/StandoffResponderV2.scala | 6 +++--- .../responders/v2/ValuesResponderV2.scala | 6 +++--- .../v2/ontology/CardinalityHandler.scala | 9 +++----- .../v2/ontology/OntologyHelpers.scala | 21 +++++++------------ .../resources/CreateResourceV2Handler.scala | 4 ++-- .../org/knora/webapi/routing/ApiRoutes.scala | 12 +++-------- .../knora/webapi/routing/Authenticator.scala | 4 ++-- .../api/service/ProjectRestService.scala | 4 ++-- .../slice/common/api/BaseEndpoints.scala | 4 ++-- .../webapi/slice/infrastructure/Scope.scala | 2 +- .../domain/service/CardinalityService.scala | 10 ++++----- .../ontology/repo/service/OntologyCache.scala | 9 +++----- .../domain/TriplestoreStatus.scala | 2 +- .../impl/TriplestoreServiceLive.scala | 6 +++--- .../upgrade/RepositoryUpdater.scala | 15 ++++--------- 33 files changed, 79 insertions(+), 119 deletions(-) diff --git a/integration/src/test/scala/org/knora/webapi/messages/util/search/gravsearch/prequery/GravsearchToCountPrequeryTransformerSpec.scala b/integration/src/test/scala/org/knora/webapi/messages/util/search/gravsearch/prequery/GravsearchToCountPrequeryTransformerSpec.scala index 11c875341e..e55a17445a 100644 --- a/integration/src/test/scala/org/knora/webapi/messages/util/search/gravsearch/prequery/GravsearchToCountPrequeryTransformerSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/messages/util/search/gravsearch/prequery/GravsearchToCountPrequeryTransformerSpec.scala @@ -28,7 +28,7 @@ class GravsearchToCountPrequeryTransformerSpec extends CoreSpec { qt <- ZIO.service[QueryTraverser] mr <- ZIO.service[MessageRelay] sf <- ZIO.service[StringFormatter] - } yield GravsearchTypeInspectionRunner(qt, mr, sf) + } yield GravsearchTypeInspectionRunner(qt, mr)(sf) val countQueryZio = for { constructQuery <- ZIO.attempt(GravsearchParser.parseQuery(query)) diff --git a/integration/src/test/scala/org/knora/webapi/messages/util/search/gravsearch/prequery/GravsearchToPrequeryTransformerSpec.scala b/integration/src/test/scala/org/knora/webapi/messages/util/search/gravsearch/prequery/GravsearchToPrequeryTransformerSpec.scala index 02410fbe91..6feae46e29 100644 --- a/integration/src/test/scala/org/knora/webapi/messages/util/search/gravsearch/prequery/GravsearchToPrequeryTransformerSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/messages/util/search/gravsearch/prequery/GravsearchToPrequeryTransformerSpec.scala @@ -32,7 +32,7 @@ class GravsearchToPrequeryTransformerSpec extends CoreSpec { qt <- ZIO.service[QueryTraverser] mr <- ZIO.service[MessageRelay] sf <- ZIO.service[StringFormatter] - } yield GravsearchTypeInspectionRunner(qt, mr, sf) + } yield GravsearchTypeInspectionRunner(qt, mr)(sf) val preQueryZio = for { constructQuery <- ZIO.attempt(GravsearchParser.parseQuery(query)) diff --git a/integration/src/test/scala/org/knora/webapi/messages/util/search/gravsearch/types/GravsearchTypeInspectorSpec.scala b/integration/src/test/scala/org/knora/webapi/messages/util/search/gravsearch/types/GravsearchTypeInspectorSpec.scala index a21890c93b..9d0f0d12a8 100644 --- a/integration/src/test/scala/org/knora/webapi/messages/util/search/gravsearch/types/GravsearchTypeInspectorSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/messages/util/search/gravsearch/types/GravsearchTypeInspectorSpec.scala @@ -1305,7 +1305,7 @@ class GravsearchTypeInspectorSpec extends CoreSpec with ImplicitSender { qt <- ZIO.service[QueryTraverser] mr <- ZIO.service[MessageRelay] sf <- ZIO.service[StringFormatter] - } yield GravsearchTypeInspectionRunner(qt, mr, sf) + } yield GravsearchTypeInspectionRunner(qt, mr)(sf) def inspectTypes( query: String, diff --git a/webapi/src/main/scala/org/knora/webapi/core/AppRouter.scala b/webapi/src/main/scala/org/knora/webapi/core/AppRouter.scala index 71b9b20cfa..e26991eb21 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/AppRouter.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/AppRouter.scala @@ -44,7 +44,7 @@ object AppRouter { OntologyRepo & PermissionUtilADM & ResourceUtilV2 & StandoffTagUtilV2, ] ref = system.actorOf( - Props(core.actors.RoutingActor(messageRelay, runtime)).withRouter(new RoundRobinPool(1_000)), + Props(core.actors.RoutingActor(messageRelay)(runtime)).withRouter(new RoundRobinPool(1_000)), "applicationManager", ) } yield AppRouter(system, ref), diff --git a/webapi/src/main/scala/org/knora/webapi/core/actors/RoutingActor.scala b/webapi/src/main/scala/org/knora/webapi/core/actors/RoutingActor.scala index d65e944468..c7154537f4 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/actors/RoutingActor.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/actors/RoutingActor.scala @@ -22,9 +22,8 @@ import org.knora.webapi.slice.ontology.domain.service.OntologyRepo import org.knora.webapi.slice.ontology.repo.service.OntologyCache import org.knora.webapi.util.ActorUtil -final case class RoutingActor( - messageRelay: MessageRelay, - implicit val runtime: Runtime[ +final case class RoutingActor(messageRelay: MessageRelay)(implicit + val runtime: Runtime[ CardinalityHandler & CardinalityService & ConstructResponseUtilV2 & OntologyCache & OntologyHelpers & OntologyRepo & PermissionUtilADM & ResourceUtilV2 & StandoffTagUtilV2, ], diff --git a/webapi/src/main/scala/org/knora/webapi/messages/util/ConstructResponseUtilV2.scala b/webapi/src/main/scala/org/knora/webapi/messages/util/ConstructResponseUtilV2.scala index 46b0b88cc4..bb78184d27 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/util/ConstructResponseUtilV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/util/ConstructResponseUtilV2.scala @@ -424,8 +424,8 @@ final case class ConstructResponseUtilV2Live( messageRelay: MessageRelay, standoffTagUtilV2: StandoffTagUtilV2, projectService: ProjectService, - implicit val stringFormatter: StringFormatter, -) extends ConstructResponseUtilV2 { +)(implicit val stringFormatter: StringFormatter) + extends ConstructResponseUtilV2 { private val inferredPredicates = Set( OntologyConstants.KnoraBase.HasValue, diff --git a/webapi/src/main/scala/org/knora/webapi/messages/util/search/QueryTraverser.scala b/webapi/src/main/scala/org/knora/webapi/messages/util/search/QueryTraverser.scala index 8154dba753..b6a3253449 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/util/search/QueryTraverser.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/util/search/QueryTraverser.scala @@ -59,9 +59,7 @@ case class TransformedOrderBy( /** * Assists in the transformation of CONSTRUCT queries by traversing the query, delegating work to a [[AbstractPrequeryGenerator]]. */ -final case class QueryTraverser( - private val messageRelay: MessageRelay, - private val ontologyCache: OntologyCache, +final case class QueryTraverser(private val messageRelay: MessageRelay, private val ontologyCache: OntologyCache)( implicit private val stringFormatter: StringFormatter, ) { @@ -321,6 +319,5 @@ final case class QueryTraverser( } object QueryTraverser { - val layer: URLayer[MessageRelay & OntologyCache & StringFormatter, QueryTraverser] = - ZLayer.fromFunction(QueryTraverser.apply _) + val layer = ZLayer.derive[QueryTraverser] } 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 9ee01e47ed..c212b1a8c8 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 @@ -355,7 +355,7 @@ object GravsearchParser { val sourceName: String = projectionElem.getName val targetName: Option[String] = projectionElem.getProjectionAlias.toScala - if (sourceName == targetName) { + if (targetName.contains(sourceName)) { throw GravsearchException(s"SELECT queries are not allowed in search, please use a CONSTRUCT query instead") } diff --git a/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/prequery/InferenceOptimizationService.scala b/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/prequery/InferenceOptimizationService.scala index feca0b0af6..82164bf4d0 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/prequery/InferenceOptimizationService.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/prequery/InferenceOptimizationService.scala @@ -30,8 +30,7 @@ import org.knora.webapi.slice.ontology.repo.service.OntologyCache final case class InferenceOptimizationService( private val projectService: ProjectService, private val ontologyCache: OntologyCache, - implicit private val stringFormatter: StringFormatter, -) { +)(implicit private val stringFormatter: StringFormatter) { /** * Helper method that analyzed an RDF Entity and returns a sequence of Ontology IRIs that are being referenced by the entity. diff --git a/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/transformers/OntologyInferencer.scala b/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/transformers/OntologyInferencer.scala index 4fa3c0e991..d77f6da957 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/transformers/OntologyInferencer.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/transformers/OntologyInferencer.scala @@ -17,9 +17,8 @@ import org.knora.webapi.messages.util.search._ import org.knora.webapi.slice.ontology.repo.model.OntologyCacheData import org.knora.webapi.slice.ontology.repo.service.OntologyCache -final case class OntologyInferencer( - private val ontologyCache: OntologyCache, - implicit private val stringFormatter: StringFormatter, +final case class OntologyInferencer(private val ontologyCache: OntologyCache)(implicit + private val stringFormatter: StringFormatter, ) { private def inferSubclasses( @@ -151,6 +150,5 @@ final case class OntologyInferencer( } object OntologyInferencer { - val layer: ZLayer[OntologyCache & StringFormatter, Nothing, OntologyInferencer] = - ZLayer.fromFunction(OntologyInferencer.apply _) + val layer = ZLayer.derive[OntologyInferencer] } diff --git a/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/types/GravsearchTypeInspectionRunner.scala b/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/types/GravsearchTypeInspectionRunner.scala index a39fd981df..62edeb89b8 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/types/GravsearchTypeInspectionRunner.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/types/GravsearchTypeInspectionRunner.scala @@ -22,8 +22,7 @@ import org.knora.webapi.slice.admin.domain.model.User final case class GravsearchTypeInspectionRunner( private val queryTraverser: QueryTraverser, private val messageRelay: MessageRelay, - implicit private val stringFormatter: StringFormatter, -) { +)(implicit private val stringFormatter: StringFormatter) { private val inferringInspector: InferringGravsearchTypeInspector = InferringGravsearchTypeInspector(messageRelay, queryTraverser) private val annotationReadingInspector: AnnotationReadingGravsearchTypeInspector = @@ -169,6 +168,5 @@ final case class GravsearchTypeInspectionRunner( } object GravsearchTypeInspectionRunner { - val layer: ZLayer[QueryTraverser & MessageRelay & StringFormatter, Nothing, GravsearchTypeInspectionRunner] = - ZLayer.fromFunction(GravsearchTypeInspectionRunner.apply _) + val layer = ZLayer.derive[GravsearchTypeInspectionRunner] } diff --git a/webapi/src/main/scala/org/knora/webapi/messages/util/standoff/StandoffTagUtilV2.scala b/webapi/src/main/scala/org/knora/webapi/messages/util/standoff/StandoffTagUtilV2.scala index 37721b29a0..c1d5bc6ca8 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/util/standoff/StandoffTagUtilV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/util/standoff/StandoffTagUtilV2.scala @@ -6,7 +6,6 @@ package org.knora.webapi.messages.util.standoff import zio.Task -import zio.URLayer import zio.ZLayer import java.time.Instant @@ -61,10 +60,8 @@ trait StandoffTagUtilV2 { ): Task[Vector[StandoffTagV2]] } -final case class StandoffTagUtilV2Live( - messageRelay: MessageRelay, - implicit val stringFormatter: StringFormatter, -) extends StandoffTagUtilV2 { +final case class StandoffTagUtilV2Live(messageRelay: MessageRelay)(implicit val stringFormatter: StringFormatter) + extends StandoffTagUtilV2 { /** * Creates a sequence of [[StandoffTagV2]] from the given standoff nodes resulting from a SPARQL CONSTRUCT query. @@ -268,8 +265,7 @@ final case class StandoffTagUtilV2Live( } object StandoffTagUtilV2Live { - val layer: URLayer[MessageRelay & StringFormatter, StandoffTagUtilV2] = - ZLayer.fromFunction(StandoffTagUtilV2Live.apply _) + val layer = ZLayer.derive[StandoffTagUtilV2Live] } object StandoffTagUtilV2 { diff --git a/webapi/src/main/scala/org/knora/webapi/responders/admin/AssetPermissionsResponder.scala b/webapi/src/main/scala/org/knora/webapi/responders/admin/AssetPermissionsResponder.scala index bc03b7b1b1..d12d8fcc65 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/admin/AssetPermissionsResponder.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/admin/AssetPermissionsResponder.scala @@ -31,8 +31,7 @@ import org.knora.webapi.store.triplestore.api.TriplestoreService.Queries.Constru final case class AssetPermissionsResponder( private val knoraProjectService: KnoraProjectService, private val triplestoreService: TriplestoreService, - private implicit val sf: StringFormatter, -) { +)(private implicit val sf: StringFormatter) { def getPermissionCodeAndProjectRestrictedViewSettings( shortcode: ShortcodeIdentifier, diff --git a/webapi/src/main/scala/org/knora/webapi/responders/admin/GroupsResponderADM.scala b/webapi/src/main/scala/org/knora/webapi/responders/admin/GroupsResponderADM.scala index 780ff330bd..b39b644cf8 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/admin/GroupsResponderADM.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/admin/GroupsResponderADM.scala @@ -52,8 +52,8 @@ final case class GroupsResponderADM( iriService: IriService, knoraUserService: KnoraUserService, projectService: ProjectService, - implicit val stringFormatter: StringFormatter, -) extends MessageHandler +)(implicit val stringFormatter: StringFormatter) + extends MessageHandler with GroupsADMJsonProtocol with LazyLogging { @@ -394,7 +394,7 @@ object GroupsResponderADM { kus <- ZIO.service[KnoraUserService] ps <- ZIO.service[ProjectService] mr <- ZIO.service[MessageRelay] - handler <- mr.subscribe(GroupsResponderADM(ts, mr, iris, kus, ps, sf)) + handler <- mr.subscribe(GroupsResponderADM(ts, mr, iris, kus, ps)(sf)) } yield handler } } diff --git a/webapi/src/main/scala/org/knora/webapi/responders/admin/ListsResponder.scala b/webapi/src/main/scala/org/knora/webapi/responders/admin/ListsResponder.scala index 85507b9e0a..752458bd32 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/admin/ListsResponder.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/admin/ListsResponder.scala @@ -51,8 +51,7 @@ final case class ListsResponder( knoraProjectService: KnoraProjectService, mapper: PredicateObjectMapper, triplestore: TriplestoreService, - implicit val stringFormatter: StringFormatter, -) { +)(implicit val stringFormatter: StringFormatter) { // The IRI used to lock user creation and update private val LISTS_GLOBAL_LOCK_IRI = "http://rdfh.ch/lists" diff --git a/webapi/src/main/scala/org/knora/webapi/responders/admin/PermissionsResponder.scala b/webapi/src/main/scala/org/knora/webapi/responders/admin/PermissionsResponder.scala index 4e4779dd29..16304f4037 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/admin/PermissionsResponder.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/admin/PermissionsResponder.scala @@ -57,8 +57,8 @@ final case class PermissionsResponder( triplestore: TriplestoreService, auth: AuthorizationRestService, administrativePermissionService: AdministrativePermissionService, - implicit val stringFormatter: StringFormatter, -) extends MessageHandler +)(implicit val stringFormatter: StringFormatter) + extends MessageHandler with LazyLogging { private val PERMISSIONS_GLOBAL_LOCK_IRI = "http://rdfh.ch/permissions" @@ -1777,7 +1777,7 @@ object PermissionsResponder { ts <- ZIO.service[TriplestoreService] sf <- ZIO.service[StringFormatter] aps <- ZIO.service[AdministrativePermissionService] - handler <- mr.subscribe(PermissionsResponder(ac, gs, is, kpr, mr, ts, au, aps, sf)) + handler <- mr.subscribe(PermissionsResponder(ac, gs, is, kpr, mr, ts, au, aps)(sf)) } yield handler } } diff --git a/webapi/src/main/scala/org/knora/webapi/responders/v2/OntologyResponderV2.scala b/webapi/src/main/scala/org/knora/webapi/responders/v2/OntologyResponderV2.scala index 8feba87f5e..a7b6cddece 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/v2/OntologyResponderV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/v2/OntologyResponderV2.scala @@ -77,8 +77,8 @@ final case class OntologyResponderV2Live( knoraProjectService: KnoraProjectService, triplestoreService: TriplestoreService, cacheService: CacheService, - implicit val stringFormatter: StringFormatter, -) extends OntologyResponderV2 +)(implicit val stringFormatter: StringFormatter) + extends OntologyResponderV2 with MessageHandler with LazyLogging { @@ -2983,7 +2983,7 @@ object OntologyResponderV2Live { sf <- ZIO.service[StringFormatter] ts <- ZIO.service[TriplestoreService] cache <- ZIO.service[CacheService] - responder = OntologyResponderV2Live(ac, ch, cs, is, oc, oh, or, kr, ts, cache, sf) + responder = OntologyResponderV2Live(ac, ch, cs, is, oc, oh, or, kr, ts, cache)(sf) _ <- ZIO.serviceWithZIO[MessageRelay](_.subscribe(responder)) } yield responder } 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 75836ad412..cca6d4267d 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 @@ -88,8 +88,8 @@ final case class ResourcesResponderV2( knoraProjectService: KnoraProjectService, searchResponderV2: SearchResponderV2, ontologyRepo: OntologyRepo, - implicit val stringFormatter: StringFormatter, -) extends MessageHandler +)(implicit val stringFormatter: StringFormatter) + extends MessageHandler with LazyLogging with GetResources { @@ -105,7 +105,6 @@ final case class ResourcesResponderV2( searchResponderV2, this, ontologyRepo, - stringFormatter, ) override def isResponsibleFor(message: ResponderRequest): Boolean = @@ -2019,7 +2018,7 @@ object ResourcesResponderV2 { sr <- ZIO.service[SearchResponderV2] or <- ZIO.service[OntologyRepo] sf <- ZIO.service[StringFormatter] - handler <- mr.subscribe(ResourcesResponderV2(config, iriS, mr, ts, cu, su, ru, pu, pr, sr, or, sf)) + handler <- mr.subscribe(ResourcesResponderV2(config, iriS, mr, ts, cu, su, ru, pu, pr, sr, or)(sf)) } yield handler } } diff --git a/webapi/src/main/scala/org/knora/webapi/responders/v2/StandoffResponderV2.scala b/webapi/src/main/scala/org/knora/webapi/responders/v2/StandoffResponderV2.scala index 6d2f7ba973..40090c8158 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/v2/StandoffResponderV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/v2/StandoffResponderV2.scala @@ -67,8 +67,8 @@ final case class StandoffResponderV2( constructResponseUtilV2: ConstructResponseUtilV2, standoffTagUtilV2: StandoffTagUtilV2, projectService: ProjectService, - implicit val stringFormatter: StringFormatter, -) extends MessageHandler +)(implicit val stringFormatter: StringFormatter) + extends MessageHandler with LazyLogging { private val xmlMimeTypes = Set("text/xml", "application/xml") @@ -996,7 +996,7 @@ object StandoffResponderV2 { stu <- ZIO.service[StandoffTagUtilV2] ps <- ZIO.service[ProjectService] sf <- ZIO.service[StringFormatter] - handler <- mr.subscribe(StandoffResponderV2(ac, mr, ts, cru, stu, ps, sf)) + handler <- mr.subscribe(StandoffResponderV2(ac, mr, ts, cru, stu, ps)(sf)) } yield handler } } 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 6607b8c924..c59904ebe4 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 @@ -81,8 +81,8 @@ final case class ValuesResponderV2Live( resourceUtilV2: ResourceUtilV2, searchResponderV2: SearchResponderV2, triplestoreService: TriplestoreService, - implicit val stringFormatter: StringFormatter, -) extends ValuesResponderV2 +)(implicit val stringFormatter: StringFormatter) + extends ValuesResponderV2 with MessageHandler { override def isResponsibleFor(message: ResponderRequest): Boolean = message.isInstanceOf[ValuesResponderRequestV2] @@ -2448,7 +2448,7 @@ object ValuesResponderV2Live { ts <- ZIO.service[TriplestoreService] sr <- ZIO.service[SearchResponderV2] sf <- ZIO.service[StringFormatter] - handler <- mr.subscribe(ValuesResponderV2Live(config, is, mr, pu, ru, sr, ts, sf)) + handler <- mr.subscribe(ValuesResponderV2Live(config, is, mr, pu, ru, sr, ts)(sf)) } yield handler } } diff --git a/webapi/src/main/scala/org/knora/webapi/responders/v2/ontology/CardinalityHandler.scala b/webapi/src/main/scala/org/knora/webapi/responders/v2/ontology/CardinalityHandler.scala index c938b3f044..c2fba8f357 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/v2/ontology/CardinalityHandler.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/v2/ontology/CardinalityHandler.scala @@ -77,8 +77,8 @@ final case class CardinalityHandlerLive( triplestoreService: TriplestoreService, messageRelay: MessageRelay, ontologyHelpers: OntologyHelpers, - implicit val stringFormatter: StringFormatter, -) extends CardinalityHandler { +)(implicit val stringFormatter: StringFormatter) + extends CardinalityHandler { /** * @param deleteCardinalitiesFromClassRequest the requested cardinalities to be deleted. @@ -487,8 +487,5 @@ final case class CardinalityHandlerLive( } object CardinalityHandlerLive { - val layer: URLayer[ - OntologyCache & TriplestoreService & MessageRelay & OntologyHelpers & StringFormatter, - CardinalityHandler, - ] = ZLayer.fromFunction(CardinalityHandlerLive.apply _) + val layer = ZLayer.derive[CardinalityHandlerLive] } 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 734c7a1619..2a96a55a1d 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 @@ -1566,8 +1566,8 @@ final case class OntologyHelpersLive( messageRelay: MessageRelay, triplestore: TriplestoreService, ontologyCache: OntologyCache, - implicit val stringFormatter: StringFormatter, -) extends OntologyHelpers { +)(implicit val stringFormatter: StringFormatter) + extends OntologyHelpers { /** * Reads an ontology's metadata. @@ -2147,13 +2147,11 @@ final case class OntologyHelpersLive( */ override def checkExternalOntologyIriForUpdate(externalOntologyIri: SmartIri): Task[Unit] = if (!externalOntologyIri.isKnoraOntologyIri) { - ZIO.fail(throw BadRequestException(s"Invalid ontology IRI for request: $externalOntologyIri}")) + ZIO.fail(BadRequestException(s"Invalid ontology IRI for request: $externalOntologyIri}")) } else if (!externalOntologyIri.getOntologySchema.contains(ApiV2Complex)) { - ZIO.fail(throw BadRequestException(s"Invalid ontology schema for request: $externalOntologyIri")) + ZIO.fail(BadRequestException(s"Invalid ontology schema for request: $externalOntologyIri")) } else if (externalOntologyIri.isKnoraBuiltInDefinitionIri) { - ZIO.fail( - throw BadRequestException(s"Ontology $externalOntologyIri cannot be modified via the Knora API"), - ) + ZIO.fail(BadRequestException(s"Ontology $externalOntologyIri cannot be modified via the Knora API")) } else { ZIO.succeed(()) } @@ -2166,9 +2164,9 @@ final case class OntologyHelpersLive( */ private def checkExternalEntityIriForUpdate(externalEntityIri: SmartIri): Task[Unit] = if (!externalEntityIri.isKnoraApiV2EntityIri) { - ZIO.fail(throw BadRequestException(s"Invalid entity IRI for request: $externalEntityIri")) + ZIO.fail(BadRequestException(s"Invalid entity IRI for request: $externalEntityIri")) } else if (!externalEntityIri.getOntologySchema.contains(ApiV2Complex)) { - ZIO.fail(throw BadRequestException(s"Invalid ontology schema for request: $externalEntityIri")) + ZIO.fail(BadRequestException(s"Invalid ontology schema for request: $externalEntityIri")) } else { ZIO.succeed(()) } @@ -2176,8 +2174,5 @@ final case class OntologyHelpersLive( } object OntologyHelpersLive { - val layer: URLayer[ - AppConfig & IriService & MessageRelay & TriplestoreService & OntologyCache & StringFormatter, - OntologyHelpers, - ] = ZLayer.fromFunction(OntologyHelpersLive.apply _) + val layer = ZLayer.derive[OntologyHelpersLive] } 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 161a72cfe6..358a6ed3b2 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 @@ -59,8 +59,8 @@ final case class CreateResourceV2Handler( searchResponderV2: SearchResponderV2, getResources: GetResources, ontologyRepo: OntologyRepo, - implicit val stringFormatter: StringFormatter, -) extends LazyLogging { +)(implicit val stringFormatter: StringFormatter) + extends LazyLogging { /** * Represents a resource that is ready to be created and whose contents can be verified afterwards. diff --git a/webapi/src/main/scala/org/knora/webapi/routing/ApiRoutes.scala b/webapi/src/main/scala/org/knora/webapi/routing/ApiRoutes.scala index b15c5fbb48..67367a6b2f 100644 --- a/webapi/src/main/scala/org/knora/webapi/routing/ApiRoutes.scala +++ b/webapi/src/main/scala/org/knora/webapi/routing/ApiRoutes.scala @@ -49,8 +49,8 @@ final case class ApiRoutes( searchApiRoutes: SearchApiRoutes, managementRoutes: ManagementRoutes, appConfig: AppConfig, - implicit val runtime: Runtime[ApiRoutes.ApiRoutesRuntime], -) extends AroundDirectives { +)(implicit val runtime: Runtime[ApiRoutes.ApiRoutesRuntime]) + extends AroundDirectives { private implicit val system: ActorSystem = routeData.system @@ -103,13 +103,7 @@ object ApiRoutes { managementRoutes <- ZIO.service[ManagementRoutes] routeData <- ZIO.succeed(KnoraRouteData(sys, router.ref, appConfig)) runtime <- ZIO.runtime[ApiRoutesRuntime] - } yield ApiRoutes( - routeData, - adminApiRoutes, - resourceInfoRoutes, - searchApiRoutes, - managementRoutes, - appConfig, + } yield ApiRoutes(routeData, adminApiRoutes, resourceInfoRoutes, searchApiRoutes, managementRoutes, appConfig)( runtime, ) } diff --git a/webapi/src/main/scala/org/knora/webapi/routing/Authenticator.scala b/webapi/src/main/scala/org/knora/webapi/routing/Authenticator.scala index 8f08c373b7..b7609c5260 100644 --- a/webapi/src/main/scala/org/knora/webapi/routing/Authenticator.scala +++ b/webapi/src/main/scala/org/knora/webapi/routing/Authenticator.scala @@ -144,8 +144,8 @@ final case class AuthenticatorLive( private val userService: UserService, private val jwtService: JwtService, private val passwordService: PasswordService, - private implicit val stringFormatter: StringFormatter, -) extends Authenticator { +)(private implicit val stringFormatter: StringFormatter) + extends Authenticator { /** * Checks if the provided credentials are valid, and if so returns a JWT token for the client to save. diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/ProjectRestService.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/ProjectRestService.scala index d6d18ceb33..d875e74680 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/ProjectRestService.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/ProjectRestService.scala @@ -291,8 +291,8 @@ final case class ProjectRestService( def importProject(shortcode: Shortcode, user: User): Task[ProjectImportResponse] = for { _ <- auth.ensureSystemAdmin(user) path <- projectImportService.importProject(shortcode).flatMap { - case Some(export) => export.toAbsolutePath.map(_.toString) - case None => ZIO.fail(NotFoundException(s"Project export for ${shortcode.value} not found.")) + case Some(ex) => ex.toAbsolutePath.map(_.toString) + case None => ZIO.fail(NotFoundException(s"Project export for ${shortcode.value} not found.")) } } yield ProjectImportResponse(path) diff --git a/webapi/src/main/scala/org/knora/webapi/slice/common/api/BaseEndpoints.scala b/webapi/src/main/scala/org/knora/webapi/slice/common/api/BaseEndpoints.scala index 566113c097..8ecd267228 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/common/api/BaseEndpoints.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/common/api/BaseEndpoints.scala @@ -32,7 +32,7 @@ import org.knora.webapi.routing.UnsafeZioRun import org.knora.webapi.slice.admin.domain.model.Email import org.knora.webapi.slice.admin.domain.model.User -final case class BaseEndpoints(authenticator: Authenticator, implicit val r: zio.Runtime[Any]) { +final case class BaseEndpoints(authenticator: Authenticator)(implicit val r: zio.Runtime[Any]) { private val defaultErrorOutputs: EndpointOutput.OneOf[RequestRejectedException, RequestRejectedException] = oneOf[RequestRejectedException]( @@ -102,6 +102,6 @@ object BaseEndpoints { for { auth <- ZIO.service[Authenticator] r <- ZIO.runtime[Any] - } yield BaseEndpoints(auth, r), + } yield BaseEndpoints(auth)(r), ) } diff --git a/webapi/src/main/scala/org/knora/webapi/slice/infrastructure/Scope.scala b/webapi/src/main/scala/org/knora/webapi/slice/infrastructure/Scope.scala index 5535c32476..d754047980 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/infrastructure/Scope.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/infrastructure/Scope.scala @@ -33,7 +33,7 @@ object ScopeValue { override def toScopeString: String = s"write:project:${project.value}" } - final case object Admin extends ScopeValue { + case object Admin extends ScopeValue { override def toScopeString: String = "admin" } diff --git a/webapi/src/main/scala/org/knora/webapi/slice/ontology/domain/service/CardinalityService.scala b/webapi/src/main/scala/org/knora/webapi/slice/ontology/domain/service/CardinalityService.scala index 4ad378acd2..7ca11d0629 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/ontology/domain/service/CardinalityService.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/ontology/domain/service/CardinalityService.scala @@ -88,15 +88,15 @@ object ChangeCardinalityCheckResult { object CanReplaceCardinalityCheckResult { sealed trait CanReplaceCardinalityCheckResult extends ChangeCardinalityCheckResult - final case object Success extends Success with CanReplaceCardinalityCheckResult + case object Success extends Success with CanReplaceCardinalityCheckResult trait Failure extends ChangeCardinalityCheckResult.Failure with CanReplaceCardinalityCheckResult - final case object IsInUseCheckFailure extends CanReplaceCardinalityCheckResult.Failure { + case object IsInUseCheckFailure extends CanReplaceCardinalityCheckResult.Failure { override val reason: String = "Cardinality is in use." } - final case object KnoraOntologyCheckFailure + case object KnoraOntologyCheckFailure extends ChangeCardinalityCheckResult.KnoraOntologyCheckFailure with CanReplaceCardinalityCheckResult.Failure } @@ -104,7 +104,7 @@ object ChangeCardinalityCheckResult { object CanSetCardinalityCheckResult { sealed trait CanSetCardinalityCheckResult extends ChangeCardinalityCheckResult - final case object Success extends Success with CanSetCardinalityCheckResult + case object Success extends Success with CanSetCardinalityCheckResult trait Failure extends ChangeCardinalityCheckResult.Failure with CanSetCardinalityCheckResult @@ -124,7 +124,7 @@ object ChangeCardinalityCheckResult { val reason: String = "The cardinality of the current class is not included in the new cardinality." } - final case object KnoraOntologyCheckFailure + case object KnoraOntologyCheckFailure extends ChangeCardinalityCheckResult.KnoraOntologyCheckFailure with CanSetCardinalityCheckResult.Failure } diff --git a/webapi/src/main/scala/org/knora/webapi/slice/ontology/repo/service/OntologyCache.scala b/webapi/src/main/scala/org/knora/webapi/slice/ontology/repo/service/OntologyCache.scala index 25065b6f59..34a65afb62 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/ontology/repo/service/OntologyCache.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/ontology/repo/service/OntologyCache.scala @@ -485,10 +485,8 @@ trait OntologyCache { ): Task[OntologyCacheData] } -final case class OntologyCacheLive( - triplestore: TriplestoreService, - implicit val stringFormatter: StringFormatter, -) extends OntologyCache +final case class OntologyCacheLive(triplestore: TriplestoreService)(implicit val stringFormatter: StringFormatter) + extends OntologyCache with LazyLogging { /** @@ -1070,6 +1068,5 @@ final case class OntologyCacheLive( } object OntologyCacheLive { - val layer: URLayer[TriplestoreService & StringFormatter, OntologyCache] = - ZLayer.fromFunction(OntologyCacheLive.apply _) + val layer = ZLayer.derive[OntologyCacheLive] } diff --git a/webapi/src/main/scala/org/knora/webapi/store/triplestore/domain/TriplestoreStatus.scala b/webapi/src/main/scala/org/knora/webapi/store/triplestore/domain/TriplestoreStatus.scala index 7649825290..074159609e 100644 --- a/webapi/src/main/scala/org/knora/webapi/store/triplestore/domain/TriplestoreStatus.scala +++ b/webapi/src/main/scala/org/knora/webapi/store/triplestore/domain/TriplestoreStatus.scala @@ -17,7 +17,7 @@ sealed trait TriplestoreStatus { object TriplestoreStatus { final case class Unavailable(msg: String) extends TriplestoreStatus final case class NotInitialized(msg: String) extends TriplestoreStatus - final case object Available extends TriplestoreStatus { + case object Available extends TriplestoreStatus { val msg = "Triplestore is available." } } diff --git a/webapi/src/main/scala/org/knora/webapi/store/triplestore/impl/TriplestoreServiceLive.scala b/webapi/src/main/scala/org/knora/webapi/store/triplestore/impl/TriplestoreServiceLive.scala index cd728e9271..4238328add 100644 --- a/webapi/src/main/scala/org/knora/webapi/store/triplestore/impl/TriplestoreServiceLive.scala +++ b/webapi/src/main/scala/org/knora/webapi/store/triplestore/impl/TriplestoreServiceLive.scala @@ -70,8 +70,8 @@ case class TriplestoreServiceLive( triplestoreConfig: Triplestore, queryHttpClient: CloseableHttpClient, targetHost: HttpHost, - implicit val sf: StringFormatter, -) extends TriplestoreService +)(implicit val sf: StringFormatter) + extends TriplestoreService with FusekiTriplestore { private val requestTimer = @@ -655,6 +655,6 @@ object TriplestoreServiceLive { config <- ZIO.service[Triplestore] host = new HttpHost(config.host, config.fuseki.port, "http") client <- makeHttpClient(config, host) - } yield TriplestoreServiceLive(config, client, host, sf) + } yield TriplestoreServiceLive(config, client, host)(sf) } } diff --git a/webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/RepositoryUpdater.scala b/webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/RepositoryUpdater.scala index 4b5f461622..53ffd6d2c1 100644 --- a/webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/RepositoryUpdater.scala +++ b/webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/RepositoryUpdater.scala @@ -12,7 +12,6 @@ import zio._ import java.io.File import java.nio.file.Files import java.nio.file.Path -import scala.reflect.io.Directory import dsp.errors.InconsistentRepositoryDataException import org.knora.webapi.messages.store.triplestoremessages._ @@ -85,19 +84,13 @@ final case class RepositoryUpdater(triplestoreService: TriplestoreService) { /** * Deletes directories inside tmp directory starting with `tmpDirNamePrefix`. */ - private def deleteTmpDirectories(): UIO[Unit] = ZIO.attempt { + private def deleteTmpDirectories(): UIO[Unit] = { val rootDir = new File("/tmp/") val getTmpToDelete = rootDir.listFiles.filter(_.getName.startsWith(tmpDirNamePrefix)) - - if (getTmpToDelete.length != 0) { - getTmpToDelete.foreach { dir => - val dirToDelete = new Directory(dir) - dirToDelete.deleteRecursively() - } - log.info(s"Deleted tmp directories: ${getTmpToDelete.map(_.getName()).mkString(", ")}") + ZIO.foreach(getTmpToDelete) { dir => + zio.nio.file.Files.deleteRecursive(zio.nio.file.Path(dir.getPath)) } - () - }.orDie + }.unit.orDie /** * Determines the `knora-base` version in the repository.