Skip to content

Commit

Permalink
Remove ability to tag SPARQL views (#4691)
Browse files Browse the repository at this point in the history
Co-authored-by: Simon <[email protected]>
  • Loading branch information
dantb and imsdu authored Jan 26, 2024
1 parent a2ba1fc commit a31a2c1
Show file tree
Hide file tree
Showing 21 changed files with 52 additions and 456 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ import ch.epfl.bluebrain.nexus.delta.sdk.model._
import ch.epfl.bluebrain.nexus.delta.sdk.projects.FetchContext
import ch.epfl.bluebrain.nexus.delta.sdk.projects.model.ApiMappings
import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.ResolverContextResolution
import ch.epfl.bluebrain.nexus.delta.sourcing.ScopedEntityDefinition.Tagger
import ch.epfl.bluebrain.nexus.delta.sourcing._
import ch.epfl.bluebrain.nexus.delta.sourcing.config.EventLogConfig
import ch.epfl.bluebrain.nexus.delta.sourcing.model.EntityDependency.DependsOn
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.Subject
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Tag.UserTag
import ch.epfl.bluebrain.nexus.delta.sourcing.model._
import ch.epfl.bluebrain.nexus.delta.sourcing.offset.Offset
import ch.epfl.bluebrain.nexus.delta.sourcing.stream.Elem
Expand Down Expand Up @@ -166,36 +164,6 @@ final class BlazegraphViews(
} yield res
}.span("updateBlazegraphView")

/**
* Add a tag to an existing view.
*
* @param id
* the id of the view
* @param project
* the project to which the view belongs
* @param tag
* the tag label
* @param tagRev
* the target revision of the tag
* @param rev
* the current revision of the view
*/
def tag(
id: IdSegment,
project: ProjectRef,
tag: UserTag,
tagRev: Int,
rev: Int
)(implicit subject: Subject): IO[ViewResource] = {
for {
pc <- fetchContext.onModify(project)
iri <- expandIri(id, pc)
_ <- validateNotDefaultView(iri)
res <- eval(TagBlazegraphView(iri, project, tagRev, tag, rev, subject))
_ <- createNamespace(res)
} yield res
}.span("tagBlazegraphView")

/**
* Deprecate a view.
*
Expand Down Expand Up @@ -281,10 +249,8 @@ final class BlazegraphViews(
notFound = ViewNotFound(iri, project)
state <- id match {
case Latest(_) => log.stateOr(project, iri, notFound)
case Revision(_, rev) =>
log.stateOr(project, iri, rev, notFound, RevisionNotFound)
case Tag(_, tag) =>
log.stateOr(project, iri, tag, notFound, TagNotFound(tag))
case Revision(_, rev) => log.stateOr(project, iri, rev, notFound, RevisionNotFound)
case t: Tag => IO.raiseError(FetchByTagNotSupported(t))
}
} yield state
}.span("fetchBlazegraphView")
Expand Down Expand Up @@ -394,7 +360,6 @@ object BlazegraphViews {
e.uuid,
e.value,
e.source,
Tags.empty,
e.rev,
e.rev,
deprecated = false,
Expand Down Expand Up @@ -422,7 +387,7 @@ object BlazegraphViews {
}

def tagAdded(e: BlazegraphViewTagAdded): Option[BlazegraphViewState] = state.map { s =>
s.copy(rev = e.rev, tags = s.tags + (e.tag -> e.targetRev), updatedAt = e.instant, updatedBy = e.subject)
s.copy(rev = e.rev, updatedAt = e.instant, updatedBy = e.subject)
}

def deprecated(e: BlazegraphViewDeprecated): Option[BlazegraphViewState] = state.map { s =>
Expand Down Expand Up @@ -475,19 +440,6 @@ object BlazegraphViews {
} yield BlazegraphViewUpdated(c.id, c.project, s.uuid, c.value, c.source, s.rev + 1, t, c.subject)
}

def tag(c: TagBlazegraphView) = state match {
case None =>
IO.raiseError(ViewNotFound(c.id, c.project))
case Some(s) if s.rev != c.rev =>
IO.raiseError(IncorrectRev(c.rev, s.rev))
case Some(s) if c.targetRev <= 0 || c.targetRev > s.rev =>
IO.raiseError(RevisionNotFound(c.targetRev, s.rev))
case Some(s) =>
clock.realTimeInstant.map(
BlazegraphViewTagAdded(c.id, c.project, s.value.tpe, s.uuid, c.targetRev, c.tag, s.rev + 1, _, c.subject)
)
}

def deprecate(c: DeprecateBlazegraphView) = state match {
case None =>
IO.raiseError(ViewNotFound(c.id, c.project))
Expand Down Expand Up @@ -517,7 +469,6 @@ object BlazegraphViews {
cmd match {
case c: CreateBlazegraphView => create(c)
case c: UpdateBlazegraphView => update(c)
case c: TagBlazegraphView => tag(c)
case c: DeprecateBlazegraphView => deprecate(c)
case c: UndeprecateBlazegraphView => undeprecate(c)
}
Expand All @@ -530,7 +481,7 @@ object BlazegraphViews {
BlazegraphViewEvent,
BlazegraphViewRejection
] =
ScopedEntityDefinition(
ScopedEntityDefinition.untagged(
entityType,
StateMachine(
None,
Expand All @@ -539,15 +490,6 @@ object BlazegraphViews {
),
BlazegraphViewEvent.serializer,
BlazegraphViewState.serializer,
Tagger[BlazegraphViewEvent](
{
case r: BlazegraphViewTagAdded => Some(r.tag -> r.targetRev)
case _ => None
},
{ _ =>
None
}
),
{ s =>
s.value match {
case a: AggregateBlazegraphViewValue =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ 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, Tags}
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
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{IriFilter, ProjectRef}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Tag.UserTag
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{IriFilter, ProjectRef}
import io.circe.generic.extras.Configuration
import io.circe.generic.extras.semiauto.deriveConfiguredEncoder
import io.circe.syntax._
Expand Down Expand Up @@ -52,12 +52,6 @@ sealed trait BlazegraphView extends Product with Serializable {
*/
def project: ProjectRef

/**
* @return
* the tag -> rev mapping
*/
def tags: Tags

/**
* @return
* the original json document provided at creation or update
Expand Down Expand Up @@ -118,7 +112,6 @@ object BlazegraphView {
includeMetadata: Boolean,
includeDeprecated: Boolean,
permission: Permission,
tags: Tags,
source: Json,
indexingRev: Int
) extends BlazegraphView {
Expand Down Expand Up @@ -147,7 +140,6 @@ object BlazegraphView {
description: Option[String],
project: ProjectRef,
views: NonEmptySet[ViewRef],
tags: Tags,
source: Json
) extends BlazegraphView {
override def metadata: Metadata = Metadata(None, None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model

import ch.epfl.bluebrain.nexus.delta.rdf.IriOrBNode.Iri
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.Subject
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Tag.UserTag
import ch.epfl.bluebrain.nexus.delta.sourcing.model.ProjectRef
import io.circe.Json

Expand Down Expand Up @@ -116,29 +115,4 @@ object BlazegraphViewCommand {
*/
final case class UndeprecateBlazegraphView(id: Iri, project: ProjectRef, rev: Int, subject: Subject)
extends BlazegraphViewCommand

/**
* Command for adding a tag to a Blazegraph view.
*
* @param id
* the view id
* @param project
* a reference to the parent project
* @param targetRev
* the revision that is being aliased with the provided ''tag''
* @param tag
* the tag label
* @param rev
* the last known revision of the view
* @param subject
* the identity associated with this command
*/
final case class TagBlazegraphView(
id: Iri,
project: ProjectRef,
targetRev: Int,
tag: UserTag,
rev: Int,
subject: Subject
) extends BlazegraphViewCommand
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import ch.epfl.bluebrain.nexus.delta.rdf.{RdfError, Vocabulary}
import ch.epfl.bluebrain.nexus.delta.sdk.jsonld.JsonLdRejection
import ch.epfl.bluebrain.nexus.delta.sdk.jsonld.JsonLdRejection.{BlankId, UnexpectedId}
import ch.epfl.bluebrain.nexus.delta.sdk.marshalling.HttpResponseFields
import ch.epfl.bluebrain.nexus.delta.sdk.model.IdSegmentRef
import ch.epfl.bluebrain.nexus.delta.sdk.permissions.model.Permission
import ch.epfl.bluebrain.nexus.delta.sdk.projects.FetchContext.ContextRejection
import ch.epfl.bluebrain.nexus.delta.sdk.views.ViewRef
Expand Down Expand Up @@ -112,6 +113,11 @@ object BlazegraphViewRejection {
s"Incorrect revision '$provided' provided, expected '$expected', the view may have been updated since last seen."
)

final case class FetchByTagNotSupported(tag: IdSegmentRef.Tag)
extends BlazegraphViewRejection(
s"Fetching blazegraph views by tag is no longer supported. Id ${tag.value.asString} and tag ${tag.tag.value}"
)

/**
* Signals a rejection caused when interacting with other APIs when fetching a resource
*/
Expand Down Expand Up @@ -265,6 +271,7 @@ object BlazegraphViewRejection {
case ViewIsDefaultView => StatusCodes.Forbidden
case IncorrectRev(_, _) => StatusCodes.Conflict
case ProjectContextRejection(rej) => rej.status
case _: FetchByTagNotSupported => StatusCodes.BadRequest
case _ => StatusCodes.BadRequest
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.BlazegraphView._
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.BlazegraphViewValue._
import ch.epfl.bluebrain.nexus.delta.rdf.IriOrBNode.Iri
import ch.epfl.bluebrain.nexus.delta.sdk.model.{ResourceF, ResourceUris, Tags}
import ch.epfl.bluebrain.nexus.delta.sdk.model.{ResourceF, ResourceUris}
import ch.epfl.bluebrain.nexus.delta.sourcing.Serializer
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.Subject
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{ProjectRef, ResourceRef}
Expand Down Expand Up @@ -51,7 +51,6 @@ final case class BlazegraphViewState(
uuid: UUID,
value: BlazegraphViewValue,
source: Json,
tags: Tags,
rev: Int,
indexingRev: Int,
deprecated: Boolean,
Expand Down Expand Up @@ -91,12 +90,11 @@ final case class BlazegraphViewState(
includeMetadata,
includeDeprecated,
permission,
tags,
source,
indexingRev
)
case AggregateBlazegraphViewValue(name, description, views) =>
AggregateBlazegraphView(id, name, description, project, views, tags, source)
AggregateBlazegraphView(id, name, description, project, views, source)
}

def toResource: ViewResource =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.routes
import akka.http.scaladsl.model.StatusCodes.Created
import akka.http.scaladsl.server.{Directive0, Route}
import cats.implicits._
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.BlazegraphView._
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.BlazegraphViewRejection._
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model._
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.permissions.{read => Read, write => Write}
Expand All @@ -22,7 +21,6 @@ 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.implicits._
import ch.epfl.bluebrain.nexus.delta.sdk.marshalling.RdfMarshalling
import ch.epfl.bluebrain.nexus.delta.sdk.model.routes.Tag
import ch.epfl.bluebrain.nexus.delta.sdk.model.search.SearchResults._
import ch.epfl.bluebrain.nexus.delta.sdk.model.search.{PaginationConfig, SearchResults}
import ch.epfl.bluebrain.nexus.delta.sdk.model.{BaseUri, IdSegment}
Expand Down Expand Up @@ -168,36 +166,6 @@ class BlazegraphViewsRoutes(
}
)
},
(pathPrefix("tags") & pathEndOrSingleSlash) {
concat(
// Fetch tags for a view
(get & idSegmentRef(id) & authorizeFor(project, Read)) { id =>
emit(
views
.fetch(id, project)
.map(_.value.tags)
.attemptNarrow[BlazegraphViewRejection]
.rejectOn[ViewNotFound]
)
},
// Tag a view
(post & parameter("rev".as[Int])) { rev =>
authorizeFor(project, Write).apply {
entity(as[Tag]) { case Tag(tagRev, tag) =>
emit(
Created,
views
.tag(id, project, tag, tagRev, rev)
.flatTap(index(project, _, mode))
.mapValue(_.metadata)
.attemptNarrow[BlazegraphViewRejection]
.rejectOn[ViewNotFound]
)
}
}
}
)
},
// Fetch a view original source
(pathPrefix("source") & get & pathEndOrSingleSlash & idSegmentRef(id)) { id =>
authorizeFor(project, Read).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
]
},
"uuid": "f8468909-a797-4b10-8b5f-000cba337bfa",
"tags": {
"mytag": 3
},
"createdAt": "1970-01-01T00:00:00Z",
"createdBy": {
"@type": "User",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
"source": {
"elastic": "value"
},
"tags": {
"mytag": 3
},
"updatedAt": "1970-01-01T00:00:00Z",
"updatedBy": {
"@type": "User",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ch.epfl.bluebrain.nexus.delta.plugins.blazegraph

import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.{BlazegraphViewState, BlazegraphViewValue, ViewResource}
import ch.epfl.bluebrain.nexus.delta.rdf.IriOrBNode.Iri
import ch.epfl.bluebrain.nexus.delta.sdk.model.Tags
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.{Anonymous, Subject}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.ProjectRef
import io.circe.Json
Expand All @@ -21,7 +20,6 @@ object BlazegraphViewsGen {
rev: Int = 1,
indexingRev: Int = 1,
deprecated: Boolean = false,
tags: Tags = Tags.empty,
createdBy: Subject = Anonymous,
updatedBy: Subject = Anonymous
): ViewResource =
Expand All @@ -31,7 +29,6 @@ object BlazegraphViewsGen {
uuid,
value,
source,
tags,
rev,
indexingRev,
deprecated,
Expand Down
Loading

0 comments on commit a31a2c1

Please sign in to comment.