From f9f1498bb777aa82b0e63a65d81172b0793931ee Mon Sep 17 00:00:00 2001 From: Oliver <20188437+olivergrabinski@users.noreply.github.com> Date: Fri, 5 Apr 2024 14:13:52 +0200 Subject: [PATCH] Wire more contexts in nexus ship; use `source` instead of `value` in BG and ES processor (#4836) --- .../bluebrain/nexus/ship/ContextWiring.scala | 74 +++++++++++++++---- .../ship/views/BlazegraphViewProcessor.scala | 18 ++++- .../views/ElasticSearchViewProcessor.scala | 18 ++++- 3 files changed, 88 insertions(+), 22 deletions(-) diff --git a/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/ContextWiring.scala b/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/ContextWiring.scala index 8c4a7efe79..ba5916f4c8 100644 --- a/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/ContextWiring.scala +++ b/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/ContextWiring.scala @@ -5,6 +5,7 @@ import ch.epfl.bluebrain.nexus.delta.kernel.utils.ClasspathResourceLoader import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.{contexts => bgContexts} import ch.epfl.bluebrain.nexus.delta.plugins.compositeviews.model.{contexts => compositeViewContexts} import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.model.{contexts => esContexts} +import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary.contexts import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.api.JsonLdApi import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.{ContextValue, RemoteContextResolution} @@ -22,26 +23,71 @@ object ContextWiring { def remoteContextResolution: IO[RemoteContextResolution] = for { - metadataCtx <- ContextValue.fromFile("contexts/metadata.json") - pipelineCtx <- ContextValue.fromFile("contexts/pipeline.json") - shaclCtx <- ContextValue.fromFile("contexts/shacl.json") - schemasMetaCtx <- ContextValue.fromFile("contexts/schemas-metadata.json") - elasticsearchCtx <- ContextValue.fromFile("contexts/elasticsearch.json") - blazegraphCtx <- ContextValue.fromFile("contexts/sparql.json") - compositeCtx <- ContextValue.fromFile("contexts/composite-views.json") + // Delta + bulkOpCtx <- ContextValue.fromFile("contexts/bulk-operation.json") + errorCtx <- ContextValue.fromFile("contexts/error.json") + metadataCtx <- ContextValue.fromFile("contexts/metadata.json") + searchCtx <- ContextValue.fromFile("contexts/search.json") + pipelineCtx <- ContextValue.fromFile("contexts/pipeline.json") + remoteContextsCtx <- ContextValue.fromFile("contexts/remote-contexts.json") + tagsCtx <- ContextValue.fromFile("contexts/tags.json") + versionCtx <- ContextValue.fromFile("contexts/version.json") + validationCtx <- ContextValue.fromFile("contexts/validation.json") + // Project + projectsCtx <- ContextValue.fromFile("contexts/projects.json") + projectsMetaCtx <- ContextValue.fromFile("contexts/projects-metadata.json") + // Resolver + resolversCtx <- ContextValue.fromFile("contexts/resolvers.json") + resolversMetaCtx <- ContextValue.fromFile("contexts/resolvers-metadata.json") + // Schema + shaclCtx <- ContextValue.fromFile("contexts/shacl.json") + schemasMetaCtx <- ContextValue.fromFile("contexts/schemas-metadata.json") + // ElasticSearch + aggregationsCtx <- ContextValue.fromFile("contexts/aggregations.json") + elasticsearchCtx <- ContextValue.fromFile("contexts/elasticsearch.json") + elasticsearchMetaCtx <- ContextValue.fromFile("contexts/elasticsearch-metadata.json") + elasticsearchIdxCtx <- ContextValue.fromFile("contexts/elasticsearch-indexing.json") + offsetCtx <- ContextValue.fromFile("contexts/offset.json") + statisticsCtx <- ContextValue.fromFile("contexts/statistics.json") + // Blazegraph + blazegraphCtx <- ContextValue.fromFile("contexts/sparql.json") + blazegraphMetaCtx <- ContextValue.fromFile("contexts/sparql-metadata.json") + // Composite views + compositeCtx <- ContextValue.fromFile("contexts/composite-views.json") + compositeMetaCtx <- ContextValue.fromFile("contexts/composite-views-metadata.json") } yield RemoteContextResolution.fixed( // Delta - contexts.metadata -> metadataCtx, - contexts.pipeline -> pipelineCtx, + contexts.error -> errorCtx, + contexts.metadata -> metadataCtx, + contexts.search -> searchCtx, + contexts.pipeline -> pipelineCtx, + contexts.remoteContexts -> remoteContextsCtx, + contexts.tags -> tagsCtx, + contexts.version -> versionCtx, + contexts.validation -> validationCtx, + contexts.bulkOperation -> bulkOpCtx, + // Project + contexts.projects -> projectsCtx, + contexts.projectsMetadata -> projectsMetaCtx, + // Resolver + contexts.resolvers -> resolversCtx, + contexts.resolversMetadata -> resolversMetaCtx, // Schema - contexts.shacl -> shaclCtx, - contexts.schemasMetadata -> schemasMetaCtx, + contexts.shacl -> shaclCtx, + contexts.schemasMetadata -> schemasMetaCtx, // ElasticSearch - esContexts.elasticsearch -> elasticsearchCtx, + esContexts.aggregations -> aggregationsCtx, + esContexts.elasticsearch -> elasticsearchCtx, + esContexts.elasticsearchMetadata -> elasticsearchMetaCtx, + esContexts.elasticsearchIndexing -> elasticsearchIdxCtx, + Vocabulary.contexts.offset -> offsetCtx, + Vocabulary.contexts.statistics -> statisticsCtx, // Blazegraph - bgContexts.blazegraph -> blazegraphCtx, + bgContexts.blazegraph -> blazegraphCtx, + bgContexts.blazegraphMetadata -> blazegraphMetaCtx, // Composite views - compositeViewContexts.compositeViews -> compositeCtx + compositeViewContexts.compositeViews -> compositeCtx, + compositeViewContexts.compositeViewsMetadata -> compositeMetaCtx ) def resolverContextResolution( diff --git a/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/views/BlazegraphViewProcessor.scala b/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/views/BlazegraphViewProcessor.scala index fea2c60241..dddbe98488 100644 --- a/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/views/BlazegraphViewProcessor.scala +++ b/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/views/BlazegraphViewProcessor.scala @@ -5,9 +5,10 @@ import ch.epfl.bluebrain.nexus.delta.kernel.Logger import ch.epfl.bluebrain.nexus.delta.kernel.utils.UUIDF import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.BlazegraphViewEvent._ import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.BlazegraphViewRejection.{IncorrectRev, ResourceAlreadyExists} -import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.{BlazegraphViewEvent, BlazegraphViewValue, ViewResource} +import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.{defaultViewId, BlazegraphViewEvent, BlazegraphViewValue, ViewResource} import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.{BlazegraphViews, ValidateBlazegraphView} import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.api.JsonLdApi +import ch.epfl.bluebrain.nexus.delta.sdk.identities.model.Caller import ch.epfl.bluebrain.nexus.delta.sdk.projects.FetchContext import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.ResolverContextResolution import ch.epfl.bluebrain.nexus.delta.sourcing.Transactors @@ -38,11 +39,20 @@ class BlazegraphViewProcessor private ( private def evaluateInternal(event: BlazegraphViewEvent): IO[ImportStatus] = { implicit val s: Subject = event.subject + implicit val c: Caller = Caller(s, Set.empty) val cRev = event.rev - 1 val project = projectMapper.map(event.project) event match { - case e: BlazegraphViewCreated => views(event.uuid).flatMap(_.create(e.id, project, e.value)) - case e: BlazegraphViewUpdated => views(event.uuid).flatMap(_.update(e.id, project, cRev, e.value)) + case e: BlazegraphViewCreated => + e.id match { + case id if id == defaultViewId => views(event.uuid).flatMap(_.create(e.id, project, e.value)) + case _ => views(event.uuid).flatMap(_.create(e.id, project, e.source)) + } + case e: BlazegraphViewUpdated => + e.id match { + case id if id == defaultViewId => views(event.uuid).flatMap(_.update(e.id, project, cRev, e.value)) + case _ => views(event.uuid).flatMap(_.update(e.id, project, cRev, e.source)) + } case e: BlazegraphViewDeprecated => views(event.uuid).flatMap(_.deprecate(e.id, project, cRev)) case e: BlazegraphViewUndeprecated => views(event.uuid).flatMap(_.undeprecate(e.id, project, cRev)) case _: BlazegraphViewTagAdded => IO.unit // TODO: Can we tag? @@ -74,7 +84,7 @@ object BlazegraphViewProcessor { val noValidation = new ValidateBlazegraphView { override def apply(value: BlazegraphViewValue): IO[Unit] = IO.unit } - val prefix = "wrong_prefix" // TODO: fix prefix + val prefix = "nexus" // TODO: use the config? val views = (uuid: UUID) => BlazegraphViews( diff --git a/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/views/ElasticSearchViewProcessor.scala b/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/views/ElasticSearchViewProcessor.scala index 49433b44bd..43b017ab35 100644 --- a/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/views/ElasticSearchViewProcessor.scala +++ b/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/views/ElasticSearchViewProcessor.scala @@ -5,9 +5,10 @@ import ch.epfl.bluebrain.nexus.delta.kernel.Logger import ch.epfl.bluebrain.nexus.delta.kernel.utils.{ClasspathResourceLoader, UUIDF} import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.model.ElasticSearchViewEvent._ import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.model.ElasticSearchViewRejection.{IncorrectRev, ResourceAlreadyExists} -import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.model.{ElasticSearchFiles, ElasticSearchViewEvent, ElasticSearchViewValue} +import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.model.{defaultViewId, ElasticSearchFiles, ElasticSearchViewEvent, ElasticSearchViewValue} import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.{ElasticSearchViews, ValidateElasticSearchView} import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.api.JsonLdApi +import ch.epfl.bluebrain.nexus.delta.sdk.identities.model.Caller import ch.epfl.bluebrain.nexus.delta.sdk.projects.FetchContext import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.ResolverContextResolution import ch.epfl.bluebrain.nexus.delta.sdk.views.IndexingRev @@ -39,11 +40,20 @@ class ElasticSearchViewProcessor private ( private def evaluateInternal(event: ElasticSearchViewEvent): IO[ImportStatus] = { implicit val s: Subject = event.subject + implicit val c: Caller = Caller(s, Set.empty) val cRev = event.rev - 1 val project = projectMapper.map(event.project) event match { - case e: ElasticSearchViewCreated => views(event.uuid).flatMap(_.create(e.id, project, e.value)) - case e: ElasticSearchViewUpdated => views(event.uuid).flatMap(_.update(e.id, project, cRev, e.value)) + case e: ElasticSearchViewCreated => + e.id match { + case id if id == defaultViewId => views(event.uuid).flatMap(_.create(e.id, project, e.value)) + case _ => views(event.uuid).flatMap(_.create(e.id, project, e.source)) + } + case e: ElasticSearchViewUpdated => + e.id match { + case id if id == defaultViewId => views(event.uuid).flatMap(_.update(e.id, project, cRev, e.value)) + case _ => views(event.uuid).flatMap(_.update(e.id, project, cRev, e.source)) + } case e: ElasticSearchViewDeprecated => views(event.uuid).flatMap(_.deprecate(e.id, project, cRev)) case e: ElasticSearchViewUndeprecated => views(event.uuid).flatMap(_.undeprecate(e.id, project, cRev)) case _: ElasticSearchViewTagAdded => IO.unit // TODO: Check if this is correct @@ -78,7 +88,7 @@ object ElasticSearchViewProcessor { val noValidation = new ValidateElasticSearchView { override def apply(uuid: UUID, indexingRev: IndexingRev, v: ElasticSearchViewValue): IO[Unit] = IO.unit } - val prefix = "wrong_prefix" // TODO: fix prefix + val prefix = "nexus" // TODO: use the config? val esFiles = ElasticSearchFiles.mk(loader) for {