Skip to content

Commit

Permalink
Merge branch 'refactor/modularize-layers' into refactor/modularize-la…
Browse files Browse the repository at this point in the history
…yers-broken
  • Loading branch information
seakayone committed Mar 19, 2024
2 parents 87ca116 + 42b7731 commit db98e3b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 17 deletions.
7 changes: 3 additions & 4 deletions webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import org.knora.webapi.slice.infrastructure.api.ManagementRoutes
import org.knora.webapi.slice.ontology.api.service.RestCardinalityService
import org.knora.webapi.slice.ontology.api.service.RestCardinalityServiceLive
import org.knora.webapi.slice.ontology.domain.service.CardinalityService
import org.knora.webapi.slice.ontology.domain.service.OntologyRepo
import org.knora.webapi.slice.ontology.repo.service.OntologyCache
import org.knora.webapi.slice.ontology.repo.service.OntologyCacheLive
import org.knora.webapi.slice.ontology.repo.service.OntologyRepoLive
Expand Down Expand Up @@ -79,10 +78,10 @@ object LayersLive {
CacheServiceRequestMessageHandler & CardinalityHandler & CardinalityService & ConstructResponseUtilV2 &
ConstructTransformer & GravsearchTypeInspectionRunner & GroupsService & GroupsResponderADM & HttpServer &
IIIFRequestMessageHandler & InferenceOptimizationService & InstrumentationServerConfig & IriConverter &
IriService & JwtService & KnoraProjectRepo & KnoraUserService & ListsResponder & ListsResponderV2 &
MessageRelay & OntologyCache & OntologyHelpers & OntologyInferencer & OntologyRepo & OntologyResponderV2 &
IriService & JwtService & ListsResponder & ListsResponderV2 &
MessageRelay & OntologyHelpers & OntologyCache & OntologyInferencer & OntologyResponderV2 &
PasswordService & PermissionsResponderADM & PermissionsRestService & PermissionUtilADM & PredicateObjectMapper &
ProjectADMRestService & ProjectService & ProjectExportService & ProjectExportStorageService &
ProjectADMRestService & ProjectExportService & ProjectExportStorageService &
ProjectImportService & ProjectsResponderADM & QueryTraverser & RepositoryUpdater & ResourcesResponderV2 &
ResourceUtilV2 & ResourceUtilV2 & RestCardinalityService & RestResourceInfoService & SearchApiRoutes &
SearchResponderV2 & SipiService & StandoffResponderV2 & StandoffTagUtilV2 & State & StoreRestService &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import org.knora.webapi.slice.admin.domain.model.KnoraProject.ProjectIri
import org.knora.webapi.slice.admin.domain.model.ListProperties.ListIri
import org.knora.webapi.slice.admin.domain.model.ListProperties.ListName
import org.knora.webapi.slice.admin.domain.model.User
import org.knora.webapi.slice.admin.domain.service.KnoraProjectRepo
import org.knora.webapi.slice.admin.domain.service.KnoraProjectService
import org.knora.webapi.slice.admin.domain.service.ProjectService
import org.knora.webapi.slice.common.api.AuthorizationRestService
import org.knora.webapi.slice.common.repo.service.PredicateObjectMapper
Expand All @@ -48,7 +48,7 @@ final case class ListsResponder(
appConfig: AppConfig,
auth: AuthorizationRestService,
iriService: IriService,
projectRepo: KnoraProjectRepo,
knoraProjectService: KnoraProjectService,
mapper: PredicateObjectMapper,
triplestore: TriplestoreService,
implicit val stringFormatter: StringFormatter,
Expand Down Expand Up @@ -589,7 +589,7 @@ final case class ListsResponder(

for {
/* Verify that the project exists by retrieving it. We need the project information so that we can calculate the data graph and IRI for the new node. */
project <- projectRepo
project <- knoraProjectService
.findById(projectIri)
.someOrFail(BadRequestException(s"Project '$projectIri' not found."))

Expand Down Expand Up @@ -758,7 +758,7 @@ final case class ListsResponder(

private def ensureUserIsAdminOrProjectOwner(listIri: ListIri, user: User): Task[KnoraProject] =
getProjectIriFromNode(listIri.value)
.flatMap(projectRepo.findById)
.flatMap(knoraProjectService.findById)
.someOrFail(BadRequestException(s"Project not found for node $listIri"))
.tap(auth.ensureSystemAdminOrProjectAdmin(user, _))

Expand Down Expand Up @@ -1505,7 +1505,7 @@ final case class ListsResponder(
* @return an [[IRI]].
*/
private def getDataNamedGraph(projectIri: ProjectIri): Task[IRI] =
projectRepo
knoraProjectService
.findById(projectIri)
.someOrFail(BadRequestException(s"Project '$projectIri' not found."))
.map(ProjectService.projectDataNamedGraphV2(_).value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import org.knora.webapi.slice.admin.domain.model.KnoraProject.ProjectIri
import org.knora.webapi.slice.admin.domain.model.KnoraProject.Shortcode
import org.knora.webapi.slice.admin.domain.model.PermissionIri
import org.knora.webapi.slice.admin.domain.model.User
import org.knora.webapi.slice.admin.domain.service.KnoraProjectRepo
import org.knora.webapi.slice.admin.domain.service.KnoraProjectService
import org.knora.webapi.slice.common.api.AuthorizationRestService
import org.knora.webapi.store.triplestore.api.TriplestoreService
import org.knora.webapi.store.triplestore.api.TriplestoreService.Queries.Ask
Expand Down Expand Up @@ -242,7 +242,7 @@ final case class PermissionsResponderADMLive(
iriService: IriService,
messageRelay: MessageRelay,
triplestore: TriplestoreService,
projectRepo: KnoraProjectRepo,
knoraProjectService: KnoraProjectService,
auth: AuthorizationRestService,
implicit val stringFormatter: StringFormatter,
) extends PermissionsResponderADM
Expand Down Expand Up @@ -1529,7 +1529,7 @@ final case class PermissionsResponderADMLive(
projectIri <- ZIO
.fromEither(ProjectIri.from(createRequest.forProject))
.mapError(BadRequestException.apply)
project <- projectRepo
project <- knoraProjectService
.findById(projectIri)
.someOrFail(NotFoundException(s"Project ${projectIri.value} not found"))
_ <- auth.ensureSystemAdminSystemUserOrProjectAdmin(user, project)
Expand Down Expand Up @@ -2224,14 +2224,14 @@ final case class PermissionsResponderADMLive(

object PermissionsResponderADMLive {
val layer: URLayer[
AppConfig & AuthorizationRestService & IriService & KnoraProjectRepo & MessageRelay & StringFormatter & TriplestoreService,
AppConfig & AuthorizationRestService & IriService & KnoraProjectService & MessageRelay & StringFormatter & TriplestoreService,
PermissionsResponderADMLive,
] = ZLayer.fromZIO {
for {
au <- ZIO.service[AuthorizationRestService]
ac <- ZIO.service[AppConfig]
is <- ZIO.service[IriService]
kpr <- ZIO.service[KnoraProjectRepo]
kpr <- ZIO.service[KnoraProjectService]
mr <- ZIO.service[MessageRelay]
ts <- ZIO.service[TriplestoreService]
sf <- ZIO.service[StringFormatter]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import zio.ZLayer

import org.knora.webapi.slice.admin.domain.service.*
import org.knora.webapi.slice.admin.domain.AdminDomainModule
import org.knora.webapi.slice.admin.domain.service.KnoraGroupRepo
import org.knora.webapi.slice.admin.domain.service.KnoraProjectRepo
import org.knora.webapi.slice.admin.domain.service.KnoraProjectService
import org.knora.webapi.slice.admin.domain.service.KnoraUserRepo
import org.knora.webapi.slice.admin.repo.AdminRepoModule
import org.knora.webapi.store.cache.CacheService
import org.knora.webapi.store.triplestore.api.TriplestoreService
Expand All @@ -20,8 +24,8 @@ object AdminModule {
type Dependencies =
TriplestoreService & CacheService & IriService & PasswordService & CacheService & PredicateObjectMapper

type Provided = KnoraGroupRepo & KnoraUserRepo & KnoraProjectRepo & KnoraUserService & MaintenanceService
type Provided =
KnoraGroupRepo & KnoraUserRepo & KnoraProjectRepo & KnoraUserService & MaintenanceService & KnoraProjectService

val layer: ZLayer[Dependencies, Nothing, Provided] = AdminRepoModule.layer >+> AdminDomainModule.layer

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package org.knora.webapi.slice.admin.domain
import zio.ZLayer
import org.knora.webapi.slice.admin.domain.service.*
import org.knora.webapi.responders.IriService
import org.knora.webapi.slice.admin.domain.service.KnoraProjectService
import org.knora.webapi.store.cache.CacheService
import org.knora.webapi.slice.common.repo.service.PredicateObjectMapper
import org.knora.webapi.store.triplestore.api.TriplestoreService
Expand All @@ -16,10 +17,11 @@ object AdminDomainModule {

type Dependencies =
KnoraProjectRepo & TriplestoreService & KnoraUserRepo & IriService & PasswordService & CacheService & PredicateObjectMapper
type Provided = KnoraUserService & MaintenanceService
type Provided = KnoraUserService & MaintenanceService & KnoraProjectService

val layer = ZLayer.makeSome[Dependencies, Provided](
KnoraUserService.layer,
MaintenanceService.layer,
KnoraProjectService.layer,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.knora.webapi.slice.admin.domain.service

import org.knora.webapi.slice.admin.domain.model.KnoraProject.ProjectIri

final case class KnoraProjectService(knoraProjectRepo: KnoraProjectRepo) {

def findById(id: ProjectIri) = knoraProjectRepo.findById(id)
}

object KnoraProjectService {
val layer = zio.ZLayer.derive[KnoraProjectService]
}

0 comments on commit db98e3b

Please sign in to comment.