Skip to content

Commit

Permalink
Add support for copying files to another project
Browse files Browse the repository at this point in the history
  • Loading branch information
dantb committed Nov 13, 2023
1 parent 7aac39b commit 077d2e9
Show file tree
Hide file tree
Showing 92 changed files with 1,016 additions and 700 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 @@ -90,15 +90,6 @@ trait ClasspathResourceUtils {
props.asScala.toMap
}

final def bioPropertiesOf(resourcePath: String)(implicit
classLoader: ClassLoader
): BIO[ClasspathResourceError, Map[String, String]] =
bioStreamOf(resourcePath).map { is =>
val props = new Properties()
props.load(is)
props.asScala.toMap
}

/**
* Loads the content of the argument classpath resource as a string and replaces all the key matches of the
* ''replacements'' with their values. The resulting string is parsed into a json value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import monix.bio.{Task, UIO}
import java.time.Instant
import java.util.UUID
import java.util.concurrent.TimeUnit
import scala.concurrent.duration.{DurationLong, FiniteDuration, MILLISECONDS}

trait IOUtils {

Expand All @@ -22,6 +23,13 @@ object IOUtils extends IOUtils
trait IOInstant {
def now(implicit clock: Clock[IO]): IO[Instant] =
clock.realTime(TimeUnit.MILLISECONDS).map(Instant.ofEpochMilli)

def timed[A](io: IO[A])(implicit c: Clock[IO]): IO[(A, FiniteDuration)] =
for {
start <- c.monotonic(MILLISECONDS)
result <- io
finish <- c.monotonic(MILLISECONDS)
} yield (result, (finish - start).millis)
}

object IOInstant extends IOInstant
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
@@ -1,16 +1,17 @@
package ch.epfl.bluebrain.nexus.delta.plugins.blazegraph

import cats.effect.IO
import ch.epfl.bluebrain.nexus.delta.kernel.effect.migration.toCatsIOOps
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.{contexts, BlazegraphViewType}
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.api.JsonLdApi
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.{ContextValue, JsonLdContext, RemoteContextResolution}
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.decoder.Configuration
import monix.bio.Task

private[blazegraph] object BlazegraphDecoderConfiguration {

def apply(implicit jsonLdApi: JsonLdApi, rcr: RemoteContextResolution): Task[Configuration] = for {
contextValue <- Task.delay { ContextValue(contexts.blazegraph) }
jsonLdContext <- JsonLdContext(contextValue)
def apply(implicit jsonLdApi: JsonLdApi, rcr: RemoteContextResolution): IO[Configuration] = for {
contextValue <- IO.delay { ContextValue(contexts.blazegraph) }
jsonLdContext <- JsonLdContext(contextValue).toCatsIO
} yield {
val enhancedJsonLdContext = jsonLdContext
.addAliasIdType("IndexingBlazegraphViewValue", BlazegraphViewType.IndexingBlazegraphView.tpe)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package ch.epfl.bluebrain.nexus.delta.plugins.blazegraph
import akka.actor.typed.ActorSystem
import cats.effect.{Clock, ContextShift, IO, Timer}
import ch.epfl.bluebrain.nexus.delta.kernel.effect.migration._
import ch.epfl.bluebrain.nexus.delta.kernel.utils.UUIDF
import ch.epfl.bluebrain.nexus.delta.kernel.utils.{CatsEffectsClasspathResourceUtils, UUIDF}
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.client.BlazegraphClient
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.config.BlazegraphViewsConfig
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.indexing.BlazegraphCoordinator
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.BlazegraphViewRejection.ProjectContextRejection
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.{contexts, schema => viewsSchemaId, BlazegraphView, BlazegraphViewEvent}
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.{contexts, schema => viewsSchemaId, BlazegraphView, BlazegraphViewEvent, DefaultProperties}
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.routes.{BlazegraphViewsIndexingRoutes, BlazegraphViewsRoutes, BlazegraphViewsRoutesHandler}
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.slowqueries.{BlazegraphSlowQueryDeleter, BlazegraphSlowQueryLogger, BlazegraphSlowQueryStore}
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.api.JsonLdApi
Expand Down Expand Up @@ -48,6 +48,10 @@ class BlazegraphPluginModule(priority: Int) extends ModuleDef {

make[BlazegraphViewsConfig].from { BlazegraphViewsConfig.load(_) }

make[DefaultProperties].fromEffect {
CatsEffectsClasspathResourceUtils.ioPropertiesOf("blazegraph/index.properties").map(DefaultProperties)
}

make[HttpClient].named("http-indexing-client").from {
(cfg: BlazegraphViewsConfig, as: ActorSystem[Nothing], sc: Scheduler) =>
HttpClient()(cfg.indexingClient, as.classicSystem, sc)
Expand All @@ -69,17 +73,18 @@ class BlazegraphPluginModule(priority: Int) extends ModuleDef {
)(timer)
}

make[BlazegraphSlowQueryLogger].from { (cfg: BlazegraphViewsConfig, store: BlazegraphSlowQueryStore) =>
BlazegraphSlowQueryLogger(store, cfg.slowQueries.slowQueryThreshold)
make[BlazegraphSlowQueryLogger].from { (cfg: BlazegraphViewsConfig, store: BlazegraphSlowQueryStore, c: Clock[IO]) =>
BlazegraphSlowQueryLogger(store, cfg.slowQueries.slowQueryThreshold)(c)
}

make[BlazegraphClient].named("blazegraph-indexing-client").from {
(
cfg: BlazegraphViewsConfig,
client: HttpClient @Id("http-indexing-client"),
as: ActorSystem[Nothing]
as: ActorSystem[Nothing],
properties: DefaultProperties
) =>
BlazegraphClient(client, cfg.base, cfg.credentials, cfg.queryTimeout)(as.classicSystem)
BlazegraphClient(client, cfg.base, cfg.credentials, cfg.queryTimeout, properties.value)(as.classicSystem)
}

make[HttpClient].named("http-query-client").from {
Expand All @@ -91,9 +96,10 @@ class BlazegraphPluginModule(priority: Int) extends ModuleDef {
(
cfg: BlazegraphViewsConfig,
client: HttpClient @Id("http-query-client"),
as: ActorSystem[Nothing]
as: ActorSystem[Nothing],
properties: DefaultProperties
) =>
BlazegraphClient(client, cfg.base, cfg.credentials, cfg.queryTimeout)(as.classicSystem)
BlazegraphClient(client, cfg.base, cfg.credentials, cfg.queryTimeout, properties.value)(as.classicSystem)
}

make[ValidateBlazegraphView].from {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ch.epfl.bluebrain.nexus.delta.plugins.blazegraph

import cats.effect.IO
import ch.epfl.bluebrain.nexus.delta.kernel.effect.migration._
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.client.BlazegraphClient
import ch.epfl.bluebrain.nexus.delta.sdk.ServiceDependency
import ch.epfl.bluebrain.nexus.delta.sdk.model.ComponentDescription.ServiceDescription
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ch.epfl.bluebrain.nexus.delta.kernel.effect.migration._
import ch.epfl.bluebrain.nexus.delta.kernel.kamon.KamonMetricComponent
import ch.epfl.bluebrain.nexus.delta.kernel.utils.{IOInstant, UUIDF}
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.BlazegraphViews._
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.client.BlazegraphClient
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.client.{BlazegraphClient, SparqlClientError}
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.indexing.IndexingViewDef
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.indexing.IndexingViewDef.{ActiveViewDef, DeprecatedViewDef}
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.BlazegraphView.IndexingBlazegraphView
Expand Down 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 Expand Up @@ -542,9 +542,8 @@ object BlazegraphViews {
case i: IndexingBlazegraphView =>
client
.createNamespace(BlazegraphViews.namespace(i, prefix))
.mapError(WrappedBlazegraphClientError.apply)
.adaptError { case e: SparqlClientError => WrappedBlazegraphClientError(e) }
.void
.toCatsIO
case _ => IO.unit
}
apply(fetchContext, contextResolution, validate, createNameSpace, eventLogConfig, prefix, xas)
Expand Down
Loading

0 comments on commit 077d2e9

Please sign in to comment.