Skip to content

Commit

Permalink
Use FetchSchema in SchemaImports
Browse files Browse the repository at this point in the history
  • Loading branch information
olivergrabinski committed Mar 8, 2024
1 parent 48e2f0f commit 1448a8a
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ 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.ResolverResolution.ResourceResolution
import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.{ResolverContextResolution, Resolvers, ResourceResolution}
import ch.epfl.bluebrain.nexus.delta.sdk.resources.Resources.{ScopedResourceDefinition, ScopedResourceLog}
import ch.epfl.bluebrain.nexus.delta.sdk.resources.Resources.{ResourceDefinition, ResourceLog}
import ch.epfl.bluebrain.nexus.delta.sdk.resources._
import ch.epfl.bluebrain.nexus.delta.sdk.resources.model.{Resource, ResourceEvent}
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.Schemas
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.FetchSchema
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.model.Schema
import ch.epfl.bluebrain.nexus.delta.sdk.sse.SseEncoder
import ch.epfl.bluebrain.nexus.delta.sourcing.{ScopedEventLog, Transactors}
Expand All @@ -32,8 +32,8 @@ import izumi.distage.model.definition.{Id, ModuleDef}
* Resources wiring
*/
object ResourcesModule extends ModuleDef {
make[ResourceResolution[Schema]].from { (aclCheck: AclCheck, resolvers: Resolvers, schemas: Schemas) =>
ResourceResolution.schemaResource(aclCheck, resolvers, schemas, excludeDeprecated = false)
make[ResourceResolution[Schema]].from { (aclCheck: AclCheck, resolvers: Resolvers, fetchSchema: FetchSchema) =>
ResourceResolution.schemaResource(aclCheck, resolvers, fetchSchema, excludeDeprecated = false)
}

make[ValidateResource].from {
Expand All @@ -45,30 +45,28 @@ object ResourcesModule extends ModuleDef {

make[DetectChange].from { (config: ResourcesConfig) => DetectChange(config.skipUpdateNoChange) }

make[ScopedResourceDefinition].from {
(validateResource: ValidateResource, detectChange: DetectChange, clock: Clock[IO]) =>
Resources.definition(validateResource, detectChange, clock)
make[ResourceDefinition].from { (validateResource: ValidateResource, detectChange: DetectChange, clock: Clock[IO]) =>
Resources.definition(validateResource, detectChange, clock)
}

make[ScopedResourceLog].from {
(scopedDefinition: ScopedResourceDefinition, config: ResourcesConfig, xas: Transactors) =>
ScopedEventLog(scopedDefinition, config.eventLog, xas)
make[ResourceLog].from { (scopedDefinition: ResourceDefinition, config: ResourcesConfig, xas: Transactors) =>
ScopedEventLog(scopedDefinition, config.eventLog, xas)
}

make[FetchResource].from { (scopedLog: ScopedResourceLog) =>
make[FetchResource].from { (scopedLog: ResourceLog) =>
FetchResource(scopedLog)
}

make[Resources].from {
(
scopedLog: ScopedResourceLog,
resourceLog: ResourceLog,
fetchContext: FetchContext,
resolverContextResolution: ResolverContextResolution,
api: JsonLdApi,
uuidF: UUIDF
) =>
ResourcesImpl(
scopedLog,
resourceLog,
fetchContext,
resolverContextResolution
)(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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, Resolvers}
import ch.epfl.bluebrain.nexus.delta.sdk.resources.FetchResource
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.Schemas.{ScopedSchemaDefinition, ScopedSchemaLog}
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.Schemas.{SchemaDefinition, SchemaLog}
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.model.{Schema, SchemaEvent}
import ch.epfl.bluebrain.nexus.delta.sdk.schemas._
import ch.epfl.bluebrain.nexus.delta.sdk.sse.SseEncoder
Expand All @@ -40,25 +40,29 @@ object SchemasModule extends ModuleDef {

}

make[ScopedSchemaDefinition].from { (validateSchema: ValidateSchema, clock: Clock[IO]) =>
make[SchemaDefinition].from { (validateSchema: ValidateSchema, clock: Clock[IO]) =>
Schemas.definition(validateSchema, clock)
}

make[ScopedSchemaLog].from { (scopedDefinition: ScopedSchemaDefinition, config: SchemasConfig, xas: Transactors) =>
make[SchemaLog].from { (scopedDefinition: SchemaDefinition, config: SchemasConfig, xas: Transactors) =>
ScopedEventLog(scopedDefinition, config.eventLog, xas)
}

make[FetchSchema].from { (schemaLog: SchemaLog) =>
FetchSchema(schemaLog)
}

make[Schemas].from {
(
scopedLog: ScopedSchemaLog,
schemaLog: SchemaLog,
fetchContext: FetchContext,
schemaImports: SchemaImports,
api: JsonLdApi,
resolverContextResolution: ResolverContextResolution,
uuidF: UUIDF
) =>
SchemasImpl(
scopedLog,
schemaLog,
fetchContext,
schemaImports,
resolverContextResolution
Expand All @@ -69,10 +73,10 @@ object SchemasModule extends ModuleDef {
(
aclCheck: AclCheck,
resolvers: Resolvers,
schemas: Schemas,
fetchSchema: FetchSchema,
fetchResource: FetchResource
) =>
SchemaImports(aclCheck, resolvers, schemas, fetchResource)
SchemaImports(aclCheck, resolvers, fetchSchema, fetchResource)
}

make[SchemasRoutes].from {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.ResolverResolution.{Deprecati
import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.model.Resolver
import ch.epfl.bluebrain.nexus.delta.sdk.resources.FetchResource
import ch.epfl.bluebrain.nexus.delta.sdk.resources.model.Resource
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.Schemas
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.FetchSchema
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.model.Schema
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{Identity, ProjectRef, ResourceRef}

Expand Down Expand Up @@ -100,21 +100,21 @@ object ResourceResolution {
* how to check acls
* @param resolvers
* a resolvers instance
* @param schemas
* a schemas instance
* @param fetchSchema
* how to fetch a schema
* @param excludeDeprecated
* to exclude deprecated resources from the resolution
*/
def schemaResource(
aclCheck: AclCheck,
resolvers: Resolvers,
schemas: Schemas,
fetchSchema: FetchSchema,
excludeDeprecated: Boolean
): ResourceResolution[Schema] =
apply(
aclCheck,
resolvers,
(ref: ResourceRef, project: ProjectRef) => schemas.fetch(ref, project).redeem(_ => None, Some(_)),
fetchSchema.fetch _,
Permissions.schemas.read,
excludeDeprecated
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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.resources.Resources.ScopedResourceLog
import ch.epfl.bluebrain.nexus.delta.sdk.resources.Resources.ResourceLog
import ch.epfl.bluebrain.nexus.delta.sdk.resources.model.ResourceRejection.{ResourceNotFound, RevisionNotFound, TagNotFound}
import ch.epfl.bluebrain.nexus.delta.sdk.resources.model.{Resource, ResourceRejection, ResourceState}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{ProjectRef, ResourceRef}
Expand All @@ -22,7 +22,7 @@ trait FetchResource {

object FetchResource {

def apply(log: ScopedResourceLog): FetchResource = {
def apply(log: ResourceLog): FetchResource = {

def notFound(iri: Iri, ref: ProjectRef) = ResourceNotFound(iri, ref)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,9 @@ object Resources {
}
}

type ScopedResourceDefinition =
type ResourceDefinition =
ScopedEntityDefinition[Iri, ResourceState, ResourceCommand, ResourceEvent, ResourceRejection]
type ScopedResourceLog =
type ResourceLog =
ScopedEventLog[Iri, ResourceState, ResourceCommand, ResourceEvent, ResourceRejection]

/**
Expand All @@ -517,7 +517,7 @@ object Resources {
validateResource: ValidateResource,
detectChange: DetectChange,
clock: Clock[IO]
): ScopedResourceDefinition =
): ResourceDefinition =
ScopedEntityDefinition(
entityType,
StateMachine(None, evaluate(validateResource, detectChange, clock)(_, _), next),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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.ProjectContext
import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.ResolverContextResolution
import ch.epfl.bluebrain.nexus.delta.sdk.resources.Resources.{entityType, expandIri, expandResourceRef, ScopedResourceLog}
import ch.epfl.bluebrain.nexus.delta.sdk.resources.Resources.{entityType, expandIri, expandResourceRef, ResourceLog}
import ch.epfl.bluebrain.nexus.delta.sdk.resources.ResourcesImpl.{logger, ResourcesLog}
import ch.epfl.bluebrain.nexus.delta.sdk.resources.model.ResourceCommand._
import ch.epfl.bluebrain.nexus.delta.sdk.resources.model.ResourceRejection.{NoChangeDetected, ResourceNotFound}
Expand Down Expand Up @@ -211,7 +211,7 @@ object ResourcesImpl {
* the context resolver
*/
final def apply(
scopedLog: ScopedResourceLog,
scopedLog: ResourceLog,
fetchContext: FetchContext,
contextResolution: ResolverContextResolution
)(implicit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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.Schemas.SchemaLog
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}
Expand All @@ -22,7 +22,7 @@ trait FetchSchema {

object FetchSchema {

def apply(log: ScopedSchemaLog): FetchSchema = {
def apply(log: SchemaLog): FetchSchema = {

def notFound(iri: Iri, ref: ProjectRef) = SchemaNotFound(iri, ref)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ object SchemaImports {
final def apply(
aclCheck: AclCheck,
resolvers: Resolvers,
schemas: Schemas,
fetchSchema: FetchSchema,
fetchResource: FetchResource
): SchemaImports = {
def resolveSchema(ref: ResourceRef, projectRef: ProjectRef, caller: Caller) =
ResourceResolution
.schemaResource(aclCheck, resolvers, schemas, excludeDeprecated = true)
.schemaResource(aclCheck, resolvers, fetchSchema, excludeDeprecated = true)
.resolve(ref, projectRef)(caller)
.map(_.map(_.value))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,16 +375,16 @@ object Schemas {
}
}

type ScopedSchemaDefinition = ScopedEntityDefinition[Iri, SchemaState, SchemaCommand, SchemaEvent, SchemaRejection]
type ScopedSchemaLog = ScopedEventLog[Iri, SchemaState, SchemaCommand, SchemaEvent, SchemaRejection]
type SchemaDefinition = ScopedEntityDefinition[Iri, SchemaState, SchemaCommand, SchemaEvent, SchemaRejection]
type SchemaLog = ScopedEventLog[Iri, SchemaState, SchemaCommand, SchemaEvent, SchemaRejection]

/**
* Entity definition for [[Schemas]]
*/
def definition(
validate: ValidateSchema,
clock: Clock[IO]
): ScopedSchemaDefinition =
): SchemaDefinition =
ScopedEntityDefinition(
entityType,
StateMachine(None, evaluate(validate, clock), next),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import ch.epfl.bluebrain.nexus.delta.sdk.model.IdSegmentRef.{Latest, Revision, T
import ch.epfl.bluebrain.nexus.delta.sdk.model._
import ch.epfl.bluebrain.nexus.delta.sdk.projects.FetchContext
import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.ResolverContextResolution
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.Schemas.{entityType, expandIri, ScopedSchemaLog}
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.Schemas.{entityType, expandIri, SchemaLog}
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.SchemasImpl.SchemasLog
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.model.SchemaCommand._
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.model.SchemaRejection.{RevisionNotFound, SchemaNotFound, TagNotFound}
Expand Down Expand Up @@ -173,7 +173,7 @@ object SchemasImpl {
* Constructs a [[Schemas]] instance.
*/
final def apply(
scopedLog: ScopedSchemaLog,
scopedLog: SchemaLog,
fetchContext: FetchContext,
schemaImports: SchemaImports,
contextResolution: ResolverContextResolution
Expand Down

0 comments on commit 1448a8a

Please sign in to comment.