Skip to content

Commit

Permalink
Merge branch 'master' into 4727-fix-es-default-view-resetter
Browse files Browse the repository at this point in the history
  • Loading branch information
imsdu authored Mar 6, 2024
2 parents a5860cd + 8a5fa31 commit f34c704
Show file tree
Hide file tree
Showing 47 changed files with 278 additions and 675 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import ch.epfl.bluebrain.nexus.delta.sdk.model.routes.Tag
import ch.epfl.bluebrain.nexus.delta.sdk.model.{BaseUri, ResourceF}
import ch.epfl.bluebrain.nexus.delta.sdk.permissions.Permissions.resources.{read => Read, write => Write}
import ch.epfl.bluebrain.nexus.delta.sdk.resources.NexusSource.DecodingOption
import ch.epfl.bluebrain.nexus.delta.sdk.resources.model.ResourceRejection.{InvalidJsonLdFormat, InvalidSchemaRejection, NoSchemaProvided, ResourceNotFound}
import ch.epfl.bluebrain.nexus.delta.sdk.resources.model.ResourceRejection._
import ch.epfl.bluebrain.nexus.delta.sdk.resources.model.{Resource, ResourceRejection}
import ch.epfl.bluebrain.nexus.delta.sdk.resources.{NexusSource, Resources}
import io.circe.{Json, Printer}
Expand Down Expand Up @@ -93,7 +93,6 @@ final class ResourcesRoutes(
.flatTap(index(project, _, mode))
.map(_.void)
.attemptNarrow[ResourceRejection]
.rejectWhen(wrongJsonOrNotFound)
)
}
},
Expand All @@ -114,7 +113,6 @@ final class ResourcesRoutes(
.flatTap(index(project, _, mode))
.map(_.void)
.attemptNarrow[ResourceRejection]
.rejectWhen(wrongJsonOrNotFound)
)
case (Some(rev), source, tag) =>
// Update a resource
Expand All @@ -124,7 +122,7 @@ final class ResourcesRoutes(
.flatTap(index(project, _, mode))
.map(_.void)
.attemptNarrow[ResourceRejection]
.rejectWhen(wrongJsonOrNotFound)
.rejectOn[ResourceNotFound]
)
}
}
Expand All @@ -138,7 +136,7 @@ final class ResourcesRoutes(
.flatTap(index(project, _, mode))
.map(_.void)
.attemptNarrow[ResourceRejection]
.rejectWhen(wrongJsonOrNotFound)
.rejectOn[ResourceNotFound]
)
}
},
Expand All @@ -152,7 +150,7 @@ final class ResourcesRoutes(
resources
.fetch(resourceRef, project, schemaOpt)
.attemptNarrow[ResourceRejection]
.rejectWhen(wrongJsonOrNotFound)
.rejectOn[ResourceNotFound]
)
}
)
Expand All @@ -168,7 +166,7 @@ final class ResourcesRoutes(
.flatTap(index(project, _, mode))
.map(_.void)
.attemptNarrow[ResourceRejection]
.rejectWhen(wrongJsonOrNotFound)
.rejectOn[ResourceNotFound]
)
}
},
Expand All @@ -182,7 +180,7 @@ final class ResourcesRoutes(
.flatTap(index(project, _, mode))
}
.attemptNarrow[ResourceRejection]
.rejectWhen(wrongJsonOrNotFound)
.rejectOn[ResourceNotFound]
)
}
},
Expand All @@ -195,7 +193,7 @@ final class ResourcesRoutes(
.flatTap(index(project, _, mode))
.map(_.void)
.attemptNarrow[ResourceRejection]
.rejectWhen(wrongJsonOrNotFound)
.rejectOn[ResourceNotFound]
)
}
},
Expand All @@ -218,7 +216,7 @@ final class ResourcesRoutes(
.fetch(resourceRef, project, schemaOpt)
.map(_.value.source)
.attemptNarrow[ResourceRejection]
.rejectWhen(wrongJsonOrNotFound)
.rejectOn[ResourceNotFound]
)
}
}
Expand Down Expand Up @@ -247,7 +245,7 @@ final class ResourcesRoutes(
.fetch(resourceRef, project, schemaOpt)
.map(_.value.tags)
.attemptNarrow[ResourceRejection]
.rejectWhen(wrongJsonOrNotFound)
.rejectOn[ResourceNotFound]
)
},
// Tag a resource
Expand All @@ -261,7 +259,7 @@ final class ResourcesRoutes(
.flatTap(index(project, _, mode))
.map(_.void)
.attemptNarrow[ResourceRejection]
.rejectWhen(wrongJsonOrNotFound)
.rejectOn[ResourceNotFound]
)
}
}
Expand Down Expand Up @@ -291,11 +289,6 @@ final class ResourcesRoutes(
}
}
}

private val wrongJsonOrNotFound: PartialFunction[ResourceRejection, Boolean] = {
case _: ResourceNotFound | _: InvalidSchemaRejection | _: InvalidJsonLdFormat => true
}

}

object ResourcesRoutes {
Expand Down
5 changes: 0 additions & 5 deletions delta/app/src/test/resources/resources/errors/blank-id.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,7 @@ class ResourcesRoutesSpec extends BaseRouteSpec with CatsIOValues {
"fail if the id is blank" in {
Post("/v1/resources/myorg/myproject/_/", payloadWithBlankId.toEntity) ~> asWriter ~> routes ~> check {
response.status shouldEqual StatusCodes.BadRequest
response.asJson shouldEqual jsonContentOf(
"resources/errors/blank-id.json"
)
response.asJson.hcursor.get[String]("@type").toOption should contain("BlankId")
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Archives(
log: ArchiveLog,
fetchContext: FetchContext,
archiveDownload: ArchiveDownload,
sourceDecoder: JsonLdSourceDecoder[ArchiveRejection, ArchiveValue],
sourceDecoder: JsonLdSourceDecoder[ArchiveValue],
config: EphemeralLogConfig
)(implicit rcr: RemoteContextResolution) {

Expand Down Expand Up @@ -204,11 +204,8 @@ object Archives {
onUniqueViolation = (id: Iri, c: CreateArchive) => ResourceAlreadyExists(id, c.project)
)

private[archive] def sourceDecoder(implicit
api: JsonLdApi,
uuidF: UUIDF
): JsonLdSourceDecoder[ArchiveRejection, ArchiveValue] =
new JsonLdSourceDecoder[ArchiveRejection, ArchiveValue](contexts.archives, uuidF)
private[archive] def sourceDecoder(implicit api: JsonLdApi, uuidF: UUIDF): JsonLdSourceDecoder[ArchiveValue] =
new JsonLdSourceDecoder[ArchiveValue](contexts.archives, uuidF)

private[archive] def evaluate(clock: Clock[IO])(
command: CreateArchive
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package ch.epfl.bluebrain.nexus.delta.plugins.archive.model

import akka.http.scaladsl.model.StatusCodes
import ch.epfl.bluebrain.nexus.delta.kernel.Mapper
import ch.epfl.bluebrain.nexus.delta.kernel.error.Rejection
import ch.epfl.bluebrain.nexus.delta.kernel.utils.ClassUtils
import ch.epfl.bluebrain.nexus.delta.plugins.archive.FileSelf
import ch.epfl.bluebrain.nexus.delta.plugins.storage.files.model.FileRejection
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.AbsolutePath
import ch.epfl.bluebrain.nexus.delta.rdf.IriOrBNode.Iri
import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary
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.decoder.JsonLdDecoderError
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.encoder.JsonLdEncoder
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.marshalling.HttpResponseFields
import ch.epfl.bluebrain.nexus.delta.sdk.syntax._
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{ProjectRef, ResourceRef}
Expand Down Expand Up @@ -93,41 +90,6 @@ object ArchiveRejection {
final case class InvalidArchiveId(id: String)
extends ArchiveRejection(s"Archive identifier '$id' cannot be expanded to an Iri.")

/**
* Rejection returned when attempting to create an Archive while providing an id that is blank.
*/
final case object BlankArchiveId extends ArchiveRejection(s"Archive identifier cannot be blank.")

/**
* Rejection returned when attempting to create an Archive where the passed id does not match the id on the source
* json document.
*
* @param id
* the archive identifier
* @param sourceId
* the archive identifier in the source json document
*/
final case class UnexpectedArchiveId(id: Iri, sourceId: Iri)
extends ArchiveRejection(
s"The provided Archive '$id' does not match the id '$sourceId' in the source document."
)

/**
* Rejection returned when attempting to decode an expanded JsonLD as an Archive.
*
* @param error
* the decoder error
*/
final case class DecodingFailed(error: JsonLdDecoderError) extends ArchiveRejection(error.getMessage)

/**
* Rejection returned when converting the source Json document to a JsonLD document.
*/
final case class InvalidJsonLdFormat(id: Option[Iri], rdfError: RdfError)
extends ArchiveRejection(
s"The provided Archive JSON document ${id.fold("")(id => s"with id '$id'")} cannot be interpreted as a JSON-LD document."
)

/**
* Rejection returned when a referenced resource could not be found.
*
Expand All @@ -147,21 +109,13 @@ object ArchiveRejection {
*/
final case class WrappedFileRejection(rejection: FileRejection) extends ArchiveRejection(rejection.reason)

implicit final val jsonLdRejectionMapper: Mapper[JsonLdRejection, ArchiveRejection] = {
case JsonLdRejection.UnexpectedId(id, sourceId) => UnexpectedArchiveId(id, sourceId)
case JsonLdRejection.InvalidJsonLdFormat(id, rdfError) => InvalidJsonLdFormat(id, rdfError)
case JsonLdRejection.DecodingFailed(error) => DecodingFailed(error)
case JsonLdRejection.BlankId => BlankArchiveId
}

implicit final val archiveRejectionEncoder: Encoder.AsObject[ArchiveRejection] =
Encoder.AsObject.instance { r =>
val tpe = ClassUtils.simpleName(r)
val obj = JsonObject.empty.add(keywords.tpe, tpe.asJson).add("reason", r.reason.asJson)
r match {
case InvalidResourceCollection(duplicates, invalids, longIds) =>
obj.add("duplicates", duplicates.asJson).add("invalids", invalids.asJson).add("longIds", longIds.asJson)
case InvalidJsonLdFormat(_, rdf) => obj.add("rdf", rdf.asJson)
case _: ArchiveNotFound => obj.add(keywords.tpe, "ResourceNotFound".asJson)
case _ => obj
}
Expand All @@ -176,11 +130,7 @@ object ArchiveRejection {
case InvalidResourceCollection(_, _, _) => StatusCodes.BadRequest
case ArchiveNotFound(_, _) => StatusCodes.NotFound
case InvalidArchiveId(_) => StatusCodes.BadRequest
case UnexpectedArchiveId(_, _) => StatusCodes.BadRequest
case DecodingFailed(_) => StatusCodes.BadRequest
case InvalidJsonLdFormat(_, _) => StatusCodes.BadRequest
case ResourceNotFound(_, _) => StatusCodes.NotFound
case BlankArchiveId => StatusCodes.BadRequest
case InvalidFileSelf(_) => StatusCodes.BadRequest
case WrappedFileRejection(rejection) => rejection.status
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ package ch.epfl.bluebrain.nexus.delta.plugins.archive
import cats.data.NonEmptySet
import ch.epfl.bluebrain.nexus.delta.kernel.utils.UUIDF
import ch.epfl.bluebrain.nexus.delta.plugins.archive.model.ArchiveReference.{FileReference, ResourceReference}
import ch.epfl.bluebrain.nexus.delta.plugins.archive.model.ArchiveRejection.{DecodingFailed, InvalidJsonLdFormat, UnexpectedArchiveId}
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.AbsolutePath
import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary.nxv
import ch.epfl.bluebrain.nexus.delta.rdf.implicits._
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.api.{JsonLdApi, JsonLdJavaApi}
import ch.epfl.bluebrain.nexus.delta.sdk.jsonld.JsonLdRejection.{DecodingFailed, InvalidJsonLdFormat, UnexpectedId}
import ch.epfl.bluebrain.nexus.delta.sdk.model.ResourceRepresentation.{AnnotatedSourceJson, CompactedJsonLd, Dot, ExpandedJsonLd, NTriples, SourceJson}
import ch.epfl.bluebrain.nexus.delta.sdk.projects.model.{ApiMappings, ProjectContext}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.ProjectRef
import ch.epfl.bluebrain.nexus.delta.sourcing.model.ResourceRef.{Latest, Revision, Tag}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Tag.UserTag
import ch.epfl.bluebrain.nexus.testkit.scalatest.ce.CatsEffectSpec
import io.circe.literal._

import java.nio.file.Paths
import io.circe.literal._

class ArchivesDecodingSpec extends CatsEffectSpec with RemoteContextResolutionFixture {

Expand Down Expand Up @@ -347,7 +347,7 @@ class ArchivesDecodingSpec extends CatsEffectSpec with RemoteContextResolutionFi
}
]
}"""
decoder(context, providedId, source).rejectedWith[UnexpectedArchiveId]
decoder(context, providedId, source).rejectedWith[UnexpectedId]
}

"parsing a source as an ExpandedJsonLd" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import java.util.UUID
final class BlazegraphViews(
log: BlazegraphLog,
fetchContext: FetchContext,
sourceDecoder: JsonLdSourceResolvingDecoder[BlazegraphViewRejection, BlazegraphViewValue],
sourceDecoder: JsonLdSourceResolvingDecoder[BlazegraphViewValue],
createNamespace: ViewResource => IO[Unit],
prefix: String
) {
Expand Down Expand Up @@ -549,7 +549,7 @@ object BlazegraphViews {

BlazegraphDecoderConfiguration.apply
.map { implicit config =>
new JsonLdSourceResolvingDecoder[BlazegraphViewRejection, BlazegraphViewValue](
new JsonLdSourceResolvingDecoder[BlazegraphViewValue](
contexts.blazegraph,
contextResolution,
uuidF
Expand Down
Loading

0 comments on commit f34c704

Please sign in to comment.