From 2a34e247b6e9385f2ca541ce4afde1e763c55d4d Mon Sep 17 00:00:00 2001 From: Oliver <20188437+olivergrabinski@users.noreply.github.com> Date: Thu, 21 Dec 2023 18:28:56 +0100 Subject: [PATCH] Correctly decode context in an ES view value (#4617) --- .../ElasticSearchViewJsonLdSourceDecoder.scala | 1 + .../ElasticSearchViewDecodingSpec.scala | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchViewJsonLdSourceDecoder.scala b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchViewJsonLdSourceDecoder.scala index 815899a42a..6d5fccbce5 100644 --- a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchViewJsonLdSourceDecoder.scala +++ b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchViewJsonLdSourceDecoder.scala @@ -61,6 +61,7 @@ class ElasticSearchViewJsonLdSourceDecoder private ( private def mapJsonToString(json: Json): Json = json .mapAllKeys("mapping", _.noSpaces.asJson) .mapAllKeys("settings", _.noSpaces.asJson) + .mapAllKeys("context", _.noSpaces.asJson) } object ElasticSearchViewJsonLdSourceDecoder { diff --git a/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchViewDecodingSpec.scala b/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchViewDecodingSpec.scala index a5636dc13b..a2377428c9 100644 --- a/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchViewDecodingSpec.scala +++ b/delta/plugins/elasticsearch/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchViewDecodingSpec.scala @@ -7,6 +7,7 @@ import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.model.ElasticSearchVi import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.model.ElasticSearchViewValue.{AggregateElasticSearchViewValue, IndexingElasticSearchViewValue} import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.model.permissions import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary.schemas +import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.ContextValue.ContextObject import ch.epfl.bluebrain.nexus.delta.rdf.syntax.iriStringContextSyntax import ch.epfl.bluebrain.nexus.delta.sdk.identities.model.Caller import ch.epfl.bluebrain.nexus.delta.sdk.permissions.model.Permission @@ -17,7 +18,9 @@ import ch.epfl.bluebrain.nexus.delta.sourcing.model.Tag.UserTag import ch.epfl.bluebrain.nexus.delta.sourcing.model.{Label, ProjectRef} import ch.epfl.bluebrain.nexus.delta.sourcing.stream.pipes._ import ch.epfl.bluebrain.nexus.testkit.scalatest.ce.CatsEffectSpec +import io.circe.JsonObject import io.circe.literal._ +import io.circe.syntax.KeyOps import java.util.UUID @@ -62,6 +65,21 @@ class ElasticSearchViewDecodingSpec extends CatsEffectSpec with Fixtures { id.toString should startWith(context.base.iri.toString) } + "it has a context" in { + val additionalContext = + JsonObject("description" := "http://schema.org/description") + val sourceWithAdditionalContext = + json"""{ + "@type": "ElasticSearchView", + "mapping": $mapping, + "context": $additionalContext, + "pipeline": [{"name": "filterDeprecated"}] + }""" + + val (_, value) = decoder(ref, context, sourceWithAdditionalContext).accepted + value.asIndexingValue.get.context should contain(ContextObject(additionalContext)) + } + "all legacy fields are specified" in { val source = json"""{