Skip to content

Commit

Permalink
Merge branch 'master' into migrate-bg-client
Browse files Browse the repository at this point in the history
  • Loading branch information
dantb authored Nov 8, 2023
2 parents af84486 + 6f96c00 commit c173bb0
Show file tree
Hide file tree
Showing 43 changed files with 275 additions and 333 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ import ch.epfl.bluebrain.nexus.delta.sdk.organizations.model.OrganizationRejecti
import ch.epfl.bluebrain.nexus.delta.sdk.projects.FetchContext.ContextRejection
import ch.epfl.bluebrain.nexus.delta.sdk.projects._
import ch.epfl.bluebrain.nexus.delta.sdk.projects.model.ProjectRejection.WrappedOrganizationRejection
import ch.epfl.bluebrain.nexus.delta.sdk.projects.model.{ApiMappings, Project, ProjectEvent, ProjectRejection}
import ch.epfl.bluebrain.nexus.delta.sdk.projects.model.{ApiMappings, Project, ProjectEvent}
import ch.epfl.bluebrain.nexus.delta.sdk.provisioning.ProjectProvisioning
import ch.epfl.bluebrain.nexus.delta.sdk.quotas.Quotas
import ch.epfl.bluebrain.nexus.delta.sdk.sse.SseEncoder
import ch.epfl.bluebrain.nexus.delta.sourcing.Transactors
import ch.epfl.bluebrain.nexus.delta.sourcing.stream.Supervisor
import izumi.distage.model.definition.{Id, ModuleDef}
import monix.execution.Scheduler

/**
* Projects wiring
Expand Down Expand Up @@ -67,8 +66,7 @@ object ProjectsModule extends ModuleDef {
.fetchActiveOrganization(_)
.adaptError { case e: OrganizationRejection =>
WrappedOrganizationRejection(e)
}
.toBIO[ProjectRejection],
},
ValidateProjectDeletion(xas, config.projects.deletion.enabled),
scopeInitializations,
mappings.merge,
Expand Down Expand Up @@ -120,12 +118,11 @@ object ProjectsModule extends ModuleDef {
}

make[UUIDCache].fromEffect { (config: AppConfig, xas: Transactors) =>
toCatsIO(UUIDCache(config.projects.cache, config.organizations.cache, xas))
UUIDCache(config.projects.cache, config.organizations.cache, xas)
}

make[DeltaSchemeDirectives].from {
(fetchContext: FetchContext[ContextRejection], uuidCache: UUIDCache, s: Scheduler) =>
DeltaSchemeDirectives(fetchContext, uuidCache)(s)
make[DeltaSchemeDirectives].from { (fetchContext: FetchContext[ContextRejection], uuidCache: UUIDCache) =>
DeltaSchemeDirectives(fetchContext, uuidCache)
}

make[ProjectsRoutes].from {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import ch.epfl.bluebrain.nexus.delta.sourcing.offset.Offset
import ch.epfl.bluebrain.nexus.delta.sourcing.query.SelectFilter
import ch.epfl.bluebrain.nexus.delta.sourcing.stream.RemainingElems
import ch.epfl.bluebrain.nexus.testkit.CirceLiteral
import ch.epfl.bluebrain.nexus.testkit.bio.IOFromMap
import ch.epfl.bluebrain.nexus.testkit.ce.IOFromMap
import fs2.Stream

import java.time.Instant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.{Anonymous, Authent
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{Label, ProjectRef}
import ch.epfl.bluebrain.nexus.delta.sourcing.offset.Offset
import ch.epfl.bluebrain.nexus.delta.sourcing.offset.Offset.{At, Start}
import ch.epfl.bluebrain.nexus.testkit.bio.IOFromMap
import ch.epfl.bluebrain.nexus.testkit.ce.IOFromMap
import fs2.Stream

import java.util.UUID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import ch.epfl.bluebrain.nexus.delta.sdk.projects.OwnerPermissionsScopeInitializ
import ch.epfl.bluebrain.nexus.delta.sdk.utils.BaseRouteSpec
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.{Anonymous, Authenticated, Group, Subject}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Label
import ch.epfl.bluebrain.nexus.testkit.bio.IOFromMap
import ch.epfl.bluebrain.nexus.testkit.ce.IOFromMap
import io.circe.Json

import java.util.UUID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import ch.epfl.bluebrain.nexus.delta.sdk.provisioning.{AutomaticProvisioningConf
import ch.epfl.bluebrain.nexus.delta.sdk.utils.BaseRouteSpec
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.{Anonymous, Authenticated, Group, Subject, User}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{Label, ProjectRef}
import ch.epfl.bluebrain.nexus.testkit.bio.IOFromMap
import ch.epfl.bluebrain.nexus.testkit.ce.IOFromMap
import io.circe.Json
import monix.bio.{IO, UIO}
import ch.epfl.bluebrain.nexus.delta.kernel.effect.migration._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import ch.epfl.bluebrain.nexus.delta.sdk.utils.BaseRouteSpec
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.{Anonymous, Authenticated, Group, Subject, User}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Tag.UserTag
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{ProjectRef, ResourceRef}
import ch.epfl.bluebrain.nexus.testkit.bio.IOFromMap
import ch.epfl.bluebrain.nexus.testkit.ce.IOFromMap
import ch.epfl.bluebrain.nexus.testkit.scalatest.ce.CatsIOValues
import io.circe.{Json, Printer}
import org.scalatest.Assertion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import ch.epfl.bluebrain.nexus.delta.sdk.schemas.{SchemaImports, SchemasConfig,
import ch.epfl.bluebrain.nexus.delta.sdk.utils.BaseRouteSpec
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.{Anonymous, Authenticated, Group, Subject}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.ProjectRef
import ch.epfl.bluebrain.nexus.testkit.bio.IOFromMap
import ch.epfl.bluebrain.nexus.testkit.ce.IOFromMap
import ch.epfl.bluebrain.nexus.testkit.scalatest.ce.CatsIOValues
import io.circe.Json

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ import io.circe.Json
* a source decoder for [[ArchiveValue]]
* @param config
* the log config
* @param uuidF
* the uuid generator
* @param rcr
* the archive remote context resolution
*/
Expand Down Expand Up @@ -82,7 +80,7 @@ class Archives(
*/
def create(project: ProjectRef, source: Json)(implicit subject: Subject): IO[ArchiveResource] =
(for {
p <- toCatsIO(fetchContext.onRead(project))
p <- fetchContext.onRead(project)
(iri, value) <- toCatsIO(sourceDecoder(p, source))
res <- create(iri, project, value)
} yield res).span("createArchive")
Expand Down Expand Up @@ -149,12 +147,11 @@ class Archives(
source <- archiveDownload(value.value, project, ignoreNotFound)
} yield source).span("downloadArchive")

private def expandWithContext(id: IdSegment, project: ProjectRef) = toCatsIO {
private def expandWithContext(id: IdSegment, project: ProjectRef) =
for {
p <- fetchContext.onRead(project)
iri <- expandIri(id, p)
} yield (iri, p)
}

private def eval(cmd: CreateArchive): IO[ArchiveResource] =
log.evaluate(cmd.project, cmd.id, cmd).map { _.toResource(config.ttl) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ch.epfl.bluebrain.nexus.delta.plugins.archive
import akka.http.scaladsl.model.Uri
import cats.effect.IO
import cats.syntax.all._
import ch.epfl.bluebrain.nexus.delta.kernel.effect.migration._
import ch.epfl.bluebrain.nexus.delta.kernel.utils.UrlUtils
import ch.epfl.bluebrain.nexus.delta.plugins.archive.FileSelf.ParsingError._
import ch.epfl.bluebrain.nexus.delta.rdf.IriOrBNode.Iri
Expand Down Expand Up @@ -101,9 +100,7 @@ object FileSelf {
case Array(org, project, id) =>
for {
project <- IO.fromEither(ProjectRef.parse(org, project).leftMap(_ => InvalidProject(self)))
projectContext <- toCatsIO(
fetchContext.onRead(project).mapError { _ => InvalidProjectContext(self, project) }
)
projectContext <- fetchContext.onRead(project).adaptError { _ => InvalidProjectContext(self, project) }
decodedId = UrlUtils.decode(id)
iriOption =
IdSegment(decodedId).toIri(projectContext.apiMappings, projectContext.base).map(ResourceRef(_))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ final class BlazegraphViews(
*/
def create(project: ProjectRef, source: Json)(implicit caller: Caller): IO[ViewResource] = {
for {
pc <- fetchContext.onCreate(project).toCatsIO
pc <- fetchContext.onCreate(project)
(iri, viewValue) <- sourceDecoder(project, pc, source).toCatsIO
res <- eval(CreateBlazegraphView(iri, project, viewValue, source, caller.subject))
_ <- createNamespace(res)
Expand All @@ -86,8 +86,8 @@ final class BlazegraphViews(
source: Json
)(implicit caller: Caller): IO[ViewResource] = {
for {
pc <- fetchContext.onCreate(project).toCatsIO
iri <- expandIri(id, pc).toCatsIO
pc <- fetchContext.onCreate(project)
iri <- expandIri(id, pc)
viewValue <- sourceDecoder(project, pc, iri, source).toCatsIO
res <- eval(CreateBlazegraphView(iri, project, viewValue, source, caller.subject))
_ <- createNamespace(res)
Expand All @@ -107,8 +107,8 @@ final class BlazegraphViews(
subject: Subject
): IO[ViewResource] = {
for {
pc <- fetchContext.onCreate(project).toCatsIO
iri <- expandIri(id, pc).toCatsIO
pc <- fetchContext.onCreate(project)
iri <- expandIri(id, pc)
source = view.toJson(iri)
res <- eval(CreateBlazegraphView(iri, project, view, source, subject))
_ <- createNamespace(res)
Expand All @@ -133,8 +133,8 @@ final class BlazegraphViews(
source: Json
)(implicit caller: Caller): IO[ViewResource] = {
for {
pc <- fetchContext.onModify(project).toCatsIO
iri <- expandIri(id, pc).toCatsIO
pc <- fetchContext.onModify(project)
iri <- expandIri(id, pc)
viewValue <- sourceDecoder(project, pc, iri, source).toCatsIO
res <- eval(UpdateBlazegraphView(iri, project, viewValue, rev, source, caller.subject))
_ <- createNamespace(res)
Expand All @@ -157,8 +157,8 @@ final class BlazegraphViews(
subject: Subject
): IO[ViewResource] = {
for {
pc <- fetchContext.onModify(project).toCatsIO
iri <- expandIri(id, pc).toCatsIO
pc <- fetchContext.onModify(project)
iri <- expandIri(id, pc)
source = view.toJson(iri)
res <- eval(UpdateBlazegraphView(iri, project, view, rev, source, subject))
_ <- createNamespace(res)
Expand Down Expand Up @@ -187,8 +187,8 @@ final class BlazegraphViews(
rev: Int
)(implicit subject: Subject): IO[ViewResource] = {
for {
pc <- fetchContext.onModify(project).toCatsIO
iri <- expandIri(id, pc).toCatsIO
pc <- fetchContext.onModify(project)
iri <- expandIri(id, pc)
res <- eval(TagBlazegraphView(iri, project, tagRev, tag, rev, subject))
_ <- createNamespace(res)
} yield res
Expand All @@ -210,8 +210,8 @@ final class BlazegraphViews(
rev: Int
)(implicit subject: Subject): IO[ViewResource] = {
for {
pc <- fetchContext.onModify(project).toCatsIO
iri <- expandIri(id, pc).toCatsIO
pc <- fetchContext.onModify(project)
iri <- expandIri(id, pc)
res <- eval(DeprecateBlazegraphView(iri, project, rev, subject))
} yield res
}.span("deprecateBlazegraphView")
Expand Down Expand Up @@ -247,8 +247,8 @@ final class BlazegraphViews(
project: ProjectRef
): IO[BlazegraphViewState] = {
for {
pc <- fetchContext.onRead(project).toCatsIO
iri <- expandIri(id.value, pc).toCatsIO
pc <- fetchContext.onRead(project)
iri <- expandIri(id.value, pc)
notFound = ViewNotFound(iri, project)
state <- id match {
case Latest(_) => log.stateOr(project, iri, notFound)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ object BlazegraphViewsQuery {
base: BaseUri
): IO[SearchResults[SparqlLink]] =
for {
p <- fetchContext.onRead(projectRef).toCatsIO
iri <- expandIri(id, p).toCatsIO
p <- fetchContext.onRead(projectRef)
iri <- expandIri(id, p)
q = SparqlQuery(replace(incomingQuery, iri, pagination))
bindings <- query(IriSegment(defaultViewId), projectRef, q, SparqlResultsJson)
links = toSparqlLinks(bindings.value)
Expand All @@ -158,8 +158,8 @@ object BlazegraphViewsQuery {
includeExternalLinks: Boolean
)(implicit caller: Caller, base: BaseUri): IO[SearchResults[SparqlLink]] =
for {
p <- fetchContext.onRead(projectRef).toCatsIO
iri <- expandIri(id, p).toCatsIO
p <- fetchContext.onRead(projectRef)
iri <- expandIri(id, p)
queryTemplate = if (includeExternalLinks) outgoingWithExternalQuery else outgoingScopedQuery
q = SparqlQuery(replace(queryTemplate, iri, pagination))
bindings <- query(IriSegment(defaultViewId), projectRef, q, SparqlResultsJson)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import ch.epfl.bluebrain.nexus.delta.sourcing.projections.{ProjectionErrors, Pro
import ch.epfl.bluebrain.nexus.delta.sourcing.query.SelectFilter
import ch.epfl.bluebrain.nexus.delta.sourcing.stream.Elem.FailedElem
import ch.epfl.bluebrain.nexus.delta.sourcing.stream.ProjectionProgress
import ch.epfl.bluebrain.nexus.testkit.bio.IOFromMap
import ch.epfl.bluebrain.nexus.testkit.ce.IOFromMap
import ch.epfl.bluebrain.nexus.testkit.ce.CatsRunContext

import java.time.Instant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import akka.http.scaladsl.server.Route
import akka.util.ByteString
import cats.effect.IO
import ch.epfl.bluebrain.nexus.delta.kernel.utils.{UUIDF, UrlUtils}
import ch.epfl.bluebrain.nexus.delta.kernel.effect.migration._
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.BlazegraphViews
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.client.{SparqlQueryClientDummy, SparqlResults}
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.BlazegraphViewRejection.ProjectContextRejection
Expand Down Expand Up @@ -72,7 +71,7 @@ class BlazegraphViewsRoutesSpec extends BlazegraphViewRoutesFixtures {
Map("resource-incoming-outgoing" -> linksResults)
)

private val groupDirectives = DeltaSchemeDirectives(fetchContext, _ => IO.none.toUIO, _ => IO.none.toUIO)
private val groupDirectives = DeltaSchemeDirectives(fetchContext, _ => IO.none, _ => IO.none)
private lazy val routes =
Route.seal(
BlazegraphViewsRoutesHandler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ final class CompositeViews private (
baseUri: BaseUri
): IO[ViewResource] = {
for {
pc <- toCatsIO(fetchContext.onCreate(project))
iri <- toCatsIO(expandIri(id, pc))
pc <- fetchContext.onCreate(project)
iri <- expandIri(id, pc)
res <- eval(CreateCompositeView(iri, project, value, value.toJson(iri), subject, pc.base))
} yield res
}.span("createCompositeView")
Expand All @@ -82,8 +82,8 @@ final class CompositeViews private (
*/
def create(project: ProjectRef, source: Json)(implicit caller: Caller): IO[ViewResource] = {
for {
pc <- toCatsIO(fetchContext.onCreate(project))
(iri, value) <- toCatsIO(sourceDecoder(project, pc, source))
pc <- fetchContext.onCreate(project)
(iri, value) <- sourceDecoder(project, pc, source).toCatsIO
res <- eval(CreateCompositeView(iri, project, value, source, caller.subject, pc.base))
} yield res
}.span("createCompositeView")
Expand All @@ -101,8 +101,8 @@ final class CompositeViews private (
*/
def create(id: IdSegment, project: ProjectRef, source: Json)(implicit caller: Caller): IO[ViewResource] = {
for {
pc <- toCatsIO(fetchContext.onCreate(project))
iri <- toCatsIO(expandIri(id, pc))
pc <- fetchContext.onCreate(project)
iri <- expandIri(id, pc)
viewValue <- toCatsIO(sourceDecoder(project, pc, iri, source))
res <- eval(CreateCompositeView(iri, project, viewValue, source, caller.subject, pc.base))
} yield res
Expand Down Expand Up @@ -132,8 +132,8 @@ final class CompositeViews private (
baseUri: BaseUri
): IO[ViewResource] = {
for {
pc <- toCatsIO(fetchContext.onModify(project))
iri <- toCatsIO(expandIri(id, pc))
pc <- fetchContext.onModify(project)
iri <- expandIri(id, pc)
source = value.toJson(iri)
res <- eval(UpdateCompositeView(iri, project, rev, value, source, subject, pc.base))
} yield res
Expand All @@ -155,8 +155,8 @@ final class CompositeViews private (
*/
def update(id: IdSegment, project: ProjectRef, rev: Int, source: Json)(implicit caller: Caller): IO[ViewResource] = {
for {
pc <- toCatsIO(fetchContext.onModify(project))
iri <- toCatsIO(expandIri(id, pc))
pc <- fetchContext.onModify(project)
iri <- expandIri(id, pc)
viewValue <- toCatsIO(sourceDecoder(project, pc, iri, source))
res <- eval(UpdateCompositeView(iri, project, rev, viewValue, source, caller.subject, pc.base))
} yield res
Expand Down Expand Up @@ -186,8 +186,8 @@ final class CompositeViews private (
rev: Int
)(implicit subject: Subject): IO[ViewResource] = {
for {
pc <- toCatsIO(fetchContext.onModify(project))
iri <- toCatsIO(expandIri(id, pc))
pc <- fetchContext.onModify(project)
iri <- expandIri(id, pc)
res <- eval(TagCompositeView(iri, project, tagRev, tag, rev, subject))
} yield res
}.span("tagCompositeView")
Expand All @@ -210,8 +210,8 @@ final class CompositeViews private (
rev: Int
)(implicit subject: Subject): IO[ViewResource] = {
for {
pc <- toCatsIO(fetchContext.onModify(project))
iri <- toCatsIO(expandIri(id, pc))
pc <- fetchContext.onModify(project)
iri <- expandIri(id, pc)
res <- eval(DeprecateCompositeView(iri, project, rev, subject))
} yield res
}.span("deprecateCompositeView")
Expand Down Expand Up @@ -249,8 +249,8 @@ final class CompositeViews private (
project: ProjectRef
): IO[CompositeViewState] = {
for {
pc <- fetchContext.onRead(project).toCatsIO
iri <- expandIri(id.value, pc).toCatsIO
pc <- fetchContext.onRead(project)
iri <- expandIri(id.value, pc)
notFound = ViewNotFound(iri, project)
state <- id match {
case Latest(_) => log.stateOr(project, iri, notFound)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import ch.epfl.bluebrain.nexus.delta.sourcing.stream.Elem.FailedElem
import ch.epfl.bluebrain.nexus.delta.sourcing.stream.{ProjectionProgress, RemainingElems}
import io.circe.Json
import io.circe.syntax._
import monix.bio.UIO

import java.time.Instant
import scala.concurrent.duration._
Expand All @@ -44,7 +43,7 @@ class CompositeViewsIndexingRoutesSpec extends CompositeViewsRoutesFixtures {
private val nowPlus5 = now.plusSeconds(5)

private val fetchContext = FetchContextDummy[CompositeViewRejection](List(project), ProjectContextRejection)
private val groupDirectives = DeltaSchemeDirectives(fetchContext, _ => UIO.none, _ => UIO.none)
private val groupDirectives = DeltaSchemeDirectives(fetchContext, _ => IO.none, _ => IO.none)

private val myId = nxv + "myid"
private val view = CompositeViewsGen.resourceFor(projectRef, myId, uuid, viewValue, source = Json.obj())
Expand Down
Loading

0 comments on commit c173bb0

Please sign in to comment.