Skip to content

Commit

Permalink
Correctly decode context in an ES view value (#4617)
Browse files Browse the repository at this point in the history
  • Loading branch information
olivergrabinski authored Dec 21, 2023
1 parent 67f54a0 commit 2a34e24
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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"""{
Expand Down

0 comments on commit 2a34e24

Please sign in to comment.