-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
819a501
commit 48e2f0f
Showing
7 changed files
with
85 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/schemas/FetchSchema.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package ch.epfl.bluebrain.nexus.delta.sdk.schemas | ||
|
||
import cats.effect.IO | ||
import cats.implicits.catsSyntaxApplicativeError | ||
import ch.epfl.bluebrain.nexus.delta.rdf.IriOrBNode.Iri | ||
import ch.epfl.bluebrain.nexus.delta.sdk.model.Fetch.FetchF | ||
import ch.epfl.bluebrain.nexus.delta.sdk.model.IdSegmentRef | ||
import ch.epfl.bluebrain.nexus.delta.sdk.model.IdSegmentRef.{Latest, Revision, Tag} | ||
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.Schemas.ScopedSchemaLog | ||
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.model.SchemaRejection.{RevisionNotFound, SchemaNotFound, TagNotFound} | ||
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.model.{Schema, SchemaRejection, SchemaState} | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{ProjectRef, ResourceRef} | ||
|
||
trait FetchSchema { | ||
|
||
/** Fetch the referenced resource in the given project */ | ||
def fetch(ref: ResourceRef, project: ProjectRef): FetchF[Schema] | ||
|
||
def stateOrNotFound(id: IdSegmentRef, iri: Iri, ref: ProjectRef): IO[SchemaState] | ||
|
||
} | ||
|
||
object FetchSchema { | ||
|
||
def apply(log: ScopedSchemaLog): FetchSchema = { | ||
|
||
def notFound(iri: Iri, ref: ProjectRef) = SchemaNotFound(iri, ref) | ||
|
||
new FetchSchema { | ||
override def fetch(ref: ResourceRef, project: ProjectRef): FetchF[Schema] = { | ||
stateOrNotFound(IdSegmentRef(ref), ref.iri, project) | ||
.attemptNarrow[SchemaRejection] | ||
.map(_.toOption) | ||
.map(_.map(_.toResource)) | ||
} | ||
|
||
override def stateOrNotFound(id: IdSegmentRef, iri: Iri, ref: ProjectRef): IO[SchemaState] = | ||
id match { | ||
case Latest(_) => log.stateOr(ref, iri, notFound(iri, ref)) | ||
case Revision(_, rev) => log.stateOr(ref, iri, rev, notFound(iri, ref), RevisionNotFound) | ||
case Tag(_, tag) => log.stateOr(ref, iri, tag, notFound(iri, ref), TagNotFound(tag)) | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters