Skip to content

Commit

Permalink
refactor: Introduce model for SliceModules (#3288)
Browse files Browse the repository at this point in the history
Co-authored-by: Balduin Landolt <[email protected]>
  • Loading branch information
seakayone and BalduinLandolt authored Jun 18, 2024
1 parent 1ed1506 commit 2687412
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 141 deletions.
19 changes: 19 additions & 0 deletions webapi/src/main/scala/org/knora/webapi/slice/SliceModule.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright © 2021 - 2024 Swiss National Data and Service Center for the Humanities and/or DaSCH Service Platform contributors.
* SPDX-License-Identifier: Apache-2.0
*/

package org.knora.webapi.slice
import zio.ZLayer

trait SliceModule[RIn, E, ROut] {
type Dependencies = RIn
type Provided = ROut
inline def layer: ZLayer[RIn, E, ROut]
}

type RModule[RIn, ROut] = SliceModule[RIn, Throwable, ROut]
type URModule[RIn, ROut] = SliceModule[RIn, Nothing, ROut]
type Module[E, ROut] = SliceModule[Any, E, ROut]
type UModule[ROut] = SliceModule[Any, Nothing, ROut]
type TaskModule[ROut] = SliceModule[Any, Throwable, ROut]
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import zio.URLayer

import org.knora.webapi.config.AppConfig
import org.knora.webapi.responders.IriService
import org.knora.webapi.slice.URModule
import org.knora.webapi.slice.admin.domain.AdminDomainModule
import org.knora.webapi.slice.admin.domain.service.DspIngestClient
import org.knora.webapi.slice.admin.repo.AdminRepoModule
Expand All @@ -19,22 +20,22 @@ import org.knora.webapi.slice.ontology.repo.service.OntologyCache
import org.knora.webapi.slice.resourceinfo.domain.IriConverter
import org.knora.webapi.store.triplestore.api.TriplestoreService

object AdminModule {

type Dependencies =
// format: off
AppConfig &
CacheManager &
DspIngestClient &
IriService &
IriConverter &
OntologyRepo &
OntologyCache &
PredicateObjectMapper &
TriplestoreService
// format: on

type Provided = AdminDomainModule.Provided

val layer: URLayer[Dependencies, Provided] = AdminRepoModule.layer >>> AdminDomainModule.layer
object AdminModule
extends URModule[
// format: off
AppConfig &
CacheManager &
DspIngestClient &
IriConverter &
IriService &
OntologyCache &
OntologyRepo &
PredicateObjectMapper &
TriplestoreService
,
AdminDomainModule.Provided
// format: on
] { self =>
inline def layer: URLayer[self.Dependencies, self.Provided] =
AdminRepoModule.layer >>> AdminDomainModule.layer
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

package org.knora.webapi.slice.admin.api

import zio.URLayer
import zio.ZLayer

import org.knora.webapi.config.AppConfig
import org.knora.webapi.config.Features
import org.knora.webapi.responders.admin.AssetPermissionsResponder
import org.knora.webapi.responders.admin.ListsResponder
import org.knora.webapi.responders.admin.PermissionsResponder
import org.knora.webapi.slice.URModule
import org.knora.webapi.slice.admin.api.service.GroupRestService
import org.knora.webapi.slice.admin.api.service.MaintenanceRestService
import org.knora.webapi.slice.admin.api.service.PermissionRestService
Expand All @@ -36,44 +38,47 @@ import org.knora.webapi.slice.infrastructure.CacheManager
import org.knora.webapi.slice.ontology.repo.service.OntologyCache
import org.knora.webapi.store.triplestore.api.TriplestoreService

object AdminApiModule {

type Dependencies =
// format: off
AdministrativePermissionService &
AppConfig &
AssetPermissionsResponder &
AuthorizationRestService &
BaseEndpoints &
CacheManager &
Features &
GroupService &
HandlerMapper &
KnoraGroupService &
KnoraProjectService &
KnoraResponseRenderer &
KnoraUserService &
KnoraUserToUserConverter &
ListsResponder &
MaintenanceService &
OntologyCache &
PasswordService &
PermissionsResponder &
ProjectEraseService &
ProjectExportService &
ProjectImportService &
ProjectService &
TapirToPekkoInterpreter &
TriplestoreService &
UserService
// format: on

type Provided = AdminApiEndpoints & AdminApiRoutes &
// the `*RestService`s are only exposed for the integration tests
GroupRestService & UserRestService & ProjectRestService & PermissionRestService

val layer: ZLayer[Dependencies, Nothing, Provided] =
ZLayer.makeSome[Dependencies, Provided](
object AdminApiModule
extends URModule[
// format: off
AdministrativePermissionService &
AppConfig &
AssetPermissionsResponder &
AuthorizationRestService &
BaseEndpoints &
CacheManager &
Features &
GroupService &
HandlerMapper &
KnoraGroupService &
KnoraProjectService &
KnoraResponseRenderer &
KnoraUserService &
KnoraUserToUserConverter &
ListsResponder &
MaintenanceService &
OntologyCache &
PasswordService &
PermissionsResponder &
ProjectEraseService &
ProjectExportService &
ProjectImportService &
ProjectService &
TapirToPekkoInterpreter &
TriplestoreService &
UserService
,
AdminApiEndpoints &
AdminApiRoutes &
// the `*RestService`s are only exposed for the integration tests
GroupRestService &
PermissionRestService &
ProjectRestService &
UserRestService
// format: on
] { self =>
inline def layer: URLayer[self.Dependencies, self.Provided] =
ZLayer.makeSome[self.Dependencies, self.Provided](
AdminApiEndpoints.layer,
AdminApiRoutes.layer,
FilesEndpoints.layer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

package org.knora.webapi.slice.admin.domain

import zio.URLayer
import zio.ZLayer

import org.knora.webapi.config.AppConfig
import org.knora.webapi.responders.IriService
import org.knora.webapi.slice.URModule
import org.knora.webapi.slice.admin.domain.service.*
import org.knora.webapi.slice.admin.domain.service.GroupService
import org.knora.webapi.slice.admin.domain.service.KnoraGroupService
Expand All @@ -23,47 +25,44 @@ import org.knora.webapi.slice.ontology.repo.service.OntologyCache
import org.knora.webapi.slice.resourceinfo.domain.IriConverter
import org.knora.webapi.store.triplestore.api.TriplestoreService

object AdminDomainModule {

type Dependencies =
// format: off
AdminRepoModule.Provided &
AppConfig &
CacheManager &
DspIngestClient &
IriService &
IriConverter &
OntologyRepo &
OntologyCache &
TriplestoreService
// format: on

type Provided =
// format: off
AdministrativePermissionService &
GroupService &
KnoraGroupService &
KnoraProjectService &
KnoraUserService &
KnoraUserToUserConverter &
MaintenanceService &
PasswordService &
ProjectService &
ProjectEraseService &
UserService
// format: on

val layer = ZLayer.makeSome[Dependencies, Provided](
AdministrativePermissionService.layer,
GroupService.layer,
KnoraGroupService.layer,
KnoraProjectService.layer,
KnoraUserService.layer,
KnoraUserToUserConverter.layer,
MaintenanceService.layer,
PasswordService.layer,
ProjectEraseService.layer,
ProjectService.layer,
UserService.layer,
)
object AdminDomainModule
extends URModule[
// format: off
AdminRepoModule.Provided &
AppConfig &
CacheManager &
DspIngestClient &
IriConverter &
IriService &
OntologyCache &
OntologyRepo &
TriplestoreService
,
AdministrativePermissionService &
GroupService &
KnoraGroupService &
KnoraProjectService &
KnoraUserService &
KnoraUserToUserConverter &
MaintenanceService &
PasswordService &
ProjectEraseService &
ProjectService &
UserService
// format: on
] { self =>
inline def layer: URLayer[self.Dependencies, self.Provided] =
ZLayer.makeSome[self.Dependencies, self.Provided](
AdministrativePermissionService.layer,
GroupService.layer,
KnoraGroupService.layer,
KnoraProjectService.layer,
KnoraUserService.layer,
KnoraUserToUserConverter.layer,
MaintenanceService.layer,
PasswordService.layer,
ProjectEraseService.layer,
ProjectService.layer,
UserService.layer,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,28 @@

package org.knora.webapi.slice.infrastructure

import zio.URLayer
import zio.ZLayer

import org.knora.webapi.config.DspIngestConfig
import org.knora.webapi.config.JwtConfig
import org.knora.webapi.slice.URModule

object InfrastructureModule {

type Dependencies =
// format: off
DspIngestConfig &
JwtConfig
// format: on

type Provided =
// format: off
CacheManager &
InvalidTokenCache &
JwtService
// format: on

val layer = ZLayer.makeSome[Dependencies, Provided](
CacheManager.layer,
InvalidTokenCache.layer,
JwtServiceLive.layer,
)
object InfrastructureModule
extends URModule[
// format: off
DspIngestConfig &
JwtConfig
,
CacheManager &
InvalidTokenCache &
JwtService
// format: on
] { self =>
inline def layer: URLayer[self.Dependencies, self.Provided] =
ZLayer.makeSome[self.Dependencies, self.Provided](
CacheManager.layer,
InvalidTokenCache.layer,
JwtServiceLive.layer,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,34 @@

package org.knora.webapi.slice.security

import zio.URLayer
import zio.ZLayer

import org.knora.webapi.config.AppConfig
import org.knora.webapi.slice.URModule
import org.knora.webapi.slice.admin.domain.service.KnoraProjectService
import org.knora.webapi.slice.admin.domain.service.PasswordService
import org.knora.webapi.slice.admin.domain.service.UserService
import org.knora.webapi.slice.infrastructure.InvalidTokenCache
import org.knora.webapi.slice.infrastructure.JwtService

object SecurityModule {

type Dependencies =
// format: off
AppConfig &
InvalidTokenCache &
JwtService &
KnoraProjectService &
PasswordService &
UserService
// format: on

type Provided =
// format: off
ScopeResolver &
Authenticator
// format: on

val layer = ZLayer.makeSome[Dependencies, Provided](
ScopeResolver.layer,
AuthenticatorLive.layer,
)
object SecurityModule
extends URModule[
// format: off
AppConfig &
InvalidTokenCache &
JwtService &
KnoraProjectService &
PasswordService &
UserService
,
ScopeResolver &
Authenticator
// format: on
] { self =>
inline def layer: URLayer[self.Dependencies, self.Provided] =
ZLayer.makeSome[self.Dependencies, self.Provided](
ScopeResolver.layer,
AuthenticatorLive.layer,
)
}

0 comments on commit 2687412

Please sign in to comment.