Skip to content

Commit

Permalink
chore: Scala3 preparation (introduce at least one parameter list with…
Browse files Browse the repository at this point in the history
…out implicits) (#3184)
  • Loading branch information
seakayone authored Apr 11, 2024
1 parent 93fd50f commit a79812f
Show file tree
Hide file tree
Showing 33 changed files with 79 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {

Expand Down Expand Up @@ -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]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package org.knora.webapi.messages.util.standoff

import zio.Task
import zio.URLayer
import zio.ZLayer

import java.time.Instant
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -105,7 +105,6 @@ final case class ResourcesResponderV2(
searchResponderV2,
this,
ontologyRepo,
stringFormatter,
)

override def isResponsibleFor(message: ResponderRequest): Boolean =
Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(())
}
Expand All @@ -2166,18 +2164,15 @@ 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(())
}

}

object OntologyHelpersLive {
val layer: URLayer[
AppConfig & IriService & MessageRelay & TriplestoreService & OntologyCache & StringFormatter,
OntologyHelpers,
] = ZLayer.fromFunction(OntologyHelpersLive.apply _)
val layer = ZLayer.derive[OntologyHelpersLive]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading

0 comments on commit a79812f

Please sign in to comment.