From 84fbc22c8ca8791d4b9c931864b1778ee98350d9 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 24 Feb 2025 17:46:37 +0100 Subject: [PATCH] Do not index views anymore (#5288) Co-authored-by: Simon Dumas --- .../nexus/delta/wiring/StreamModule.scala | 7 +-- .../delta/routes/SchemaJobRoutesSpec.scala | 2 +- .../blazegraph/BlazegraphPluginModule.scala | 29 +-------- .../blazegraph/model/BlazegraphView.scala | 18 ------ .../model/BlazegraphViewEvent.scala | 28 +-------- .../routes/BlazegraphViewsRoutes.scala | 60 +++++++++---------- .../BlazegraphViewsSerializationSuite.scala | 39 ++++-------- .../BlazegraphViewsIndexingRoutesSpec.scala | 2 +- .../routes/BlazegraphViewsRoutesSpec.scala | 4 +- .../CompositeViewsPluginModule.scala | 9 --- .../compositeviews/model/CompositeView.scala | 16 +---- .../model/CompositeViewEvent.scala | 30 +--------- .../CompositeViewsSerializationSuite.scala | 33 +--------- .../main/resources/contexts/aggregations.json | 9 --- .../ElasticSearchPluginModule.scala | 23 +------ .../elasticsearch/ElasticSearchViews.scala | 3 +- .../model/ElasticSearchView.scala | 22 +------ .../model/ElasticSearchViewEvent.scala | 28 +-------- .../plugins/elasticsearch/model/package.scala | 1 - .../routes/ElasticSearchViewsRoutes.scala | 38 ++++++------ .../elasticsearch/routes/ListingRoutes.scala | 15 ++--- .../plugins/elasticsearch/Fixtures.scala | 1 - .../ElasticSearchViewSerializationSuite.scala | 35 +++-------- .../ElasticSearchIndexingRoutesSpec.scala | 2 +- .../routes/ElasticSearchViewsRoutesSpec.scala | 4 +- .../routes/ListingRoutesSpec.scala | 3 +- .../routes/MainIndexRoutesSpec.scala | 2 +- .../nexus/delta/sdk/ResourceShifts.scala | 5 +- .../sdk/model/search/AggregationResult.scala | 7 --- .../nexus/delta/sdk/schemas/Schemas.scala | 6 +- .../sourcing/projections/Projections.scala | 18 +++++- .../delta/sourcing/query/ElemStreaming.scala | 11 ++-- .../delta/sourcing/query/StreamingQuery.scala | 15 ++++- .../sourcing/query/ElemStreamingSuite.scala | 44 +++++--------- .../sourcing/stream/SupervisorSetup.scala | 2 +- .../kg/aggregations/org-aggregation.json | 45 +++++--------- .../kg/aggregations/project-aggregation.json | 45 ++++++-------- .../kg/aggregations/root-aggregation.json | 21 ++----- .../kg/aggregations/views-aggregation.json | 32 ---------- .../nexus/tests/kg/AggregationsSpec.scala | 12 ---- .../nexus/tests/kg/CompositeViewsSpec.scala | 49 +++------------ .../nexus/tests/kg/DefaultIndexSpec.scala | 16 +++-- .../tests/kg/ElasticSearchViewsSpec.scala | 7 --- .../bluebrain/nexus/tests/kg/EventsSpec.scala | 27 ++++----- .../nexus/tests/kg/ListingsSpec.scala | 2 +- .../nexus/tests/kg/ProjectsDeletionSpec.scala | 52 +++++++--------- .../nexus/tests/kg/SparqlViewsSpec.scala | 13 +--- .../IncomingOutgoingBlazegraphSpec.scala | 2 +- 48 files changed, 243 insertions(+), 651 deletions(-) delete mode 100644 delta/plugins/elasticsearch/src/main/resources/contexts/aggregations.json delete mode 100644 tests/src/test/resources/kg/aggregations/views-aggregation.json diff --git a/delta/app/src/main/scala/ch/epfl/bluebrain/nexus/delta/wiring/StreamModule.scala b/delta/app/src/main/scala/ch/epfl/bluebrain/nexus/delta/wiring/StreamModule.scala index 1e1638364a..a8d8649db4 100644 --- a/delta/app/src/main/scala/ch/epfl/bluebrain/nexus/delta/wiring/StreamModule.scala +++ b/delta/app/src/main/scala/ch/epfl/bluebrain/nexus/delta/wiring/StreamModule.scala @@ -1,6 +1,5 @@ package ch.epfl.bluebrain.nexus.delta.wiring -import cats.data.NonEmptyList import cats.effect.{Clock, IO, Sync} import ch.epfl.bluebrain.nexus.delta.sdk.ResourceShifts import ch.epfl.bluebrain.nexus.delta.sdk.stream.GraphResourceStream @@ -22,7 +21,7 @@ object StreamModule extends ModuleDef { make[ElemStreaming].from { (xas: Transactors, shifts: ResourceShifts, queryConfig: ElemQueryConfig, activitySignals: ProjectActivitySignals) => - new ElemStreaming(xas, NonEmptyList.fromList(shifts.entityTypes.toList), queryConfig, activitySignals) + new ElemStreaming(xas, shifts.entityTypes, queryConfig, activitySignals) } make[GraphResourceStream].from { (elemStreaming: ElemStreaming, shifts: ResourceShifts) => @@ -44,8 +43,8 @@ object StreamModule extends ModuleDef { registry } - make[Projections].from { (xas: Transactors, cfg: ProjectionConfig, clock: Clock[IO]) => - Projections(xas, cfg.query, clock) + make[Projections].from { (xas: Transactors, shifts: ResourceShifts, cfg: ProjectionConfig, clock: Clock[IO]) => + Projections(xas, shifts.entityTypes, cfg.query, clock) } make[ProjectionErrors].from { (xas: Transactors, clock: Clock[IO], cfg: ProjectionConfig) => diff --git a/delta/app/src/test/scala/ch/epfl/bluebrain/nexus/delta/routes/SchemaJobRoutesSpec.scala b/delta/app/src/test/scala/ch/epfl/bluebrain/nexus/delta/routes/SchemaJobRoutesSpec.scala index 83723505af..b9c3193d6e 100644 --- a/delta/app/src/test/scala/ch/epfl/bluebrain/nexus/delta/routes/SchemaJobRoutesSpec.scala +++ b/delta/app/src/test/scala/ch/epfl/bluebrain/nexus/delta/routes/SchemaJobRoutesSpec.scala @@ -40,7 +40,7 @@ class SchemaJobRoutesSpec extends BaseRouteSpec { private val aclCheck = AclSimpleCheck((alice, Root, Set(Permissions.schemas.run))).accepted - private lazy val projections = Projections(xas, queryConfig, clock) + private lazy val projections = Projections(xas, None, queryConfig, clock) private lazy val projectionErrors = ProjectionErrors(xas, queryConfig, clock) private val progress = ProjectionProgress(Offset.at(15L), Instant.EPOCH, 9000L, 400L, 30L) diff --git a/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/BlazegraphPluginModule.scala b/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/BlazegraphPluginModule.scala index af999cb301..ae848456b2 100644 --- a/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/BlazegraphPluginModule.scala +++ b/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/BlazegraphPluginModule.scala @@ -8,12 +8,11 @@ import ch.epfl.bluebrain.nexus.delta.kernel.utils.{ClasspathResourceLoader, UUID 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.{contexts, schema => viewsSchemaId, BlazegraphView, BlazegraphViewEvent, DefaultProperties} +import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.{contexts, BlazegraphViewEvent, DefaultProperties} import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.routes.{BlazegraphSupervisionRoutes, BlazegraphViewsIndexingRoutes, BlazegraphViewsRoutes, BlazegraphViewsRoutesHandler} import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.slowqueries.{BlazegraphSlowQueryDeleter, BlazegraphSlowQueryLogger, BlazegraphSlowQueryStore} import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.{ContextValue, RemoteContextResolution} import ch.epfl.bluebrain.nexus.delta.rdf.utils.JsonKeyOrdering -import ch.epfl.bluebrain.nexus.delta.sdk.IndexingAction.AggregateIndexingAction import ch.epfl.bluebrain.nexus.delta.sdk._ import ch.epfl.bluebrain.nexus.delta.sdk.acls.AclCheck import ch.epfl.bluebrain.nexus.delta.sdk.deletion.ProjectDeletionTask @@ -22,7 +21,6 @@ import ch.epfl.bluebrain.nexus.delta.sdk.fusion.FusionConfig import ch.epfl.bluebrain.nexus.delta.sdk.identities.Identities import ch.epfl.bluebrain.nexus.delta.sdk.identities.model.ServiceAccount import ch.epfl.bluebrain.nexus.delta.sdk.model._ -import ch.epfl.bluebrain.nexus.delta.sdk.model.metrics.ScopedEventMetricEncoder import ch.epfl.bluebrain.nexus.delta.sdk.permissions.Permissions import ch.epfl.bluebrain.nexus.delta.sdk.projects.FetchContext import ch.epfl.bluebrain.nexus.delta.sdk.projects.model.ApiMappings @@ -30,7 +28,6 @@ import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.ResolverContextResolution import ch.epfl.bluebrain.nexus.delta.sdk.sse.SseEncoder import ch.epfl.bluebrain.nexus.delta.sdk.stream.GraphResourceStream import ch.epfl.bluebrain.nexus.delta.sourcing.Transactors -import ch.epfl.bluebrain.nexus.delta.sourcing.model.Label import ch.epfl.bluebrain.nexus.delta.sourcing.projections.{ProjectionErrors, Projections} import ch.epfl.bluebrain.nexus.delta.sourcing.stream.{ReferenceRegistry, Supervisor} import izumi.distage.model.definition.{Id, ModuleDef} @@ -52,11 +49,7 @@ class BlazegraphPluginModule(priority: Int) extends ModuleDef { HttpClient()(cfg.indexingClient, as) } - make[BlazegraphSlowQueryStore].from { (xas: Transactors) => - BlazegraphSlowQueryStore( - xas - ) - } + make[BlazegraphSlowQueryStore].from { (xas: Transactors) => BlazegraphSlowQueryStore(xas) } make[BlazegraphSlowQueryDeleter].fromEffect { (supervisor: Supervisor, store: BlazegraphSlowQueryStore, cfg: BlazegraphViewsConfig, clock: Clock[IO]) => @@ -183,8 +176,6 @@ class BlazegraphPluginModule(priority: Int) extends ModuleDef { aclCheck: AclCheck, views: BlazegraphViews, viewsQuery: BlazegraphViewsQuery, - indexingAction: AggregateIndexingAction, - shift: BlazegraphView.Shift, baseUri: BaseUri, cfg: BlazegraphViewsConfig, cr: RemoteContextResolution @Id("aggregate"), @@ -195,8 +186,7 @@ class BlazegraphPluginModule(priority: Int) extends ModuleDef { views, viewsQuery, identities, - aclCheck, - indexingAction(_, _, _)(shift) + aclCheck )( baseUri, cr, @@ -256,8 +246,6 @@ class BlazegraphPluginModule(priority: Int) extends ModuleDef { many[SseEncoder[_]].add { base: BaseUri => BlazegraphViewEvent.sseEncoder(base) } - many[ScopedEventMetricEncoder[_]].add { BlazegraphViewEvent.bgViewMetricEncoder } - many[RemoteContextResolution].addEffect( for { blazegraphCtx <- ContextValue.fromFile("contexts/sparql.json") @@ -268,10 +256,6 @@ class BlazegraphPluginModule(priority: Int) extends ModuleDef { ) ) - many[ResourceToSchemaMappings].add( - ResourceToSchemaMappings(Label.unsafe("views") -> viewsSchemaId.iri) - ) - many[ApiMappings].add(BlazegraphViews.mappings) many[PriorityRoute].add { @@ -308,11 +292,4 @@ class BlazegraphPluginModule(priority: Int) extends ModuleDef { ) => BlazegraphIndexingAction(views, registry, client, config.syncIndexingTimeout)(baseUri) } - - make[BlazegraphView.Shift].from { (views: BlazegraphViews, base: BaseUri) => - BlazegraphView.shift(views)(base) - } - - many[ResourceShift[_, _, _]].ref[BlazegraphView.Shift] - } diff --git a/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/model/BlazegraphView.scala b/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/model/BlazegraphView.scala index 0093cc655a..ec197bcd21 100644 --- a/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/model/BlazegraphView.scala +++ b/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/model/BlazegraphView.scala @@ -1,15 +1,11 @@ package ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model import cats.data.NonEmptySet -import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.BlazegraphViews import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.BlazegraphView.Metadata import ch.epfl.bluebrain.nexus.delta.rdf.IriOrBNode.Iri import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.ContextValue import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.JsonLdContext.keywords import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.encoder.JsonLdEncoder -import ch.epfl.bluebrain.nexus.delta.sdk.ResourceShift -import ch.epfl.bluebrain.nexus.delta.sdk.jsonld.JsonLdContent -import ch.epfl.bluebrain.nexus.delta.sdk.model.{BaseUri, IdSegmentRef} import ch.epfl.bluebrain.nexus.delta.sdk.permissions.model.Permission import ch.epfl.bluebrain.nexus.delta.sdk.syntax._ import ch.epfl.bluebrain.nexus.delta.sdk.views.ViewRef @@ -94,8 +90,6 @@ object BlazegraphView { * whether to consider deprecated resources for indexing * @param permission * the permission required for querying this view - * @param tags - * the collection of tags for this resource * @param source * the original json value provided by the caller */ @@ -128,8 +122,6 @@ object BlazegraphView { * a reference to the parent project * @param views * the collection of views where queries will be delegated (if necessary permissions are met) - * @param tags - * the collection of tags for this resource * @param source * the original json value provided by the caller */ @@ -180,14 +172,4 @@ object BlazegraphView { implicit val blazegraphMetadataJsonLdEncoder: JsonLdEncoder[Metadata] = JsonLdEncoder.computeFromCirce(ContextValue(contexts.blazegraphMetadata)) - - type Shift = ResourceShift[BlazegraphViewState, BlazegraphView, Metadata] - - def shift(views: BlazegraphViews)(implicit baseUri: BaseUri): Shift = - ResourceShift.withMetadata[BlazegraphViewState, BlazegraphView, Metadata]( - BlazegraphViews.entityType, - (ref, project) => views.fetch(IdSegmentRef(ref), project), - state => state.toResource, - value => JsonLdContent(value, value.value.source, Some(value.value.metadata)) - ) } diff --git a/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/model/BlazegraphViewEvent.scala b/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/model/BlazegraphViewEvent.scala index 43f6620bfc..6ea6304525 100644 --- a/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/model/BlazegraphViewEvent.scala +++ b/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/model/BlazegraphViewEvent.scala @@ -9,9 +9,7 @@ import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.JsonLdContext.keywords import ch.epfl.bluebrain.nexus.delta.sdk.instances._ import ch.epfl.bluebrain.nexus.delta.sdk.jsonld.IriEncoder import ch.epfl.bluebrain.nexus.delta.sdk.model.BaseUri -import ch.epfl.bluebrain.nexus.delta.sdk.model.metrics.EventMetric._ -import ch.epfl.bluebrain.nexus.delta.sdk.model.metrics.ScopedEventMetricEncoder -import ch.epfl.bluebrain.nexus.delta.sdk.sse.{resourcesSelector, SseEncoder} +import ch.epfl.bluebrain.nexus.delta.sdk.sse.SseEncoder import ch.epfl.bluebrain.nexus.delta.sourcing.Serializer import ch.epfl.bluebrain.nexus.delta.sourcing.event.Event.ScopedEvent import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.Subject @@ -238,34 +236,12 @@ object BlazegraphViewEvent { Serializer.dropNulls() } - val bgViewMetricEncoder: ScopedEventMetricEncoder[BlazegraphViewEvent] = - new ScopedEventMetricEncoder[BlazegraphViewEvent] { - override def databaseDecoder: Decoder[BlazegraphViewEvent] = serializer.codec - - override def entityType: EntityType = BlazegraphViews.entityType - - override def eventToMetric: BlazegraphViewEvent => ProjectScopedMetric = event => - ProjectScopedMetric.from( - event, - event match { - case _: BlazegraphViewCreated => Created - case _: BlazegraphViewUpdated => Updated - case _: BlazegraphViewTagAdded => Tagged - case _: BlazegraphViewDeprecated => Deprecated - case _: BlazegraphViewUndeprecated => Undeprecated - }, - event.id, - event.tpe.types, - JsonObject.empty - ) - } - def sseEncoder(implicit base: BaseUri): SseEncoder[BlazegraphViewEvent] = new SseEncoder[BlazegraphViewEvent] { override val databaseDecoder: Decoder[BlazegraphViewEvent] = serializer.codec override def entityType: EntityType = BlazegraphViews.entityType - override val selectors: Set[Label] = Set(Label.unsafe("views"), resourcesSelector) + override val selectors: Set[Label] = Set(Label.unsafe("views")) override val sseEncoder: Encoder.AsObject[BlazegraphViewEvent] = { val context = ContextValue(Vocabulary.contexts.metadata, contexts.blazegraph) diff --git a/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/routes/BlazegraphViewsRoutes.scala b/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/routes/BlazegraphViewsRoutes.scala index 27a5308e82..97a7c4438f 100644 --- a/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/routes/BlazegraphViewsRoutes.scala +++ b/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/routes/BlazegraphViewsRoutes.scala @@ -15,7 +15,6 @@ import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.{ContextValue, RemoteCon import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.encoder.JsonLdEncoder import ch.epfl.bluebrain.nexus.delta.rdf.query.SparqlQuery import ch.epfl.bluebrain.nexus.delta.rdf.utils.JsonKeyOrdering -import ch.epfl.bluebrain.nexus.delta.sdk.IndexingAction import ch.epfl.bluebrain.nexus.delta.sdk.acls.AclCheck import ch.epfl.bluebrain.nexus.delta.sdk.directives.{AuthDirectives, DeltaDirectives} import ch.epfl.bluebrain.nexus.delta.sdk.fusion.FusionConfig @@ -39,15 +38,12 @@ import io.circe.Json * the identity module * @param aclCheck * to check the acls - * @param index - * the indexing action on write operations */ class BlazegraphViewsRoutes( views: BlazegraphViews, viewsQuery: BlazegraphViewsQuery, identities: Identities, - aclCheck: AclCheck, - index: IndexingAction.Execute[BlazegraphView] + aclCheck: AclCheck )(implicit baseUri: BaseUri, cr: RemoteContextResolution, @@ -95,28 +91,27 @@ class BlazegraphViewsRoutes( pathPrefix("views") { extractCaller { implicit caller => projectRef { implicit project => + val authorizeRead = authorizeFor(project, Read) + val authorizeWrite = authorizeFor(project, Write) // Create a view without id segment concat( - (pathEndOrSingleSlash & post & entity(as[Json]) & noParameter("rev") & indexingMode) { (source, mode) => - authorizeFor(project, Write).apply { - emitMetadataOrReject( - Created, - views.create(project, source).flatTap(index(project, _, mode)) - ) + (pathEndOrSingleSlash & post & entity(as[Json]) & noParameter("rev")) { source => + authorizeWrite { + emitMetadataOrReject(Created, views.create(project, source)) } }, - (idSegment & indexingMode) { (id, mode) => + idSegment { id => concat( pathEndOrSingleSlash { concat( put { - authorizeFor(project, Write).apply { + authorizeWrite { (parameter("rev".as[Int].?) & pathEndOrSingleSlash & entity(as[Json])) { case (None, source) => // Create a view with id segment emitMetadataOrReject( Created, - views.create(id, project, source).flatTap(index(project, _, mode)) + views.create(id, project, source) ) case (Some(rev), source) => // Update a view @@ -128,9 +123,9 @@ class BlazegraphViewsRoutes( }, (delete & parameter("rev".as[Int])) { rev => // Deprecate a view - authorizeFor(project, Write).apply { + authorizeWrite { emitMetadataOrReject( - views.deprecate(id, project, rev).flatTap(index(project, _, mode)) + views.deprecate(id, project, rev) ) } }, @@ -139,7 +134,7 @@ class BlazegraphViewsRoutes( emitOrFusionRedirect( project, id, - authorizeFor(project, Read).apply { + authorizeRead { emitFetch(views.fetch(id, project)) } ) @@ -148,9 +143,9 @@ class BlazegraphViewsRoutes( }, // Undeprecate a blazegraph view (pathPrefix("undeprecate") & put & parameter("rev".as[Int]) & - authorizeFor(project, Write) & pathEndOrSingleSlash) { rev => + authorizeWrite & pathEndOrSingleSlash) { rev => emitMetadataOrReject( - views.undeprecate(id, project, rev).flatTap(index(project, _, mode)) + views.undeprecate(id, project, rev) ) }, // Query a blazegraph view @@ -171,7 +166,7 @@ class BlazegraphViewsRoutes( }, // Fetch a view original source (pathPrefix("source") & get & pathEndOrSingleSlash & idSegmentRef(id)) { id => - authorizeFor(project, Read).apply { + authorizeRead { emitSource(views.fetch(id, project)) } }, @@ -202,29 +197,30 @@ class BlazegraphViewsRoutes( if (condition) idSegment.flatMap(_ => pass) else pass - private def incomingOutgoing(id: IdSegment, ref: ProjectRef)(implicit caller: Caller) = + private def incomingOutgoing(id: IdSegment, project: ProjectRef)(implicit caller: Caller) = { + val authorizeRead = authorizeFor(project, Read) + val metadataContext = ContextValue(Vocabulary.contexts.metadata) concat( (pathPrefix("incoming") & fromPaginated & pathEndOrSingleSlash & get & extractUri) { (pagination, uri) => implicit val searchJsonLdEncoder: JsonLdEncoder[SearchResults[SparqlLink]] = - searchResultsJsonLdEncoder(ContextValue(Vocabulary.contexts.metadata), pagination, uri) - - authorizeFor(ref, Read).apply { - emit(viewsQuery.incoming(id, ref, pagination).attemptNarrow[BlazegraphViewRejection]) + searchResultsJsonLdEncoder(metadataContext, pagination, uri) + authorizeRead { + emit(viewsQuery.incoming(id, project, pagination).attemptNarrow[BlazegraphViewRejection]) } }, (pathPrefix("outgoing") & fromPaginated & pathEndOrSingleSlash & get & extractUri & parameter( "includeExternalLinks".as[Boolean] ? true )) { (pagination, uri, includeExternal) => implicit val searchJsonLdEncoder: JsonLdEncoder[SearchResults[SparqlLink]] = - searchResultsJsonLdEncoder(ContextValue(Vocabulary.contexts.metadata), pagination, uri) - - authorizeFor(ref, Read).apply { + searchResultsJsonLdEncoder(metadataContext, pagination, uri) + authorizeRead { emit( - viewsQuery.outgoing(id, ref, pagination, includeExternal).attemptNarrow[BlazegraphViewRejection] + viewsQuery.outgoing(id, project, pagination, includeExternal).attemptNarrow[BlazegraphViewRejection] ) } } ) + } } object BlazegraphViewsRoutes { @@ -237,8 +233,7 @@ object BlazegraphViewsRoutes { views: BlazegraphViews, viewsQuery: BlazegraphViewsQuery, identities: Identities, - aclCheck: AclCheck, - index: IndexingAction.Execute[BlazegraphView] + aclCheck: AclCheck )(implicit baseUri: BaseUri, cr: RemoteContextResolution, @@ -250,8 +245,7 @@ object BlazegraphViewsRoutes { views, viewsQuery, identities, - aclCheck, - index + aclCheck ).routes } } diff --git a/delta/plugins/blazegraph/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/model/BlazegraphViewsSerializationSuite.scala b/delta/plugins/blazegraph/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/model/BlazegraphViewsSerializationSuite.scala index 92b9b44baf..9ef54494a6 100644 --- a/delta/plugins/blazegraph/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/model/BlazegraphViewsSerializationSuite.scala +++ b/delta/plugins/blazegraph/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/model/BlazegraphViewsSerializationSuite.scala @@ -7,14 +7,13 @@ import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.BlazegraphViewType import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.BlazegraphViewValue.{AggregateBlazegraphViewValue, IndexingBlazegraphViewValue} import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary.nxv import ch.epfl.bluebrain.nexus.delta.sdk.SerializationSuite -import ch.epfl.bluebrain.nexus.delta.sdk.model.metrics.EventMetric._ import ch.epfl.bluebrain.nexus.delta.sdk.permissions.model.Permission import ch.epfl.bluebrain.nexus.delta.sdk.sse.SseEncoder.SseData import ch.epfl.bluebrain.nexus.delta.sdk.views.ViewRef import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.{Subject, User} import ch.epfl.bluebrain.nexus.delta.sourcing.model.Tag.UserTag import ch.epfl.bluebrain.nexus.delta.sourcing.model.{IriFilter, Label, ProjectRef} -import io.circe.{Json, JsonObject} +import io.circe.Json import java.time.Instant import java.util.UUID @@ -61,20 +60,20 @@ class BlazegraphViewsSerializationSuite extends SerializationSuite { // format: on private val blazegraphViewsMapping = List( - (created, loadEvents("blazegraph", "default-indexing-view-created.json"), Created), - (created1, loadEvents("blazegraph", "indexing-view-created.json"), Created), - (created2, loadEvents("blazegraph", "aggregate-view-created.json"), Created), - (updated, loadEvents("blazegraph", "default-indexing-view-updated.json"), Updated), - (updated1, loadEvents("blazegraph", "indexing-view-updated.json"), Updated), - (updated2, loadEvents("blazegraph", "aggregate-view-updated.json"), Updated), - (tagged, loadEvents("blazegraph", "view-tag-added.json"), Tagged), - (deprecated, loadEvents("blazegraph", "view-deprecated.json"), Deprecated), - (undeprecated, loadEvents("blazegraph", "view-undeprecated.json"), Undeprecated) + (created, loadEvents("blazegraph", "default-indexing-view-created.json")), + (created1, loadEvents("blazegraph", "indexing-view-created.json")), + (created2, loadEvents("blazegraph", "aggregate-view-created.json")), + (updated, loadEvents("blazegraph", "default-indexing-view-updated.json")), + (updated1, loadEvents("blazegraph", "indexing-view-updated.json")), + (updated2, loadEvents("blazegraph", "aggregate-view-updated.json")), + (tagged, loadEvents("blazegraph", "view-tag-added.json")), + (deprecated, loadEvents("blazegraph", "view-deprecated.json")), + (undeprecated, loadEvents("blazegraph", "view-undeprecated.json")) ) private val sseEncoder = BlazegraphViewEvent.sseEncoder - blazegraphViewsMapping.foreach { case (event, (database, sse), action) => + blazegraphViewsMapping.foreach { case (event, (database, sse)) => test(s"Correctly serialize ${event.getClass.getSimpleName}") { assertOutput(BlazegraphViewEvent.serializer, event, database) } @@ -88,22 +87,6 @@ class BlazegraphViewsSerializationSuite extends SerializationSuite { .decodeJson(database) .assertRight(SseData(ClassUtils.simpleName(event), Some(projectRef), sse)) } - - test(s"Correctly encode ${event.getClass.getSimpleName} to metric") { - BlazegraphViewEvent.bgViewMetricEncoder.toMetric.decodeJson(database).assertRight { - ProjectScopedMetric( - instant, - subject, - event.rev, - Set(action), - projectRef, - Label.unsafe("myorg"), - event.id, - event.tpe.types, - JsonObject.empty - ) - } - } } private val statesMapping = Map( diff --git a/delta/plugins/blazegraph/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/routes/BlazegraphViewsIndexingRoutesSpec.scala b/delta/plugins/blazegraph/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/routes/BlazegraphViewsIndexingRoutesSpec.scala index 114d3a031e..66d036efb5 100644 --- a/delta/plugins/blazegraph/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/routes/BlazegraphViewsIndexingRoutesSpec.scala +++ b/delta/plugins/blazegraph/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/routes/BlazegraphViewsIndexingRoutesSpec.scala @@ -26,7 +26,7 @@ import java.time.Instant class BlazegraphViewsIndexingRoutesSpec extends BlazegraphViewRoutesFixtures { - private lazy val projections = Projections(xas, queryConfig, clock) + private lazy val projections = Projections(xas, None, queryConfig, clock) private lazy val projectionErrors = ProjectionErrors(xas, queryConfig, clock) private val myId = nxv + "myid" diff --git a/delta/plugins/blazegraph/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/routes/BlazegraphViewsRoutesSpec.scala b/delta/plugins/blazegraph/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/routes/BlazegraphViewsRoutesSpec.scala index 21dd5e3f9a..88cbd8483e 100644 --- a/delta/plugins/blazegraph/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/routes/BlazegraphViewsRoutesSpec.scala +++ b/delta/plugins/blazegraph/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/routes/BlazegraphViewsRoutesSpec.scala @@ -15,7 +15,6 @@ import ch.epfl.bluebrain.nexus.delta.kernel.RdfMediaTypes._ import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary.nxv import ch.epfl.bluebrain.nexus.delta.rdf.query.SparqlQuery import ch.epfl.bluebrain.nexus.delta.rdf.query.SparqlQuery.SparqlConstructQuery -import ch.epfl.bluebrain.nexus.delta.sdk.IndexingAction import ch.epfl.bluebrain.nexus.delta.sdk.acls.model.AclAddress import ch.epfl.bluebrain.nexus.delta.sdk.directives.DeltaSchemeDirectives import ch.epfl.bluebrain.nexus.delta.sdk.fusion.FusionConfig @@ -76,8 +75,7 @@ class BlazegraphViewsRoutesSpec extends BlazegraphViewRoutesFixtures { views, viewsQuery, identities, - aclCheck, - IndexingAction.noop + aclCheck ) ) ) diff --git a/delta/plugins/composite-views/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/compositeviews/CompositeViewsPluginModule.scala b/delta/plugins/composite-views/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/compositeviews/CompositeViewsPluginModule.scala index 5c40f1e682..e254b29280 100644 --- a/delta/plugins/composite-views/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/compositeviews/CompositeViewsPluginModule.scala +++ b/delta/plugins/composite-views/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/compositeviews/CompositeViewsPluginModule.scala @@ -28,7 +28,6 @@ import ch.epfl.bluebrain.nexus.delta.sdk.directives.DeltaSchemeDirectives import ch.epfl.bluebrain.nexus.delta.sdk.fusion.FusionConfig import ch.epfl.bluebrain.nexus.delta.sdk.identities.Identities import ch.epfl.bluebrain.nexus.delta.sdk.model._ -import ch.epfl.bluebrain.nexus.delta.sdk.model.metrics.ScopedEventMetricEncoder import ch.epfl.bluebrain.nexus.delta.sdk.permissions.Permissions import ch.epfl.bluebrain.nexus.delta.sdk.projects.{FetchContext, Projects} import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.ResolverContextResolution @@ -330,16 +329,8 @@ class CompositeViewsPluginModule(priority: Int) extends ModuleDef { CompositeSupervisionRoutes(views, client, identities, aclCheck, config.prefix)(cr, ordering) } - make[CompositeView.Shift].from { (views: CompositeViews, base: BaseUri) => - CompositeView.shift(views)(base) - } - - many[ResourceShift[_, _, _]].ref[CompositeView.Shift] - many[SseEncoder[_]].add { (base: BaseUri) => CompositeViewEvent.sseEncoder(base) } - many[ScopedEventMetricEncoder[_]].add { () => CompositeViewEvent.compositeViewMetricEncoder } - many[PriorityRoute].add { ( cv: CompositeViewsRoutes, diff --git a/delta/plugins/composite-views/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/compositeviews/model/CompositeView.scala b/delta/plugins/composite-views/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/compositeviews/model/CompositeView.scala index 737c605663..20aee73fc4 100644 --- a/delta/plugins/composite-views/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/compositeviews/model/CompositeView.scala +++ b/delta/plugins/composite-views/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/compositeviews/model/CompositeView.scala @@ -2,7 +2,6 @@ package ch.epfl.bluebrain.nexus.delta.plugins.compositeviews.model import cats.data.{NonEmptyList, NonEmptyMap} import cats.effect.IO -import ch.epfl.bluebrain.nexus.delta.plugins.compositeviews.CompositeViews import ch.epfl.bluebrain.nexus.delta.plugins.compositeviews.model.CompositeView.{Metadata, RebuildStrategy} import ch.epfl.bluebrain.nexus.delta.rdf.IriOrBNode.Iri import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary.nxv @@ -11,9 +10,7 @@ import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.JsonLdContext.keywords import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.{ContextValue, RemoteContextResolution} import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.encoder.JsonLdEncoder import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.{CompactedJsonLd, ExpandedJsonLd} -import ch.epfl.bluebrain.nexus.delta.sdk.ResourceShift -import ch.epfl.bluebrain.nexus.delta.sdk.jsonld.JsonLdContent -import ch.epfl.bluebrain.nexus.delta.sdk.model.{BaseUri, IdSegmentRef, Tags} +import ch.epfl.bluebrain.nexus.delta.sdk.model.{BaseUri, Tags} import ch.epfl.bluebrain.nexus.delta.sdk.syntax._ import ch.epfl.bluebrain.nexus.delta.sourcing.model.ProjectRef import io.circe.generic.extras.Configuration @@ -24,7 +21,6 @@ import io.circe.{Encoder, Json, JsonObject} import java.time.Instant import java.util.UUID - import scala.concurrent.duration.FiniteDuration /** @@ -166,14 +162,4 @@ object CompositeView { implicit val compositeViewMetadataJsonLdEncoder: JsonLdEncoder[Metadata] = JsonLdEncoder.computeFromCirce(ContextValue(contexts.compositeViewsMetadata)) - - type Shift = ResourceShift[CompositeViewState, CompositeView, Metadata] - - def shift(views: CompositeViews)(implicit baseUri: BaseUri): Shift = - ResourceShift.withMetadata[CompositeViewState, CompositeView, Metadata]( - CompositeViews.entityType, - (ref, project) => views.fetch(IdSegmentRef(ref), project), - state => state.toResource, - value => JsonLdContent(value, value.value.source, Some(value.value.metadata)) - ) } diff --git a/delta/plugins/composite-views/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/compositeviews/model/CompositeViewEvent.scala b/delta/plugins/composite-views/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/compositeviews/model/CompositeViewEvent.scala index 56dd3fc87a..9d915c21d8 100644 --- a/delta/plugins/composite-views/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/compositeviews/model/CompositeViewEvent.scala +++ b/delta/plugins/composite-views/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/compositeviews/model/CompositeViewEvent.scala @@ -9,9 +9,7 @@ import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.JsonLdContext.keywords import ch.epfl.bluebrain.nexus.delta.sdk.instances._ import ch.epfl.bluebrain.nexus.delta.sdk.jsonld.IriEncoder import ch.epfl.bluebrain.nexus.delta.sdk.model.BaseUri -import ch.epfl.bluebrain.nexus.delta.sdk.model.metrics.EventMetric._ -import ch.epfl.bluebrain.nexus.delta.sdk.model.metrics.ScopedEventMetricEncoder -import ch.epfl.bluebrain.nexus.delta.sdk.sse.{resourcesSelector, SseEncoder} +import ch.epfl.bluebrain.nexus.delta.sdk.sse.SseEncoder import ch.epfl.bluebrain.nexus.delta.sourcing.Serializer import ch.epfl.bluebrain.nexus.delta.sourcing.event.Event.ScopedEvent import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.Subject @@ -20,7 +18,7 @@ import ch.epfl.bluebrain.nexus.delta.sourcing.model.{EntityType, Label, ProjectR import io.circe.generic.extras.Configuration import io.circe.generic.extras.semiauto.{deriveConfiguredCodec, deriveConfiguredEncoder} import io.circe.syntax._ -import io.circe.{Codec, Decoder, Encoder, Json, JsonObject} +import io.circe.{Codec, Decoder, Encoder, Json} import java.time.Instant import java.util.UUID @@ -200,35 +198,13 @@ object CompositeViewEvent { Serializer.dropNulls() } - val compositeViewMetricEncoder: ScopedEventMetricEncoder[CompositeViewEvent] = - new ScopedEventMetricEncoder[CompositeViewEvent] { - override def databaseDecoder: Decoder[CompositeViewEvent] = serializer.codec - - override def entityType: EntityType = CompositeViews.entityType - - override def eventToMetric: CompositeViewEvent => ProjectScopedMetric = event => - ProjectScopedMetric.from( - event, - event match { - case _: CompositeViewCreated => Created - case _: CompositeViewUpdated => Updated - case _: CompositeViewTagAdded => Tagged - case _: CompositeViewDeprecated => Deprecated - case _: CompositeViewUndeprecated => Undeprecated - }, - event.id, - Set(nxv.View, compositeViewType), - JsonObject.empty - ) - } - def sseEncoder(implicit base: BaseUri): SseEncoder[CompositeViewEvent] = new SseEncoder[CompositeViewEvent] { override val databaseDecoder: Decoder[CompositeViewEvent] = serializer.codec override def entityType: EntityType = CompositeViews.entityType - override val selectors: Set[Label] = Set(Label.unsafe("views"), resourcesSelector) + override val selectors: Set[Label] = Set(Label.unsafe("views")) override val sseEncoder: Encoder.AsObject[CompositeViewEvent] = { val context = ContextValue(Vocabulary.contexts.metadata, contexts.compositeViews) diff --git a/delta/plugins/composite-views/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/compositeviews/model/CompositeViewsSerializationSuite.scala b/delta/plugins/composite-views/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/compositeviews/model/CompositeViewsSerializationSuite.scala index e29ce0f387..5da34bb4d8 100644 --- a/delta/plugins/composite-views/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/compositeviews/model/CompositeViewsSerializationSuite.scala +++ b/delta/plugins/composite-views/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/compositeviews/model/CompositeViewsSerializationSuite.scala @@ -2,18 +2,12 @@ package ch.epfl.bluebrain.nexus.delta.plugins.compositeviews.model import ch.epfl.bluebrain.nexus.delta.kernel.utils.ClassUtils import ch.epfl.bluebrain.nexus.delta.plugins.compositeviews.CompositeViewsFixture -import ch.epfl.bluebrain.nexus.delta.plugins.compositeviews.model.CompositeViewEvent.{CompositeViewCreated, CompositeViewDeprecated, CompositeViewTagAdded, CompositeViewUndeprecated, CompositeViewUpdated} -import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary.nxv +import ch.epfl.bluebrain.nexus.delta.plugins.compositeviews.model.CompositeViewEvent._ import ch.epfl.bluebrain.nexus.delta.sdk.SerializationSuite import ch.epfl.bluebrain.nexus.delta.sdk.model.Tags -import ch.epfl.bluebrain.nexus.delta.sdk.model.metrics.EventMetric._ import ch.epfl.bluebrain.nexus.delta.sdk.sse.SseEncoder.SseData import ch.epfl.bluebrain.nexus.delta.sdk.syntax._ -import ch.epfl.bluebrain.nexus.delta.sourcing.model.Label import ch.epfl.bluebrain.nexus.delta.sourcing.model.Tag.UserTag -import io.circe.JsonObject - -import java.time.Instant class CompositeViewsSerializationSuite extends SerializationSuite with CompositeViewsFixture { @@ -36,7 +30,6 @@ class CompositeViewsSerializationSuite extends SerializationSuite with Composite private val eventSerializer = CompositeViewEvent.serializer private val sseEncoder = CompositeViewEvent.sseEncoder - private val metricEncoder = CompositeViewEvent.compositeViewMetricEncoder eventsMapping.foreach { case (event, (database, sse)) => test(s"Correctly serialize ${event.getClass.getSimpleName}") { @@ -52,30 +45,6 @@ class CompositeViewsSerializationSuite extends SerializationSuite with Composite .decodeJson(database) .assertRight(SseData(ClassUtils.simpleName(event), Some(projectRef), sse)) } - - test(s"Correctly encode ${event.getClass.getSimpleName} to metric") { - metricEncoder.toMetric.decodeJson(database).assertRight { - ProjectScopedMetric( - Instant.EPOCH, - subject, - event.rev, - Set( - event match { - case _: CompositeViewCreated => Created - case _: CompositeViewUpdated => Updated - case _: CompositeViewTagAdded => Tagged - case _: CompositeViewDeprecated => Deprecated - case _: CompositeViewUndeprecated => Undeprecated - } - ), - projectRef, - Label.unsafe("myorg"), - event.id, - Set(nxv.View, compositeViewType), - JsonObject.empty - ) - } - } } private val state = CompositeViewState( diff --git a/delta/plugins/elasticsearch/src/main/resources/contexts/aggregations.json b/delta/plugins/elasticsearch/src/main/resources/contexts/aggregations.json deleted file mode 100644 index 1f8226c417..0000000000 --- a/delta/plugins/elasticsearch/src/main/resources/contexts/aggregations.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "@context": { - "@vocab": "https://bluebrain.github.io/nexus/vocabulary/" - }, - "@id": "https://bluebrain.github.io/nexus/contexts/aggregations.json", - "aggregations": { - "@container": "@list" - } -} \ No newline at end of file diff --git a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchPluginModule.scala b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchPluginModule.scala index c02e3bdf1d..a775c6f220 100644 --- a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchPluginModule.scala +++ b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchPluginModule.scala @@ -11,7 +11,7 @@ import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.deletion.{ElasticSear import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.indexing.{ElasticSearchCoordinator, MainIndexingAction, MainIndexingCoordinator} import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.main.MainIndexDef import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.metrics.{EventMetricsProjection, EventMetricsQuery, MetricsIndexDef} -import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.model.{contexts, schema => viewsSchemaId, ElasticSearchView, ElasticSearchViewEvent} +import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.model.{contexts, ElasticSearchViewEvent} import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.query.MainIndexQuery import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.routes._ import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.views.DefaultIndexDef @@ -19,7 +19,6 @@ import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.ContextValue.ContextObject import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.{ContextValue, RemoteContextResolution} import ch.epfl.bluebrain.nexus.delta.rdf.utils.JsonKeyOrdering -import ch.epfl.bluebrain.nexus.delta.sdk.IndexingAction.AggregateIndexingAction import ch.epfl.bluebrain.nexus.delta.sdk._ import ch.epfl.bluebrain.nexus.delta.sdk.acls.AclCheck import ch.epfl.bluebrain.nexus.delta.sdk.deletion.ProjectDeletionTask @@ -35,7 +34,6 @@ import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.ResolverContextResolution import ch.epfl.bluebrain.nexus.delta.sdk.sse.SseEncoder import ch.epfl.bluebrain.nexus.delta.sdk.stream.GraphResourceStream import ch.epfl.bluebrain.nexus.delta.sourcing.Transactors -import ch.epfl.bluebrain.nexus.delta.sourcing.model.Label import ch.epfl.bluebrain.nexus.delta.sourcing.projections.{ProjectionErrors, Projections} import ch.epfl.bluebrain.nexus.delta.sourcing.stream.{PipeChain, ReferenceRegistry, Supervisor} import izumi.distage.model.definition.{Id, ModuleDef} @@ -214,9 +212,7 @@ class ElasticSearchPluginModule(priority: Int) extends ModuleDef { identities: Identities, aclCheck: AclCheck, views: ElasticSearchViews, - indexingAction: AggregateIndexingAction, viewsQuery: ElasticSearchViewsQuery, - shift: ElasticSearchView.Shift, baseUri: BaseUri, cr: RemoteContextResolution @Id("aggregate"), ordering: JsonKeyOrdering, @@ -226,8 +222,7 @@ class ElasticSearchPluginModule(priority: Int) extends ModuleDef { identities, aclCheck, views, - viewsQuery, - indexingAction(_, _, _)(shift) + viewsQuery )( baseUri, cr, @@ -367,22 +362,18 @@ class ElasticSearchPluginModule(priority: Int) extends ModuleDef { many[SseEncoder[_]].add { base: BaseUri => ElasticSearchViewEvent.sseEncoder(base) } - many[ScopedEventMetricEncoder[_]].add { ElasticSearchViewEvent.esViewMetricEncoder } - many[RemoteContextResolution].addEffect { ( searchMetadataCtx: MetadataContextValue @Id("search-metadata"), indexingMetadataCtx: MetadataContextValue @Id("indexing-metadata") ) => for { - 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") } yield RemoteContextResolution.fixed( - contexts.aggregations -> aggregationsCtx, contexts.elasticsearch -> elasticsearchCtx, contexts.elasticsearchMetadata -> elasticsearchMetaCtx, contexts.elasticsearchIndexing -> elasticsearchIdxCtx, @@ -393,10 +384,6 @@ class ElasticSearchPluginModule(priority: Int) extends ModuleDef { ) } - many[ResourceToSchemaMappings].add( - ResourceToSchemaMappings(Label.unsafe("views") -> viewsSchemaId.iri) - ) - many[ApiMappings].add(ElasticSearchViews.mappings) many[PriorityRoute].add { @@ -448,10 +435,4 @@ class ElasticSearchPluginModule(priority: Int) extends ModuleDef { ) => MainIndexingAction(client, config.mainIndex, config.syncIndexingTimeout, config.syncIndexingRefresh)(cr) } - make[ElasticSearchView.Shift].from { (views: ElasticSearchViews, base: BaseUri, defaultIndexDef: DefaultIndexDef) => - ElasticSearchView.shift(views, defaultIndexDef)(base) - } - - many[ResourceShift[_, _, _]].ref[ElasticSearchView.Shift] - } diff --git a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchViews.scala b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchViews.scala index 15aa87a03b..7e507d9228 100644 --- a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchViews.scala +++ b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchViews.scala @@ -213,9 +213,8 @@ final class ElasticSearchViews private ( } yield res }.span("deprecateElasticSearchView") - private def validateNotDefaultView(iri: Iri): IO[Unit] = { + private def validateNotDefaultView(iri: Iri): IO[Unit] = IO.raiseWhen(iri == defaultViewId)(ViewIsDefaultView) - } /** * Undeprecates an existing ElasticSearchView. View undeprecation implies unblocking any query capabilities and in diff --git a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/model/ElasticSearchView.scala b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/model/ElasticSearchView.scala index a043d6f65a..ce3ea4a781 100644 --- a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/model/ElasticSearchView.scala +++ b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/model/ElasticSearchView.scala @@ -2,9 +2,7 @@ package ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.model import cats.data.NonEmptySet import cats.effect.IO -import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.ElasticSearchViews import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.model.ElasticSearchView.Metadata -import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.views.DefaultIndexDef import ch.epfl.bluebrain.nexus.delta.rdf.IriOrBNode.Iri import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.api.{JsonLdApi, JsonLdOptions} import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.ContextValue.ContextObject @@ -12,9 +10,7 @@ import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.JsonLdContext.keywords import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.{ContextValue, RemoteContextResolution} import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.encoder.JsonLdEncoder import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.{CompactedJsonLd, ExpandedJsonLd} -import ch.epfl.bluebrain.nexus.delta.sdk.ResourceShift -import ch.epfl.bluebrain.nexus.delta.sdk.jsonld.JsonLdContent -import ch.epfl.bluebrain.nexus.delta.sdk.model.{BaseUri, IdSegmentRef, Tags} +import ch.epfl.bluebrain.nexus.delta.sdk.model.Tags import ch.epfl.bluebrain.nexus.delta.sdk.permissions.model.Permission import ch.epfl.bluebrain.nexus.delta.sdk.syntax._ import ch.epfl.bluebrain.nexus.delta.sdk.views.{PipeStep, ViewRef} @@ -109,8 +105,6 @@ object ElasticSearchView { * the collection of tags for this resource * @param source * the original json value provided by the caller - * @param indexingRev - * the indexing revision */ final case class IndexingElasticSearchView( id: Iri, @@ -164,8 +158,6 @@ object ElasticSearchView { * * @param uuid * the optionally available unique view identifier - * @param indexingRev - * the optionally available indexing revision */ final case class Metadata(uuid: Option[UUID]) @@ -266,16 +258,4 @@ object ElasticSearchView { implicit val elasticSearchMetadataJsonLdEncoder: JsonLdEncoder[Metadata] = JsonLdEncoder.computeFromCirce(ContextValue(contexts.elasticsearchMetadata)) - - type Shift = ResourceShift[ElasticSearchViewState, ElasticSearchView, Metadata] - - def shift(views: ElasticSearchViews, defaultDef: DefaultIndexDef)(implicit - baseUri: BaseUri - ): Shift = - ResourceShift.withMetadata[ElasticSearchViewState, ElasticSearchView, Metadata]( - ElasticSearchViews.entityType, - (ref, project) => views.fetch(IdSegmentRef(ref), project), - state => state.toResource(defaultDef), - value => JsonLdContent(value, value.value.source, Some(value.value.metadata)) - ) } diff --git a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/model/ElasticSearchViewEvent.scala b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/model/ElasticSearchViewEvent.scala index 4bb1f0027d..06239fa35d 100644 --- a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/model/ElasticSearchViewEvent.scala +++ b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/model/ElasticSearchViewEvent.scala @@ -9,9 +9,7 @@ import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.JsonLdContext.keywords import ch.epfl.bluebrain.nexus.delta.sdk.instances._ import ch.epfl.bluebrain.nexus.delta.sdk.jsonld.IriEncoder import ch.epfl.bluebrain.nexus.delta.sdk.model.BaseUri -import ch.epfl.bluebrain.nexus.delta.sdk.model.metrics.EventMetric._ -import ch.epfl.bluebrain.nexus.delta.sdk.model.metrics.ScopedEventMetricEncoder -import ch.epfl.bluebrain.nexus.delta.sdk.sse.{resourcesSelector, SseEncoder} +import ch.epfl.bluebrain.nexus.delta.sdk.sse.SseEncoder import ch.epfl.bluebrain.nexus.delta.sourcing.Serializer import ch.epfl.bluebrain.nexus.delta.sourcing.event.Event.ScopedEvent import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.Subject @@ -220,34 +218,12 @@ object ElasticSearchViewEvent { Serializer.dropNulls() } - val esViewMetricEncoder: ScopedEventMetricEncoder[ElasticSearchViewEvent] = - new ScopedEventMetricEncoder[ElasticSearchViewEvent] { - override def databaseDecoder: Decoder[ElasticSearchViewEvent] = serializer.codec - - override def entityType: EntityType = ElasticSearchViews.entityType - - override def eventToMetric: ElasticSearchViewEvent => ProjectScopedMetric = event => - ProjectScopedMetric.from( - event, - event match { - case _: ElasticSearchViewCreated => Created - case _: ElasticSearchViewUpdated => Updated - case _: ElasticSearchViewTagAdded => Tagged - case _: ElasticSearchViewDeprecated => Deprecated - case _: ElasticSearchViewUndeprecated => Undeprecated - }, - event.id, - event.tpe.types, - JsonObject.empty - ) - } - def sseEncoder(implicit base: BaseUri): SseEncoder[ElasticSearchViewEvent] = new SseEncoder[ElasticSearchViewEvent] { override val databaseDecoder: Decoder[ElasticSearchViewEvent] = serializer.codec override def entityType: EntityType = ElasticSearchViews.entityType - override val selectors: Set[Label] = Set(Label.unsafe("views"), resourcesSelector) + override val selectors: Set[Label] = Set(Label.unsafe("views")) override val sseEncoder: Encoder.AsObject[ElasticSearchViewEvent] = { val context = ContextValue(Vocabulary.contexts.metadata, contexts.elasticsearch) diff --git a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/model/package.scala b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/model/package.scala index 147889b5ed..0cac2286d8 100644 --- a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/model/package.scala +++ b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/model/package.scala @@ -24,7 +24,6 @@ package object model { * ElasticSearch views contexts. */ object contexts { - val aggregations = nxvContexts + "aggregations.json" val elasticsearch = nxvContexts + "elasticsearch.json" val elasticsearchMetadata = nxvContexts + "elasticsearch-metadata.json" val elasticsearchIndexing = nxvContexts + "elasticsearch-indexing.json" diff --git a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/ElasticSearchViewsRoutes.scala b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/ElasticSearchViewsRoutes.scala index 65ceef7ca0..fec946e8a0 100644 --- a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/ElasticSearchViewsRoutes.scala +++ b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/ElasticSearchViewsRoutes.scala @@ -13,7 +13,6 @@ import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.model.permissions.{re import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.{ElasticSearchViews, ElasticSearchViewsQuery} import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.RemoteContextResolution import ch.epfl.bluebrain.nexus.delta.rdf.utils.JsonKeyOrdering -import ch.epfl.bluebrain.nexus.delta.sdk._ import ch.epfl.bluebrain.nexus.delta.sdk.acls.AclCheck import ch.epfl.bluebrain.nexus.delta.sdk.directives.AuthDirectives import ch.epfl.bluebrain.nexus.delta.sdk.directives.DeltaDirectives._ @@ -40,15 +39,12 @@ import scala.concurrent.duration.Duration * the elasticsearch views operations bundle * @param viewsQuery * the elasticsearch views query operations bundle - * @param index - * the indexing action on write operations */ final class ElasticSearchViewsRoutes( identities: Identities, aclCheck: AclCheck, views: ElasticSearchViews, - viewsQuery: ElasticSearchViewsQuery, - index: IndexingAction.Execute[ElasticSearchView] + viewsQuery: ElasticSearchViewsQuery )(implicit baseUri: BaseUri, cr: RemoteContextResolution, @@ -93,45 +89,47 @@ final class ElasticSearchViewsRoutes( pathPrefix("views") { extractCaller { implicit caller => projectRef { project => + val authorizeRead = authorizeFor(project, Read) + val authorizeWrite = authorizeFor(project, Write) concat( pathEndOrSingleSlash { // Create an elasticsearch view without id segment - (post & pathEndOrSingleSlash & noParameter("rev") & entity(as[Json]) & indexingMode) { (source, mode) => - authorizeFor(project, Write).apply { + (post & pathEndOrSingleSlash & noParameter("rev") & entity(as[Json])) { source => + authorizeWrite { emitMetadataOrReject( Created, - views.create(project, source).flatTap(index(project, _, mode)) + views.create(project, source) ) } } }, - (idSegment & indexingMode) { (id, mode) => + idSegment { id => concat( pathEndOrSingleSlash { concat( // Create or update an elasticsearch view put { - authorizeFor(project, Write).apply { + authorizeWrite { (parameter("rev".as[Int].?) & pathEndOrSingleSlash & entity(as[Json])) { case (None, source) => // Create an elasticsearch view with id segment emitMetadataOrReject( Created, - views.create(id, project, source).flatTap(index(project, _, mode)) + views.create(id, project, source) ) case (Some(rev), source) => // Update a view emitMetadataOrReject( - views.update(id, project, rev, source).flatTap(index(project, _, mode)) + views.update(id, project, rev, source) ) } } }, // Deprecate an elasticsearch view (delete & parameter("rev".as[Int])) { rev => - authorizeFor(project, Write).apply { + authorizeWrite { emitMetadataOrReject( - views.deprecate(id, project, rev).flatTap(index(project, _, mode)) + views.deprecate(id, project, rev) ) } }, @@ -140,7 +138,7 @@ final class ElasticSearchViewsRoutes( emitOrFusionRedirect( project, id, - authorizeFor(project, Read).apply { + authorizeRead { emitFetch(views.fetch(id, project)) } ) @@ -149,9 +147,9 @@ final class ElasticSearchViewsRoutes( }, // Undeprecate an elasticsearch view (pathPrefix("undeprecate") & put & pathEndOrSingleSlash & parameter("rev".as[Int])) { rev => - authorizeFor(project, Write).apply { + authorizeWrite { emitMetadataOrReject( - views.undeprecate(id, project, rev).flatTap(index(project, _, mode)) + views.undeprecate(id, project, rev) ) } }, @@ -207,8 +205,7 @@ object ElasticSearchViewsRoutes { identities: Identities, aclCheck: AclCheck, views: ElasticSearchViews, - viewsQuery: ElasticSearchViewsQuery, - index: IndexingAction.Execute[ElasticSearchView] + viewsQuery: ElasticSearchViewsQuery )(implicit baseUri: BaseUri, cr: RemoteContextResolution, @@ -219,7 +216,6 @@ object ElasticSearchViewsRoutes { identities, aclCheck, views, - viewsQuery, - index + viewsQuery ).routes } diff --git a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/ListingRoutes.scala b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/ListingRoutes.scala index 8c3ccb144c..770d8a0e98 100644 --- a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/ListingRoutes.scala +++ b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/ListingRoutes.scala @@ -12,16 +12,16 @@ import ch.epfl.bluebrain.nexus.delta.sdk.directives.DeltaDirectives._ import ch.epfl.bluebrain.nexus.delta.sdk.directives.{AuthDirectives, DeltaSchemeDirectives} import ch.epfl.bluebrain.nexus.delta.sdk.identities.Identities import ch.epfl.bluebrain.nexus.delta.sdk.identities.model.Caller -import ch.epfl.bluebrain.nexus.delta.sdk.marshalling.HttpResponseFields +import ch.epfl.bluebrain.nexus.delta.sdk.marshalling.RdfMarshalling import ch.epfl.bluebrain.nexus.delta.sdk.model._ -import ch.epfl.bluebrain.nexus.delta.sdk.model.search.AggregationResult.aggregationResultJsonLdEncoder import ch.epfl.bluebrain.nexus.delta.sdk.model.search.SearchResults.searchResultsJsonLdEncoder -import ch.epfl.bluebrain.nexus.delta.sdk.model.search.{AggregationResult, PaginationConfig, SearchResults} +import ch.epfl.bluebrain.nexus.delta.sdk.model.search.{PaginationConfig, SearchResults} import ch.epfl.bluebrain.nexus.delta.sdk.permissions.Permissions.resources import ch.epfl.bluebrain.nexus.delta.sdk.projects.ProjectScopeResolver import ch.epfl.bluebrain.nexus.delta.sourcing.Scope import ch.epfl.bluebrain.nexus.delta.sourcing.model.Label import io.circe.JsonObject +import io.circe.syntax.EncoderOps class ListingRoutes( identities: Identities, @@ -36,7 +36,8 @@ class ListingRoutes( cr: RemoteContextResolution, ordering: JsonKeyOrdering ) extends AuthDirectives(identities, aclCheck) - with ElasticSearchViewsDirectives { + with ElasticSearchViewsDirectives + with RdfMarshalling { import schemeDirectives._ @@ -164,14 +165,10 @@ class ListingRoutes( private def aggregate(request: MainIndexRequest, scope: Scope)(implicit caller: Caller): Route = (get & aggregated) { - implicit val searchJsonLdEncoder: JsonLdEncoder[AggregationResult] = - aggregationResultJsonLdEncoder(ContextValue(contexts.aggregations)) - - implicit val reultHttpResponseFields: HttpResponseFields[AggregationResult] = HttpResponseFields.defaultOk emit { projectScopeResolver(scope, resources.read).flatMap { projects => - defaultIndexQuery.aggregate(request, projects).attemptNarrow[ElasticSearchQueryError] + defaultIndexQuery.aggregate(request, projects).map(_.asJson).attemptNarrow[ElasticSearchQueryError] } } diff --git a/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/Fixtures.scala b/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/Fixtures.scala index d41b12e74a..a08528f6e2 100644 --- a/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/Fixtures.scala +++ b/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/Fixtures.scala @@ -42,7 +42,6 @@ trait Fixtures { implicit val rcr: RemoteContextResolution = RemoteContextResolution.fixedIOResource( elasticsearch -> ContextValue.fromFile("contexts/elasticsearch.json"), elasticsearchMetadata -> ContextValue.fromFile("contexts/elasticsearch-metadata.json"), - contexts.aggregations -> ContextValue.fromFile("contexts/aggregations.json"), contexts.elasticsearchIndexing -> ContextValue.fromFile("contexts/elasticsearch-indexing.json"), contexts.searchMetadata -> listingsMetadataCtx, contexts.indexingMetadata -> indexingMetadataCtx, diff --git a/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/model/ElasticSearchViewSerializationSuite.scala b/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/model/ElasticSearchViewSerializationSuite.scala index d8d976c67c..16b030a4f2 100644 --- a/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/model/ElasticSearchViewSerializationSuite.scala +++ b/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/model/ElasticSearchViewSerializationSuite.scala @@ -9,7 +9,6 @@ import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary.nxv import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.ContextValue.ContextObject import ch.epfl.bluebrain.nexus.delta.sdk.SerializationSuite import ch.epfl.bluebrain.nexus.delta.sdk.model.Tags -import ch.epfl.bluebrain.nexus.delta.sdk.model.metrics.EventMetric._ import ch.epfl.bluebrain.nexus.delta.sdk.permissions.model.Permission import ch.epfl.bluebrain.nexus.delta.sdk.sse.SseEncoder.SseData import ch.epfl.bluebrain.nexus.delta.sdk.views.{IndexingRev, PipeStep, ViewRef} @@ -17,7 +16,7 @@ import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.{Subject, User} import ch.epfl.bluebrain.nexus.delta.sourcing.model.Tag.UserTag import ch.epfl.bluebrain.nexus.delta.sourcing.model.{IriFilter, Label, ProjectRef} import ch.epfl.bluebrain.nexus.delta.sourcing.stream.pipes.{FilterBySchema, FilterByType, SourceAsText} -import io.circe.{Json, JsonObject} +import io.circe.Json import java.time.Instant import java.util.UUID @@ -66,18 +65,18 @@ class ElasticSearchViewSerializationSuite extends SerializationSuite { // format: on private val elasticsearchViewsMapping = List( - (created1, loadEvents("elasticsearch", "indexing-view-created.json"), Created), - (created2, loadEvents("elasticsearch", "aggregate-view-created.json"), Created), - (updated1, loadEvents("elasticsearch", "indexing-view-updated.json"), Updated), - (updated2, loadEvents("elasticsearch", "aggregate-view-updated.json"), Updated), - (tagged, loadEvents("elasticsearch", "view-tag-added.json"), Tagged), - (deprecated, loadEvents("elasticsearch", "view-deprecated.json"), Deprecated), - (undeprecated, loadEvents("elasticsearch", "view-undeprecated.json"), Undeprecated) + (created1, loadEvents("elasticsearch", "indexing-view-created.json")), + (created2, loadEvents("elasticsearch", "aggregate-view-created.json")), + (updated1, loadEvents("elasticsearch", "indexing-view-updated.json")), + (updated2, loadEvents("elasticsearch", "aggregate-view-updated.json")), + (tagged, loadEvents("elasticsearch", "view-tag-added.json")), + (deprecated, loadEvents("elasticsearch", "view-deprecated.json")), + (undeprecated, loadEvents("elasticsearch", "view-undeprecated.json")) ) private val sseEncoder = ElasticSearchViewEvent.sseEncoder - elasticsearchViewsMapping.foreach { case (event, (database, sse), action) => + elasticsearchViewsMapping.foreach { case (event, (database, sse)) => test(s"Correctly serialize ${event.getClass.getSimpleName}") { assertOutput(ElasticSearchViewEvent.serializer, event, database) } @@ -91,22 +90,6 @@ class ElasticSearchViewSerializationSuite extends SerializationSuite { .decodeJson(database) .assertRight(SseData(ClassUtils.simpleName(event), Some(projectRef), sse)) } - - test(s"Correctly encode ${event.getClass.getSimpleName} to metric") { - ElasticSearchViewEvent.esViewMetricEncoder.toMetric.decodeJson(database).assertRight { - ProjectScopedMetric( - instant, - subject, - event.rev, - Set(action), - projectRef, - Label.unsafe("myorg"), - event.id, - event.tpe.types, - JsonObject.empty - ) - } - } } private val statesMapping = Map( diff --git a/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/ElasticSearchIndexingRoutesSpec.scala b/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/ElasticSearchIndexingRoutesSpec.scala index 42d9e1af61..86b4890b66 100644 --- a/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/ElasticSearchIndexingRoutesSpec.scala +++ b/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/ElasticSearchIndexingRoutesSpec.scala @@ -35,7 +35,7 @@ class ElasticSearchIndexingRoutesSpec extends ElasticSearchViewsRoutesFixtures { implicit private val uuidF: UUIDF = UUIDF.fixed(uuid) - private lazy val projections = Projections(xas, queryConfig, clock) + private lazy val projections = Projections(xas, None, queryConfig, clock) private lazy val projectionErrors = ProjectionErrors(xas, queryConfig, clock) implicit private val fetchContext: FetchContext = FetchContextDummy(Map(project.value.ref -> project.value.context)) diff --git a/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/ElasticSearchViewsRoutesSpec.scala b/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/ElasticSearchViewsRoutesSpec.scala index d1730c0c09..f6a563d0b7 100644 --- a/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/ElasticSearchViewsRoutesSpec.scala +++ b/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/ElasticSearchViewsRoutesSpec.scala @@ -12,7 +12,6 @@ import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.{ElasticSearchViews, import ch.epfl.bluebrain.nexus.delta.rdf.IriOrBNode.Iri import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary.nxv import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.JsonLdContext.keywords -import ch.epfl.bluebrain.nexus.delta.sdk.IndexingAction import ch.epfl.bluebrain.nexus.delta.sdk.acls.model.AclAddress import ch.epfl.bluebrain.nexus.delta.sdk.directives.DeltaSchemeDirectives import ch.epfl.bluebrain.nexus.delta.sdk.fusion.FusionConfig @@ -85,8 +84,7 @@ class ElasticSearchViewsRoutesSpec extends ElasticSearchViewsRoutesFixtures { identities, aclCheck, views, - viewsQuery, - IndexingAction.noop + viewsQuery ) ) ) diff --git a/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/ListingRoutesSpec.scala b/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/ListingRoutesSpec.scala index 98ab2711a0..cd22af7177 100644 --- a/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/ListingRoutesSpec.scala +++ b/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/ListingRoutesSpec.scala @@ -4,7 +4,7 @@ import akka.http.scaladsl.model.StatusCodes import akka.http.scaladsl.server.Route import cats.effect.IO import ch.epfl.bluebrain.nexus.delta.kernel.utils.UrlUtils -import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.model.contexts.{aggregations, searchMetadata} +import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.model.contexts.searchMetadata import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.model.{permissions => esPermissions, schema => elasticSearchSchema} import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.routes.DummyMainIndexQuery._ import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary.contexts.search @@ -143,7 +143,6 @@ class ListingRoutesSpec extends ElasticSearchViewsRoutesFixtures { response.asJson shouldEqual JsonObject("total" -> 1.asJson) .add("aggregations", aggregationResponse.asJson) - .addContext(aggregations) .asJson } } diff --git a/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/MainIndexRoutesSpec.scala b/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/MainIndexRoutesSpec.scala index cfaaa9f321..d5bf249f7a 100644 --- a/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/MainIndexRoutesSpec.scala +++ b/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/routes/MainIndexRoutesSpec.scala @@ -19,7 +19,7 @@ import java.time.Instant class MainIndexRoutesSpec extends ElasticSearchViewsRoutesFixtures { - private lazy val projections = Projections(xas, queryConfig, clock) + private lazy val projections = Projections(xas, None, queryConfig, clock) private val project1 = ProjectRef.unsafe("org", "proj1") private val project2 = ProjectRef.unsafe("org", "proj2") diff --git a/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/ResourceShifts.scala b/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/ResourceShifts.scala index 4f0c7aea37..4b0ebc9356 100644 --- a/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/ResourceShifts.scala +++ b/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/ResourceShifts.scala @@ -1,5 +1,6 @@ package ch.epfl.bluebrain.nexus.delta.sdk +import cats.data.NonEmptyList import cats.effect.IO import cats.syntax.all._ import ch.epfl.bluebrain.nexus.delta.kernel.Logger @@ -16,7 +17,7 @@ import io.circe.Json */ trait ResourceShifts { - def entityTypes: Set[EntityType] + def entityTypes: Option[NonEmptyList[EntityType]] /** * Fetch a resource as a [[JsonLdContent]] @@ -42,7 +43,7 @@ object ResourceShifts { ): ResourceShifts = new ResourceShifts { private val shiftsMap = shifts.map { encoder => encoder.entityType -> encoder }.toMap - override def entityTypes: Set[EntityType] = shiftsMap.keySet + override def entityTypes: Option[NonEmptyList[EntityType]] = NonEmptyList.fromList(shiftsMap.keys.toList) private def findShift(entityType: EntityType): IO[ResourceShift[_, _, _]] = IO .fromOption(shiftsMap.get(entityType))( diff --git a/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/model/search/AggregationResult.scala b/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/model/search/AggregationResult.scala index 7d9e2a1423..1a9245b5eb 100644 --- a/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/model/search/AggregationResult.scala +++ b/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/model/search/AggregationResult.scala @@ -1,7 +1,5 @@ package ch.epfl.bluebrain.nexus.delta.sdk.model.search -import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.ContextValue -import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.encoder.JsonLdEncoder import io.circe.syntax.KeyOps import io.circe.{Encoder, Json, JsonObject} @@ -28,9 +26,4 @@ object AggregationResult { ) } - def aggregationResultJsonLdEncoder( - contextValue: ContextValue - ): JsonLdEncoder[AggregationResult] = - JsonLdEncoder.computeFromCirce(contextValue) - } diff --git a/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/schemas/Schemas.scala b/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/schemas/Schemas.scala index ed4c969852..573dfb962d 100644 --- a/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/schemas/Schemas.scala +++ b/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/schemas/Schemas.scala @@ -197,12 +197,12 @@ trait Schemas { ): IO[SchemaResource] = fetch(IdSegmentRef(resourceRef), projectRef) /** - * Lists all resolvers. + * Lists all schemas. * * @param project - * the project the resolvers belong to + * the project the schemas belong to * @return - * the list of resolvers in that project + * the list of schemas in that project */ def list(project: ProjectRef): IO[UnscoredSearchResults[SchemaResource]] } diff --git a/delta/sourcing-psql/src/main/scala/ch/epfl/bluebrain/nexus/delta/sourcing/projections/Projections.scala b/delta/sourcing-psql/src/main/scala/ch/epfl/bluebrain/nexus/delta/sourcing/projections/Projections.scala index 613fec9987..deac3f9482 100644 --- a/delta/sourcing-psql/src/main/scala/ch/epfl/bluebrain/nexus/delta/sourcing/projections/Projections.scala +++ b/delta/sourcing-psql/src/main/scala/ch/epfl/bluebrain/nexus/delta/sourcing/projections/Projections.scala @@ -1,9 +1,10 @@ package ch.epfl.bluebrain.nexus.delta.sourcing.projections +import cats.data.NonEmptyList import cats.effect.{Clock, IO} import ch.epfl.bluebrain.nexus.delta.sourcing.config.{PurgeConfig, QueryConfig} import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.Subject -import ch.epfl.bluebrain.nexus.delta.sourcing.model.ProjectRef +import ch.epfl.bluebrain.nexus.delta.sourcing.model.{EntityType, ProjectRef} import ch.epfl.bluebrain.nexus.delta.sourcing.offset.Offset import ch.epfl.bluebrain.nexus.delta.sourcing.projections.model.ProjectionRestart import ch.epfl.bluebrain.nexus.delta.sourcing.query.{SelectFilter, StreamingQuery} @@ -100,7 +101,12 @@ trait Projections { object Projections { - def apply(xas: Transactors, config: QueryConfig, clock: Clock[IO]): Projections = + def apply( + xas: Transactors, + entityTypes: Option[NonEmptyList[EntityType]], + config: QueryConfig, + clock: Clock[IO] + ): Projections = new Projections { private val projectionStore = ProjectionStore(xas, config, clock) private val projectionRestartStore = new ProjectionRestartStore(xas, config) @@ -135,7 +141,13 @@ object Projections { for { current <- progress(projectionId) remaining <- - StreamingQuery.remaining(Scope(project), selectFilter, current.fold(Offset.start)(_.offset), xas) + StreamingQuery.remaining( + Scope(project), + entityTypes, + selectFilter, + current.fold(Offset.start)(_.offset), + xas + ) } yield ProgressStatistics(current, remaining) } diff --git a/delta/sourcing-psql/src/main/scala/ch/epfl/bluebrain/nexus/delta/sourcing/query/ElemStreaming.scala b/delta/sourcing-psql/src/main/scala/ch/epfl/bluebrain/nexus/delta/sourcing/query/ElemStreaming.scala index fb0400a74b..0245372f51 100644 --- a/delta/sourcing-psql/src/main/scala/ch/epfl/bluebrain/nexus/delta/sourcing/query/ElemStreaming.scala +++ b/delta/sourcing-psql/src/main/scala/ch/epfl/bluebrain/nexus/delta/sourcing/query/ElemStreaming.scala @@ -11,7 +11,7 @@ import ch.epfl.bluebrain.nexus.delta.sourcing.model.{EntityType, Label, ProjectR import ch.epfl.bluebrain.nexus.delta.sourcing.{Scope, Transactors} import ch.epfl.bluebrain.nexus.delta.sourcing.offset.Offset import ch.epfl.bluebrain.nexus.delta.sourcing.query.ElemStreaming.{logger, newState} -import ch.epfl.bluebrain.nexus.delta.sourcing.query.StreamingQuery.{logQuery, stateFilter, typesSqlArray} +import ch.epfl.bluebrain.nexus.delta.sourcing.query.StreamingQuery.{entityTypeFilter, logQuery, stateFilter, typesSqlArray} import ch.epfl.bluebrain.nexus.delta.sourcing.stream.Elem.{DroppedElem, SuccessElem} import ch.epfl.bluebrain.nexus.delta.sourcing.stream.{Elem, ProjectActivitySignals, RemainingElems} import doobie.syntax.all._ @@ -52,7 +52,7 @@ final class ElemStreaming( * the offset to start from */ def remaining(scope: Scope, selectFilter: SelectFilter, start: Offset): IO[Option[RemainingElems]] = - StreamingQuery.remaining(scope, selectFilter, start, xas) + StreamingQuery.remaining(scope, entityTypes, selectFilter, start, xas) /** * Streams states and tombstones as [[Elem]] s without fetching the state value. @@ -204,7 +204,7 @@ final class ElemStreaming( private def stateEntityFilter(scope: Scope, offset: Offset, selectFilter: SelectFilter) = Fragments.whereAndOpt( - entityTypeFilter, + entityTypeFilter(entityTypes), stateFilter(scope, offset, selectFilter) ) @@ -213,16 +213,13 @@ final class ElemStreaming( selectFilter.types.asRestrictedTo.map(includedTypes => fr"cause -> 'types' ??| ${typesSqlArray(includedTypes)}") val causeFragment = Fragments.orOpt(Some(fr"cause->>'deleted' = 'true'"), typeFragment) Fragments.whereAndOpt( - entityTypeFilter, + entityTypeFilter(entityTypes), scope.asFragment, offset.asFragment, selectFilter.tag.asFragment, causeFragment ) } - - private def entityTypeFilter = entityTypes.map { e => Fragments.in(fr"type", e) } - } object ElemStreaming { diff --git a/delta/sourcing-psql/src/main/scala/ch/epfl/bluebrain/nexus/delta/sourcing/query/StreamingQuery.scala b/delta/sourcing-psql/src/main/scala/ch/epfl/bluebrain/nexus/delta/sourcing/query/StreamingQuery.scala index ca969dc2e9..858dc960b3 100644 --- a/delta/sourcing-psql/src/main/scala/ch/epfl/bluebrain/nexus/delta/sourcing/query/StreamingQuery.scala +++ b/delta/sourcing-psql/src/main/scala/ch/epfl/bluebrain/nexus/delta/sourcing/query/StreamingQuery.scala @@ -1,10 +1,11 @@ package ch.epfl.bluebrain.nexus.delta.sourcing.query +import cats.data.NonEmptyList import cats.effect.IO import ch.epfl.bluebrain.nexus.delta.kernel.Logger import ch.epfl.bluebrain.nexus.delta.sourcing.{Scope, Transactors} import ch.epfl.bluebrain.nexus.delta.sourcing.implicits._ -import ch.epfl.bluebrain.nexus.delta.sourcing.model.IriFilter +import ch.epfl.bluebrain.nexus.delta.sourcing.model.{EntityType, IriFilter} import ch.epfl.bluebrain.nexus.delta.sourcing.offset.Offset import ch.epfl.bluebrain.nexus.delta.sourcing.stream.RemainingElems import doobie.Fragments @@ -35,11 +36,15 @@ object StreamingQuery { */ def remaining( scope: Scope, + entityTypes: Option[NonEmptyList[EntityType]], selectFilter: SelectFilter, start: Offset, xas: Transactors ): IO[Option[RemainingElems]] = { - val whereClause = Fragments.whereAndOpt(stateFilter(scope, start, selectFilter)) + val whereClause = Fragments.whereAndOpt( + entityTypeFilter(entityTypes), + stateFilter(scope, start, selectFilter) + ) sql"""SELECT count(ordering), max(instant) |FROM public.scoped_states |$whereClause @@ -100,7 +105,7 @@ object StreamingQuery { logger.debug(s"Reached the end of the single evaluation of query '${query.sql}'.") } - def stateFilter(scope: Scope, offset: Offset, selectFilter: SelectFilter) = { + def stateFilter(scope: Scope, offset: Offset, selectFilter: SelectFilter): Option[doobie.Fragment] = { val typeFragment = selectFilter.types.asRestrictedTo.map(restriction => fr"value -> 'types' ??| ${typesSqlArray(restriction)}") Fragments.andOpt( @@ -111,6 +116,10 @@ object StreamingQuery { ) } + def entityTypeFilter(entityTypes: Option[NonEmptyList[EntityType]]): Option[doobie.Fragment] = entityTypes.map { e => + Fragments.in(fr"type", e) + } + def typesSqlArray(includedTypes: IriFilter.Include): Fragment = Fragment.const(s"ARRAY[${includedTypes.iris.map(t => s"'$t'").mkString(",")}]") diff --git a/delta/sourcing-psql/src/test/scala/ch/epfl/bluebrain/nexus/delta/sourcing/query/ElemStreamingSuite.scala b/delta/sourcing-psql/src/test/scala/ch/epfl/bluebrain/nexus/delta/sourcing/query/ElemStreamingSuite.scala index fa255c9e9a..ca67dc8506 100644 --- a/delta/sourcing-psql/src/test/scala/ch/epfl/bluebrain/nexus/delta/sourcing/query/ElemStreamingSuite.scala +++ b/delta/sourcing-psql/src/test/scala/ch/epfl/bluebrain/nexus/delta/sourcing/query/ElemStreamingSuite.scala @@ -37,11 +37,8 @@ class ElemStreamingSuite extends NexusSuite with Doobie.Fixture { private val qc = QueryConfig(2, RefreshStrategy.Stop) private lazy val xas = doobie() - private lazy val elemStreaming = ElemStreaming.stopping( - xas, - Some(NonEmptyList.of(PullRequest.entityType, Release.entityType)), - 2 - ) + private val entityTypes = Some(NonEmptyList.of(PullRequest.entityType, Release.entityType)) + private lazy val elemStreaming = ElemStreaming.stopping(xas, entityTypes, 2) private lazy val prStore = ScopedStateStore[Iri, PullRequestState]( PullRequest.entityType, @@ -219,38 +216,29 @@ class ElemStreamingSuite extends NexusSuite with Doobie.Fixture { } test("Get the remaining elems for project 1 on latest from the beginning") { - StreamingQuery - .remaining(Scope(project1), SelectFilter.latest, Offset.start, xas) - .assertEquals( - Some( - RemainingElems(6L, epoch) - ) - ) + val expected = Some(RemainingElems(6L, epoch)) + elemStreaming + .remaining(Scope(project1), SelectFilter.latest, Offset.start) + .assertEquals(expected) } test("Get the remaining elems for project 1 on latest from offset 6") { - StreamingQuery - .remaining(Scope(project1), SelectFilter.latest, Offset.at(6L), xas) - .assertEquals( - Some( - RemainingElems(3L, epoch) - ) - ) + val expected = Some(RemainingElems(3L, epoch)) + elemStreaming + .remaining(Scope(project1), SelectFilter.latest, Offset.at(6L)) + .assertEquals(expected) } test(s"Get the remaining elems for project 1 on tag $customTag from the beginning") { - StreamingQuery - .remaining(Scope(project1), SelectFilter.tag(customTag), Offset.at(6L), xas) - .assertEquals( - Some( - RemainingElems(4L, epoch) - ) - ) + val expected = Some(RemainingElems(4L, epoch)) + elemStreaming + .remaining(Scope(project1), SelectFilter.tag(customTag), Offset.at(6L)) + .assertEquals(expected) } test(s"Get no remaining for an unknown project") { - StreamingQuery - .remaining(Scope(ProjectRef.unsafe("xxx", "xxx")), SelectFilter.latest, Offset.at(6L), xas) + elemStreaming + .remaining(Scope(ProjectRef.unsafe("xxx", "xxx")), SelectFilter.latest, Offset.at(6L)) .assertEquals(None) } } diff --git a/delta/sourcing-psql/src/test/scala/ch/epfl/bluebrain/nexus/delta/sourcing/stream/SupervisorSetup.scala b/delta/sourcing-psql/src/test/scala/ch/epfl/bluebrain/nexus/delta/sourcing/stream/SupervisorSetup.scala index 6f95404e39..6e2d0d4d19 100644 --- a/delta/sourcing-psql/src/test/scala/ch/epfl/bluebrain/nexus/delta/sourcing/stream/SupervisorSetup.scala +++ b/delta/sourcing-psql/src/test/scala/ch/epfl/bluebrain/nexus/delta/sourcing/stream/SupervisorSetup.scala @@ -45,7 +45,7 @@ object SupervisorSetup { clock: Clock[IO] ): Resource[IO, SupervisorSetup] = Doobie.resource().flatMap { xas => - val projections = Projections(xas, config.query, clock) + val projections = Projections(xas, None, config.query, clock) val projectionErrors = ProjectionErrors(xas, config.query, clock) Supervisor(projections, projectionErrors, config).map(s => SupervisorSetup(s, projections, projectionErrors)) } diff --git a/tests/src/test/resources/kg/aggregations/org-aggregation.json b/tests/src/test/resources/kg/aggregations/org-aggregation.json index 64aff8bddd..7d68a5e4a6 100644 --- a/tests/src/test/resources/kg/aggregations/org-aggregation.json +++ b/tests/src/test/resources/kg/aggregations/org-aggregation.json @@ -1,42 +1,29 @@ { - "@context" : "https://bluebrain.github.io/nexus/contexts/aggregations.json", - "aggregations" : { - "projects" : { - "buckets" : [ + "aggregations": { + "projects": { + "buckets": [ { - "doc_count" : 4, - "key" : "{{org1}}/{{proj11}}" + "doc_count": 2, + "key": "{{org1}}/{{proj11}}" }, { - "doc_count" : 3, - "key" : "{{org1}}/{{proj12}}" + "doc_count": 1, + "key": "{{org1}}/{{proj12}}" } ], - "doc_count_error_upper_bound" : 0, - "sum_other_doc_count" : 0 + "doc_count_error_upper_bound": 0, + "sum_other_doc_count": 0 }, - "types" : { - "buckets" : [ + "types": { + "buckets": [ { - "doc_count" : 4, - "key" : "https://bluebrain.github.io/nexus/vocabulary/View" - }, - { - "doc_count" : 3, - "key" : "http://schema.org/TestResource" - }, - { - "doc_count" : 2, - "key" : "https://bluebrain.github.io/nexus/vocabulary/CompositeView" - }, - { - "doc_count" : 2, - "key" : "https://bluebrain.github.io/nexus/vocabulary/SparqlView" + "doc_count": 3, + "key": "http://schema.org/TestResource" } ], - "doc_count_error_upper_bound" : 0, - "sum_other_doc_count" : 0 + "doc_count_error_upper_bound": 0, + "sum_other_doc_count": 0 } }, - "total" : 7 + "total": 3 } \ No newline at end of file diff --git a/tests/src/test/resources/kg/aggregations/project-aggregation.json b/tests/src/test/resources/kg/aggregations/project-aggregation.json index e77a82ed15..3e7b714511 100644 --- a/tests/src/test/resources/kg/aggregations/project-aggregation.json +++ b/tests/src/test/resources/kg/aggregations/project-aggregation.json @@ -1,36 +1,25 @@ { - "@context" : "https://bluebrain.github.io/nexus/contexts/aggregations.json", - "aggregations" : { - "projects" : { - "buckets" : { - "doc_count" : 4, - "key" : "{{org}}/{{project}}" - }, - "doc_count_error_upper_bound" : 0, - "sum_other_doc_count" : 0 - }, - "types" : { - "buckets" : [ - { - "doc_count" : 2, - "key" : "https://bluebrain.github.io/nexus/vocabulary/View" - }, - { - "doc_count" : 2, - "key" : "http://schema.org/TestResource" - }, + "aggregations": { + "projects": { + "buckets": [ { - "doc_count" : 1, - "key" : "https://bluebrain.github.io/nexus/vocabulary/CompositeView" - }, + "doc_count": 2, + "key": "{{org}}/{{project}}" + } + ], + "doc_count_error_upper_bound": 0, + "sum_other_doc_count": 0 + }, + "types": { + "buckets": [ { - "doc_count" : 1, - "key" : "https://bluebrain.github.io/nexus/vocabulary/SparqlView" + "doc_count": 2, + "key": "http://schema.org/TestResource" } ], - "doc_count_error_upper_bound" : 0, - "sum_other_doc_count" : 0 + "doc_count_error_upper_bound": 0, + "sum_other_doc_count": 0 } }, - "total" : 4 + "total": 2 } \ No newline at end of file diff --git a/tests/src/test/resources/kg/aggregations/root-aggregation.json b/tests/src/test/resources/kg/aggregations/root-aggregation.json index c2847c9f60..dd95e3fadc 100644 --- a/tests/src/test/resources/kg/aggregations/root-aggregation.json +++ b/tests/src/test/resources/kg/aggregations/root-aggregation.json @@ -1,18 +1,17 @@ { - "@context" : "https://bluebrain.github.io/nexus/contexts/aggregations.json", "aggregations" : { "projects" : { "buckets" : [ { - "doc_count" : 4, + "doc_count" : 2, "key" : "{{org1}}/{{proj11}}" }, { - "doc_count" : 3, + "doc_count" : 1, "key" : "{{org1}}/{{proj12}}" }, { - "doc_count" : 3, + "doc_count" : 1, "key" : "{{org2}}/{{proj21}}" } ], @@ -21,26 +20,14 @@ }, "types" : { "buckets" : [ - { - "doc_count" : 6, - "key" : "https://bluebrain.github.io/nexus/vocabulary/View" - }, { "doc_count" : 4, "key" : "http://schema.org/TestResource" - }, - { - "doc_count" : 3, - "key" : "https://bluebrain.github.io/nexus/vocabulary/CompositeView" - }, - { - "doc_count" : 3, - "key" : "https://bluebrain.github.io/nexus/vocabulary/SparqlView" } ], "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0 } }, - "total" : 10 + "total" : 4 } \ No newline at end of file diff --git a/tests/src/test/resources/kg/aggregations/views-aggregation.json b/tests/src/test/resources/kg/aggregations/views-aggregation.json deleted file mode 100644 index 2966633523..0000000000 --- a/tests/src/test/resources/kg/aggregations/views-aggregation.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "@context": "https://bluebrain.github.io/nexus/contexts/aggregations.json", - "aggregations": { - "projects": { - "buckets": { - "doc_count": 2, - "key": "{{org}}/{{project}}" - }, - "doc_count_error_upper_bound": 0, - "sum_other_doc_count": 0 - }, - "types": { - "buckets": [ - { - "doc_count": 1, - "key": "https://bluebrain.github.io/nexus/vocabulary/CompositeView" - }, - { - "doc_count": 2, - "key": "https://bluebrain.github.io/nexus/vocabulary/View" - }, - { - "doc_count": 1, - "key": "https://bluebrain.github.io/nexus/vocabulary/SparqlView" - } - ], - "doc_count_error_upper_bound": 0, - "sum_other_doc_count": 0 - } - }, - "total": 2 -} \ No newline at end of file diff --git a/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/AggregationsSpec.scala b/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/AggregationsSpec.scala index ab2dc1adea..1db259e385 100644 --- a/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/AggregationsSpec.scala +++ b/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/AggregationsSpec.scala @@ -66,18 +66,6 @@ final class AggregationsSpec extends BaseIntegrationSpec { json should equalIgnoreArrayOrder(expected) } } - - "aggregate views" in { - val expected = jsonContentOf( - "kg/aggregations/views-aggregation.json", - "org" -> org1, - "project" -> proj11 - ) - deltaClient.get[Json](s"/views/$ref11?aggregations=true", Charlie) { (json, response) => - response.status shouldEqual StatusCodes.OK - json should equalIgnoreArrayOrder(expected) - } - } } "Aggregating resources within an org" should { diff --git a/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/CompositeViewsSpec.scala b/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/CompositeViewsSpec.scala index 80a59ec0d4..97baaa3cc5 100644 --- a/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/CompositeViewsSpec.scala +++ b/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/CompositeViewsSpec.scala @@ -61,27 +61,6 @@ class CompositeViewsSpec extends BaseIntegrationSpec { } yield succeed setup.accepted - - // wait until in project resolver is created - eventually { - deltaClient.get[Json](s"/resolvers/$orgId/$bandsProject", Jerry) { (json, response) => - response.status shouldEqual StatusCodes.OK - _total.getOption(json).value shouldEqual 1 - } - } - eventually { - deltaClient.get[Json](s"/resolvers/$orgId/$albumsProject", Jerry) { (json, response) => - response.status shouldEqual StatusCodes.OK - _total.getOption(json).value shouldEqual 1 - } - } - eventually { - deltaClient.get[Json](s"/resolvers/$orgId/$songsProject", Jerry) { (json, response) => - response.status shouldEqual StatusCodes.OK - _total.getOption(json).value shouldEqual 1 - } - } - () } @@ -89,9 +68,7 @@ class CompositeViewsSpec extends BaseIntegrationSpec { "upload context" in { val context = jsonContentOf("kg/views/composite/context.json") List(songsProject, albumsProject, bandsProject).parTraverse { projectId => - deltaClient.post[Json](s"/resources/$orgId/$projectId", context, Jerry) { (_, response) => - response.status shouldEqual StatusCodes.Created - } + deltaClient.post[Json](s"/resources/$orgId/$projectId", context, Jerry) { expectCreated } } } @@ -101,9 +78,7 @@ class CompositeViewsSpec extends BaseIntegrationSpec { jsonContentOf("kg/views/composite/songs1.json") ) .parTraverse { song => - deltaClient.post[Json](s"/resources/$orgId/$songsProject", song, Jerry) { (_, response) => - response.status shouldEqual StatusCodes.Created - } + deltaClient.post[Json](s"/resources/$orgId/$songsProject", song, Jerry) { expectCreated } } } @@ -113,9 +88,7 @@ class CompositeViewsSpec extends BaseIntegrationSpec { jsonContentOf("kg/views/composite/albums.json") ) .parTraverse { album => - deltaClient.post[Json](s"/resources/$orgId/$albumsProject", album, Jerry) { (_, response) => - response.status shouldEqual StatusCodes.Created - } + deltaClient.post[Json](s"/resources/$orgId/$albumsProject", album, Jerry) { expectCreated } } } @@ -125,9 +98,7 @@ class CompositeViewsSpec extends BaseIntegrationSpec { jsonContentOf("kg/views/composite/bands.json") ) .parTraverse { band => - deltaClient.post[Json](s"/resources/$orgId/$bandsProject", band, Jerry) { (_, response) => - response.status shouldEqual StatusCodes.Created - } + deltaClient.post[Json](s"/resources/$orgId/$bandsProject", band, Jerry) { expectCreated } } } } @@ -172,9 +143,7 @@ class CompositeViewsSpec extends BaseIntegrationSpec { ): _* ) - deltaClient.put[Json](s"/views/$orgId/bands/composite2", view, Jerry) { (_, response) => - response.status shouldEqual StatusCodes.BadRequest - } + deltaClient.put[Json](s"/views/$orgId/bands/composite2", view, Jerry) { expectBadRequest } } "reject creating a composite view with remote source endpoint with a wrong hostname" in { @@ -190,9 +159,7 @@ class CompositeViewsSpec extends BaseIntegrationSpec { ): _* ) - deltaClient.put[Json](s"/views/$orgId/bands/composite2", view, Jerry) { (_, response) => - response.status shouldEqual StatusCodes.BadRequest - } + deltaClient.put[Json](s"/views/$orgId/bands/composite2", view, Jerry) { expectBadRequest } } } @@ -242,9 +209,7 @@ class CompositeViewsSpec extends BaseIntegrationSpec { jsonContentOf("kg/views/composite/songs2.json") ) .parTraverse { song => - deltaClient.post[Json](s"/resources/$orgId/$songsProject", song, Jerry) { (_, response) => - response.status shouldEqual StatusCodes.Created - } + deltaClient.post[Json](s"/resources/$orgId/$songsProject", song, Jerry) { expectCreated } } } } diff --git a/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/DefaultIndexSpec.scala b/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/DefaultIndexSpec.scala index dc9277c841..f2fc40a2bd 100644 --- a/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/DefaultIndexSpec.scala +++ b/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/DefaultIndexSpec.scala @@ -3,10 +3,12 @@ package ch.epfl.bluebrain.nexus.tests.kg import akka.http.scaladsl.model.StatusCodes import ch.epfl.bluebrain.nexus.delta.kernel.utils.UrlUtils import ch.epfl.bluebrain.nexus.tests.BaseIntegrationSpec +import ch.epfl.bluebrain.nexus.tests.Identity.aggregations.Charlie import ch.epfl.bluebrain.nexus.tests.Identity.listings.{Alice, Bob} import ch.epfl.bluebrain.nexus.tests.Optics.{filterNestedKeys, hitProjects} import ch.epfl.bluebrain.nexus.tests.admin.ProjectPayload import ch.epfl.bluebrain.nexus.tests.iam.types.Permission.Organizations +import ch.epfl.bluebrain.nexus.tests.resources.SimpleResource import io.circe.Json class DefaultIndexSpec extends BaseIntegrationSpec { @@ -15,16 +17,22 @@ class DefaultIndexSpec extends BaseIntegrationSpec { private val proj11 = genId() private val proj12 = genId() private val ref11 = s"$org1/$proj11" + private val ref12 = s"$org1/$proj12" override def beforeAll(): Unit = { super.beforeAll() val setup = for { - _ <- aclDsl.addPermission("/", Bob, Organizations.Create) + _ <- aclDsl.addPermission("/", Bob, Organizations.Create) // First org and projects - _ <- adminDsl.createOrganization(org1, org1, Bob) - _ <- adminDsl.createProject(org1, proj11, ProjectPayload.generate(proj11), Bob) - _ <- adminDsl.createProject(org1, proj12, ProjectPayload.generate(proj12), Bob) + _ <- adminDsl.createOrganization(org1, org1, Bob) + _ <- adminDsl.createProject(org1, proj11, ProjectPayload.generate(proj11), Bob) + _ <- adminDsl.createProject(org1, proj12, ProjectPayload.generate(proj12), Bob) + resourcePayload <- SimpleResource.sourcePayload(5) + _ <- deltaClient.put[Json](s"/resources/$ref11/_/r11_1", resourcePayload, Bob)(expectCreated) + _ <- deltaClient.put[Json](s"/resources/$ref11/_/r11_2", resourcePayload, Bob)(expectCreated) + _ <- deltaClient.put[Json](s"/resources/$ref12/_/r12_1", resourcePayload, Bob)(expectCreated) + _ <- deltaClient.put[Json](s"/resources/$ref12/_/r12_2", resourcePayload, Bob)(expectCreated) } yield () setup.accepted } diff --git a/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/ElasticSearchViewsSpec.scala b/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/ElasticSearchViewsSpec.scala index 694646ab5b..0cf57ace17 100644 --- a/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/ElasticSearchViewsSpec.scala +++ b/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/ElasticSearchViewsSpec.scala @@ -184,13 +184,6 @@ class ElasticSearchViewsSpec extends BaseIntegrationSpec { } } - "wait until in project view is indexed" in eventually { - deltaClient.get[Json](s"/views/$project1?type=nxv%3AElasticSearchView", ScoobyDoo) { (json, response) => - _total.getOption(json).value shouldEqual 2 - response.status shouldEqual StatusCodes.OK - } - } - "wait until all instances are indexed in default view of project 2" in eventually { deltaClient.get[Json](s"/resources/$project2/resource", ScoobyDoo) { (json, response) => response.status shouldEqual StatusCodes.OK diff --git a/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/EventsSpec.scala b/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/EventsSpec.scala index 14b13f2ea9..02208f3502 100644 --- a/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/EventsSpec.scala +++ b/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/EventsSpec.scala @@ -69,10 +69,9 @@ class EventsSpec extends BaseIntegrationSpec { } "fetch resource events filtered by project" in eventually { - deltaClient.sseEvents(s"/resources/$id/events", BugsBunny, initialEventId, take = 12L) { seq => - val projectEvents = seq.drop(2) - projectEvents.size shouldEqual 6 - projectEvents.flatMap(_._1) should contain theSameElementsInOrderAs List( + deltaClient.sseEvents(s"/resources/$id/events", BugsBunny, initialEventId, take = 12L) { sses => + sses.size shouldEqual 6 + sses.flatMap(_._1) should contain theSameElementsInOrderAs List( "ResourceCreated", "ResourceUpdated", "ResourceTagAdded", @@ -80,16 +79,15 @@ class EventsSpec extends BaseIntegrationSpec { "FileCreated", "FileUpdated" ) - val json = Json.arr(projectEvents.flatMap(_._2.map(events.filterFields)): _*) + val json = Json.arr(sses.flatMap(_._2.map(events.filterFields)): _*) json shouldEqual expectedEvents("kg/events/events.json", orgId, projId) } } "fetch resource events filtered by organization 1" in { - deltaClient.sseEvents(s"/resources/$orgId/events", BugsBunny, initialEventId, take = 12L) { seq => - val projectEvents = seq.drop(2) - projectEvents.size shouldEqual 6 - projectEvents.flatMap(_._1) should contain theSameElementsInOrderAs List( + deltaClient.sseEvents(s"/resources/$orgId/events", BugsBunny, initialEventId, take = 12L) { sses => + sses.size shouldEqual 6 + sses.flatMap(_._1) should contain theSameElementsInOrderAs List( "ResourceCreated", "ResourceUpdated", "ResourceTagAdded", @@ -97,17 +95,16 @@ class EventsSpec extends BaseIntegrationSpec { "FileCreated", "FileUpdated" ) - val json = Json.arr(projectEvents.flatMap(_._2.map(events.filterFields)): _*) + val json = Json.arr(sses.flatMap(_._2.map(events.filterFields)): _*) json shouldEqual expectedEvents("kg/events/events.json", orgId, projId) } } "fetch resource events filtered by organization 2" in { - deltaClient.sseEvents(s"/resources/$orgId2/events", BugsBunny, initialEventId, take = 7L) { seq => - val projectEvents = seq.drop(2) - projectEvents.size shouldEqual 1 - projectEvents.flatMap(_._1) should contain theSameElementsInOrderAs List("ResourceCreated") - val json = Json.arr(projectEvents.flatMap(_._2.map(events.filterFields)): _*) + deltaClient.sseEvents(s"/resources/$orgId2/events", BugsBunny, initialEventId, take = 7L) { sses => + sses.size shouldEqual 1 + sses.flatMap(_._1) should contain theSameElementsInOrderAs List("ResourceCreated") + val json = Json.arr(sses.flatMap(_._2.map(events.filterFields)): _*) json shouldEqual expectedEvents("kg/events/events2.json", orgId2, projId) } } diff --git a/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/ListingsSpec.scala b/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/ListingsSpec.scala index dd02fe68bd..2e9f218993 100644 --- a/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/ListingsSpec.scala +++ b/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/ListingsSpec.scala @@ -108,7 +108,7 @@ final class ListingsSpec extends BaseIntegrationSpec { } } - "get default views" in { + "get default views" ignore { val defaultSparqlView = "https://bluebrain.github.io/nexus/vocabulary/defaultSparqlIndex" val searchView = "https://bluebrain.github.io/nexus/vocabulary/searchView" diff --git a/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/ProjectsDeletionSpec.scala b/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/ProjectsDeletionSpec.scala index 98442d6ece..d62a8f4fc1 100644 --- a/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/ProjectsDeletionSpec.scala +++ b/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/ProjectsDeletionSpec.scala @@ -4,7 +4,7 @@ import akka.http.scaladsl.model.StatusCodes import ch.epfl.bluebrain.nexus.delta.kernel.utils.UrlUtils import ch.epfl.bluebrain.nexus.tests.Identity.projects.{Bojack, PrincessCarolyn} import ch.epfl.bluebrain.nexus.tests.Identity.{Anonymous, ServiceAccount} -import ch.epfl.bluebrain.nexus.tests.Optics.{admin, listing, supervision} +import ch.epfl.bluebrain.nexus.tests.Optics.{_uuid, admin, listing, supervision} import ch.epfl.bluebrain.nexus.tests.iam.types.Permission.{Events, Organizations, Projects, Resources} import ch.epfl.bluebrain.nexus.tests.kg.files.model.FileInput import ch.epfl.bluebrain.nexus.tests.resources.SimpleResource @@ -25,12 +25,12 @@ final class ProjectsDeletionSpec extends BaseIntegrationSpec { private val ref1Iri = s"${config.deltaUri}/projects/$ref1" - private val elasticsearchViewId = "http://localhost/nexus/default-view" - private val encodedElasticsearchViewId = UrlUtils.encode(elasticsearchViewId) + private val elasticId = "http://localhost/nexus/custom-view" + private val encodedElasticId = UrlUtils.encode(elasticId) - private var elasticsearchViewsRef1Uuids = List.empty[String] - private var blazegraphViewsRef1Uuids = List.empty[String] - private var compositeViewsRef1Uuids = List.empty[String] + private var elasticsearchViewToDeleteUuid: Option[String] = None + private var blazegraphViewToDeleteUuid: Option[String] = None + private var compositeViewToDeleteUuid: Option[String] = None private def graphAnalyticsIndex(org: String, project: String) = s"delta_ga_${org}_$project" @@ -45,50 +45,38 @@ final class ProjectsDeletionSpec extends BaseIntegrationSpec { _ <- adminDsl.createProjectWithName(org, proj2, name = proj2, Bojack) _ <- aclDsl.addPermission(s"/$ref1", PrincessCarolyn, Resources.Read) esViewPayload = jsonContentOf("kg/views/elasticsearch/pipeline.json", "withTag" -> false) - _ <- deltaClient.put[Json](s"/views/$ref1/$encodedElasticsearchViewId", esViewPayload, Bojack) { expectCreated } - _ <- deltaClient.put[Json](s"/views/$ref2/$encodedElasticsearchViewId", esViewPayload, Bojack) { expectCreated } + _ <- deltaClient.put[Json](s"/views/$ref1/$encodedElasticId", esViewPayload, Bojack) { expectCreated } + _ <- deltaClient.put[Json](s"/views/$ref2/$encodedElasticId", esViewPayload, Bojack) { expectCreated } } yield succeed } - s"have resources for $ref1" in eventually { - deltaClient.get[Json](s"/resources/$ref1", Bojack) { (json, _) => - listing._total.getOption(json).value should be > 0L - } - } - "wait for elasticsearch views to be created" in eventually { for { - uuids <- deltaClient - .getJson[Json](s"/views/$ref1?type=nxv:ElasticSearchView", Bojack) - .map(listing.eachResult._uuid.string.getAll(_)) + uuids <- deltaClient.getJson[Json](s"/views/$ref1/$encodedElasticId", Bojack).map(_uuid.getOption) indices <- elasticsearchDsl.allIndices } yield { uuids should not be empty uuids.forall { uuid => indices.exists(_.contains(uuid)) } shouldEqual true - elasticsearchViewsRef1Uuids = uuids + elasticsearchViewToDeleteUuid = uuids succeed } } "wait for blazegraph views to be created" in eventually { for { - uuids <- deltaClient - .getJson[Json](s"/views/$ref1?type=nxv:SparqlView", Bojack) - .map(listing.eachResult._uuid.string.getAll(_)) + uuids <- deltaClient.getJson[Json](s"/views/$ref1/graph", Bojack).map(_uuid.getOption) namespaces <- blazegraphDsl.allNamespaces } yield { uuids should not be empty uuids.forall { uuid => namespaces.exists(_.contains(uuid)) } shouldEqual true - blazegraphViewsRef1Uuids = uuids + blazegraphViewToDeleteUuid = uuids succeed } } "wait for composite views to be created" in eventually { for { - uuids <- deltaClient - .getJson[Json](s"/views/$ref1?type=nxv:CompositeView", Bojack) - .map(listing.eachResult._uuid.string.getAll(_)) + uuids <- deltaClient.getJson[Json](s"/views/$ref1/search", Bojack).map(_uuid.getOption) indices <- elasticsearchDsl.allIndices namespaces <- blazegraphDsl.allNamespaces } yield { @@ -96,7 +84,7 @@ final class ProjectsDeletionSpec extends BaseIntegrationSpec { uuids.forall { uuid => namespaces.exists(_.contains(uuid)) && indices.exists(_.contains(uuid)) } shouldEqual true - compositeViewsRef1Uuids = uuids + compositeViewToDeleteUuid = uuids succeed } } @@ -129,8 +117,8 @@ final class ProjectsDeletionSpec extends BaseIntegrationSpec { "esAggView", ref1, Bojack, - ref1 -> elasticsearchViewId, - ref2 -> elasticsearchViewId + ref1 -> elasticId, + ref2 -> elasticId ) _ <- deltaClient.uploadFile(ref1, None, FileInput.randomTextFile, None)(expectCreated) _ <- deltaClient.uploadFile(ref2, None, FileInput.randomTextFile, None)(expectCreated) @@ -227,25 +215,25 @@ final class ProjectsDeletionSpec extends BaseIntegrationSpec { "have deleted elasticsearch indices for es views for the project" in { elasticsearchDsl.allIndices.map { indices => - elasticsearchViewsRef1Uuids.forall { uuid => indices.exists(_.contains(uuid)) } shouldEqual false + elasticsearchViewToDeleteUuid.forall { uuid => indices.exists(_.contains(uuid)) } shouldEqual false } } "have deleted blazegraph namespaces for blazegraph views for the project" in { blazegraphDsl.allNamespaces.map { namespaces => - blazegraphViewsRef1Uuids.forall { uuid => namespaces.exists(_.contains(uuid)) } shouldEqual false + blazegraphViewToDeleteUuid.forall { uuid => namespaces.exists(_.contains(uuid)) } shouldEqual false } } "have deleted elasticsearch indices and blazegraph namespaces for composite views for the project" in { for { _ <- elasticsearchDsl.allIndices.map { indices => - compositeViewsRef1Uuids.forall { uuid => + compositeViewToDeleteUuid.forall { uuid => indices.exists(_.contains(uuid)) } shouldEqual false } _ <- blazegraphDsl.allNamespaces.map { namespaces => - compositeViewsRef1Uuids.forall { uuid => namespaces.exists(_.contains(uuid)) } shouldEqual false + compositeViewToDeleteUuid.forall { uuid => namespaces.exists(_.contains(uuid)) } shouldEqual false } } yield succeed } diff --git a/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/SparqlViewsSpec.scala b/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/SparqlViewsSpec.scala index 8bce7c59e9..110304a534 100644 --- a/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/SparqlViewsSpec.scala +++ b/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/SparqlViewsSpec.scala @@ -133,13 +133,6 @@ class SparqlViewsSpec extends BaseIntegrationSpec { } } - "wait until in project view is indexed" in eventually { - deltaClient.get[Json](s"/views/$project1?type=nxv%3ASparqlView", ScoobyDoo) { (json, response) => - _total.getOption(json).value shouldEqual 2 - response.status shouldEqual StatusCodes.OK - } - } - "wait until all instances are indexed in default view of project 2" in eventually { deltaClient.get[Json](s"/resources/$project2/resource", ScoobyDoo) { (json, response) => response.status shouldEqual StatusCodes.OK @@ -213,9 +206,9 @@ class SparqlViewsSpec extends BaseIntegrationSpec { response.status shouldEqual StatusCodes.OK val expected = jsonContentOf( "kg/views/statistics.json", - "total" -> "9", - "processed" -> "9", - "evaluated" -> "9", + "total" -> "6", + "processed" -> "6", + "evaluated" -> "6", "discarded" -> "0", "remaining" -> "0" ) diff --git a/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/plugins/blazegraph/IncomingOutgoingBlazegraphSpec.scala b/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/plugins/blazegraph/IncomingOutgoingBlazegraphSpec.scala index 31dee21a38..24ce285696 100644 --- a/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/plugins/blazegraph/IncomingOutgoingBlazegraphSpec.scala +++ b/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/plugins/blazegraph/IncomingOutgoingBlazegraphSpec.scala @@ -81,7 +81,7 @@ class IncomingOutgoingBlazegraphSpec extends BaseIntegrationSpec { eventually { deltaClient.get[Json](s"/views/$orgLabel/$projLabel/graph/statistics", Radar) { (json, response) => response.status shouldEqual StatusCodes.OK - root.processedEvents.long.getOption(json).value shouldEqual 4L + root.processedEvents.long.getOption(json).value shouldEqual 2L } } }