Skip to content

Commit

Permalink
Rename practice to trial
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Dumas committed Sep 20, 2023
1 parent 3dc1c36 commit d84c0c1
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import ch.epfl.bluebrain.nexus.delta.kernel.effect.migration._
import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary.schemas
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.RemoteContextResolution
import ch.epfl.bluebrain.nexus.delta.rdf.utils.JsonKeyOrdering
import ch.epfl.bluebrain.nexus.delta.routes.ResourcesPracticeRoutes.SchemaInput._
import ch.epfl.bluebrain.nexus.delta.routes.ResourcesPracticeRoutes.{GenerateSchema, GenerationInput}
import ch.epfl.bluebrain.nexus.delta.routes.ResourcesTrialRoutes.SchemaInput._
import ch.epfl.bluebrain.nexus.delta.routes.ResourcesTrialRoutes.{GenerateSchema, GenerationInput}
import ch.epfl.bluebrain.nexus.delta.sdk.SchemaResource
import ch.epfl.bluebrain.nexus.delta.sdk.acls.AclCheck
import ch.epfl.bluebrain.nexus.delta.sdk.circe.CirceUnmarshalling
Expand All @@ -22,7 +22,7 @@ import ch.epfl.bluebrain.nexus.delta.sdk.model.{BaseUri, IdSegment}
import ch.epfl.bluebrain.nexus.delta.sdk.permissions.Permissions.resources.{write => Write}
import ch.epfl.bluebrain.nexus.delta.sdk.resources.NexusSource.DecodingOption
import ch.epfl.bluebrain.nexus.delta.sdk.resources.model.ResourceRejection
import ch.epfl.bluebrain.nexus.delta.sdk.resources.{NexusSource, ResourcesPractice}
import ch.epfl.bluebrain.nexus.delta.sdk.resources.{NexusSource, ResourcesTrial}
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.Schemas
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.model.SchemaRejection
import ch.epfl.bluebrain.nexus.delta.sourcing.model.ProjectRef
Expand All @@ -35,13 +35,13 @@ import monix.execution.Scheduler
import scala.annotation.nowarn

/**
* The resource practice routes allowing to do read-only operations on resource
* The resource trial routes allowing to do read-only operations on resources
*/
final class ResourcesPracticeRoutes(
final class ResourcesTrialRoutes(
identities: Identities,
aclCheck: AclCheck,
generateSchema: GenerateSchema,
resourcesPractice: ResourcesPractice,
resourcesTrial: ResourcesTrial,
schemeDirectives: DeltaSchemeDirectives
)(implicit
baseUri: BaseUri,
Expand All @@ -56,7 +56,7 @@ final class ResourcesPracticeRoutes(
import schemeDirectives._
def routes: Route =
baseUriPrefix(baseUri.prefix) {
concat(validateRoute, practiceRoute)
concat(validateRoute, generateRoute)
}

private def validateRoute: Route =
Expand All @@ -67,16 +67,16 @@ final class ResourcesPracticeRoutes(
(get & idSegment & idSegmentRef & pathPrefix("validate") & pathEndOrSingleSlash) { (schema, id) =>
val schemaOpt = underscoreToOption(schema)
emit(
resourcesPractice.validate(id, project, schemaOpt).leftWiden[ResourceRejection]
resourcesTrial.validate(id, project, schemaOpt).leftWiden[ResourceRejection]
)
}
}
}
}
}

private def practiceRoute: Route =
(get & pathPrefix("practice") & pathPrefix("resources")) {
private def generateRoute: Route =
(get & pathPrefix("trial") & pathPrefix("resources")) {
extractCaller { implicit caller =>
(resolveProjectRef & pathEndOrSingleSlash) { project =>
authorizeFor(project, Write).apply {
Expand All @@ -92,18 +92,18 @@ final class ResourcesPracticeRoutes(
private def generate(project: ProjectRef, input: GenerationInput)(implicit caller: Caller) =
input.schema match {
case ExistingSchema(schemaId) =>
emit(resourcesPractice.generate(project, schemaId, input.resource).flatMap(_.asJson))
emit(resourcesTrial.generate(project, schemaId, input.resource).flatMap(_.asJson))
case NewSchema(schemaSource) =>
emit(
generateSchema(project, schemaSource, caller).flatMap { schema =>
resourcesPractice.generate(project, schema, input.resource).flatMap(_.asJson)
resourcesTrial.generate(project, schema, input.resource).flatMap(_.asJson)
}
)
}

}

object ResourcesPracticeRoutes {
object ResourcesTrialRoutes {

type GenerateSchema = (ProjectRef, Json, Caller) => IO[SchemaRejection, SchemaResource]

Expand Down Expand Up @@ -143,20 +143,20 @@ object ResourcesPracticeRoutes {
identities: Identities,
aclCheck: AclCheck,
schemas: Schemas,
resourcesPractice: ResourcesPractice,
resourcesTrial: ResourcesTrial,
schemeDirectives: DeltaSchemeDirectives
)(implicit
baseUri: BaseUri,
s: Scheduler,
cr: RemoteContextResolution,
ordering: JsonKeyOrdering,
decodingOption: DecodingOption
): ResourcesPracticeRoutes =
new ResourcesPracticeRoutes(
): ResourcesTrialRoutes =
new ResourcesTrialRoutes(
identities,
aclCheck,
(project, source, caller) => schemas.createDryRun(project, source)(caller).toBIO[SchemaRejection],
resourcesPractice,
resourcesTrial,
schemeDirectives
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class DeltaModule(appCfg: AppConfig, config: Config)(implicit classLoader: Class
include(ResolversModule)
include(SchemasModule)
include(ResourcesModule)
include(ResourcesPracticeModule)
include(ResourcesTrialModule)
include(MultiFetchModule)
include(IdentitiesModule)
include(VersionModule)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ch.epfl.bluebrain.nexus.delta.kernel.utils.UUIDF
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.api.JsonLdApi
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.RemoteContextResolution
import ch.epfl.bluebrain.nexus.delta.rdf.utils.JsonKeyOrdering
import ch.epfl.bluebrain.nexus.delta.routes.ResourcesPracticeRoutes
import ch.epfl.bluebrain.nexus.delta.routes.ResourcesTrialRoutes
import ch.epfl.bluebrain.nexus.delta.sdk.PriorityRoute
import ch.epfl.bluebrain.nexus.delta.sdk.acls.AclCheck
import ch.epfl.bluebrain.nexus.delta.sdk.directives.DeltaSchemeDirectives
Expand All @@ -16,19 +16,19 @@ import ch.epfl.bluebrain.nexus.delta.sdk.projects.FetchContext
import ch.epfl.bluebrain.nexus.delta.sdk.projects.FetchContext.ContextRejection
import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.ResolverContextResolution
import ch.epfl.bluebrain.nexus.delta.sdk.resources.model.ResourceRejection.ProjectContextRejection
import ch.epfl.bluebrain.nexus.delta.sdk.resources.{Resources, ResourcesConfig, ResourcesPractice, ValidateResource}
import ch.epfl.bluebrain.nexus.delta.sdk.resources.{Resources, ResourcesConfig, ResourcesTrial, ValidateResource}
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.Schemas
import distage.ModuleDef
import izumi.distage.model.definition.Id
import monix.bio.UIO
import monix.execution.Scheduler

/**
* Resources practice wiring
* Resources trial wiring
*/
object ResourcesPracticeModule extends ModuleDef {
object ResourcesTrialModule extends ModuleDef {

make[ResourcesPractice].from {
make[ResourcesTrial].from {
(
resources: Resources,
validate: ValidateResource,
Expand All @@ -38,32 +38,32 @@ object ResourcesPracticeModule extends ModuleDef {
clock: Clock[UIO],
uuidF: UUIDF
) =>
ResourcesPractice(
ResourcesTrial(
resources.fetch(_, _, None),
validate,
fetchContext.mapRejection(ProjectContextRejection),
contextResolution
)(api, clock, uuidF)
}

make[ResourcesPracticeRoutes].from {
make[ResourcesTrialRoutes].from {
(
identities: Identities,
aclCheck: AclCheck,
schemas: Schemas,
resourcesPractice: ResourcesPractice,
resourcesTrial: ResourcesTrial,
schemeDirectives: DeltaSchemeDirectives,
baseUri: BaseUri,
s: Scheduler,
cr: RemoteContextResolution @Id("aggregate"),
ordering: JsonKeyOrdering,
config: ResourcesConfig
) =>
ResourcesPracticeRoutes(
ResourcesTrialRoutes(
identities,
aclCheck,
schemas,
resourcesPractice,
resourcesTrial,
schemeDirectives
)(
baseUri,
Expand All @@ -74,7 +74,7 @@ object ResourcesPracticeModule extends ModuleDef {
)
}

many[PriorityRoute].add { (route: ResourcesPracticeRoutes) =>
many[PriorityRoute].add { (route: ResourcesTrialRoutes) =>
PriorityRoute(pluginsMinPriority - 1, route.routes, requiresStrictEntity = true)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import akka.http.scaladsl.server.Route
import ch.epfl.bluebrain.nexus.delta.kernel.utils.UrlUtils
import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary.{contexts, nxv, schemas}
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.JsonLdContext.keywords
import ch.epfl.bluebrain.nexus.delta.routes.ResourcesPracticeRoutes.GenerateSchema
import ch.epfl.bluebrain.nexus.delta.routes.ResourcesTrialRoutes.GenerateSchema
import ch.epfl.bluebrain.nexus.delta.sdk.acls.AclSimpleCheck
import ch.epfl.bluebrain.nexus.delta.sdk.directives.DeltaSchemeDirectives
import ch.epfl.bluebrain.nexus.delta.sdk.generators.SchemaGen
Expand All @@ -32,7 +32,7 @@ import monix.bio.{IO, UIO}

import java.time.Instant

class ResourcesPracticeRoutesSpec extends BaseRouteSpec with ResourceInstanceFixture with ValidateResourceFixture {
class ResourcesTrialRoutesSpec extends BaseRouteSpec with ResourceInstanceFixture with ValidateResourceFixture {

implicit private val caller: Caller =
Caller(alice, Set(alice, Anonymous, Authenticated(realm), Group("group", realm)))
Expand Down Expand Up @@ -72,7 +72,7 @@ class ResourcesPracticeRoutesSpec extends BaseRouteSpec with ResourceInstanceFix

private val expectedError = ReservedResourceId(nxv + "invalid")

private val resourcesPractice = new ResourcesPractice {
private val resourcesTrial = new ResourcesTrial {
override def generate(project: ProjectRef, schema: IdSegment, source: NexusSource)(implicit
caller: Caller
): UIO[ResourceGenerationResult] =
Expand Down Expand Up @@ -116,39 +116,39 @@ class ResourcesPracticeRoutesSpec extends BaseRouteSpec with ResourceInstanceFix

private lazy val routes =
Route.seal(
new ResourcesPracticeRoutes(
new ResourcesTrialRoutes(
IdentitiesDummy(caller),
aclCheck,
generateSchema,
resourcesPractice,
resourcesTrial,
DeltaSchemeDirectives(fetchContext)
).routes
)

"A resource practice route" should {
"A resource trial route" should {

"fail to generate a resource for a user without access" in {
val payload = json"""{ "resource": $validSource }"""
Get(s"/v1/practice/resources/$projectRef/", payload.toEntity) ~> routes ~> check {
Get(s"/v1/trial/resources/$projectRef/", payload.toEntity) ~> routes ~> check {
response.status shouldEqual StatusCodes.Forbidden
response.asJson shouldEqual jsonContentOf("errors/authorization-failed.json")
}
}

"generate a resource without passing a schema" in {
val payload = json"""{ "resource": $validSource }"""
Get(s"/v1/practice/resources/$projectRef/", payload.toEntity) ~> asAlice ~> routes ~> check {
Get(s"/v1/trial/resources/$projectRef/", payload.toEntity) ~> asAlice ~> routes ~> check {
response.status shouldEqual StatusCodes.OK
val jsonResponse = response.asJsonObject
jsonResponse("schema") shouldBe empty
jsonResponse("result") shouldEqual Some(jsonContentOf("practice/generated-resource.json"))
jsonResponse("result") shouldEqual Some(jsonContentOf("trial/generated-resource.json"))
jsonResponse("error") shouldBe empty
}
}

"generate a resource passing a new schema" in {
val payload = json"""{ "schema": $schemaSource, "resource": $validSource }"""
Get(s"/v1/practice/resources/$projectRef/", payload.toEntity) ~> asAlice ~> routes ~> check {
Get(s"/v1/trial/resources/$projectRef/", payload.toEntity) ~> asAlice ~> routes ~> check {
response.status shouldEqual StatusCodes.OK
val jsonResponse = response.asJsonObject
jsonResponse("schema") should not be empty
Expand All @@ -159,7 +159,7 @@ class ResourcesPracticeRoutesSpec extends BaseRouteSpec with ResourceInstanceFix

"fails to generate a resource when passing an invalid new schema" in {
val payload = json"""{ "schema": { "invalid": "xxx" }, "resource": $validSource }"""
Get(s"/v1/practice/resources/$projectRef/", payload.toEntity) ~> asAlice ~> routes ~> check {
Get(s"/v1/trial/resources/$projectRef/", payload.toEntity) ~> asAlice ~> routes ~> check {
response.status shouldEqual StatusCodes.BadRequest
response.asJson shouldEqual
json"""{
Expand All @@ -174,7 +174,7 @@ class ResourcesPracticeRoutesSpec extends BaseRouteSpec with ResourceInstanceFix

"fails to generate a resource when the resource payload is invalid and without passing a schema" in {
val payload = json"""{ "resource": $invalidSource }"""
Get(s"/v1/practice/resources/$projectRef/", payload.toEntity) ~> asAlice ~> routes ~> check {
Get(s"/v1/trial/resources/$projectRef/", payload.toEntity) ~> asAlice ~> routes ~> check {
response.status shouldEqual StatusCodes.OK
response.asJson shouldEqual
json"""
Expand All @@ -190,7 +190,7 @@ class ResourcesPracticeRoutesSpec extends BaseRouteSpec with ResourceInstanceFix

"fail to generate a resource passing a new schema" in {
val payload = json"""{ "schema": $schemaSource, "resource": $invalidSource }"""
Get(s"/v1/practice/resources/$projectRef/", payload.toEntity) ~> asAlice ~> routes ~> check {
Get(s"/v1/trial/resources/$projectRef/", payload.toEntity) ~> asAlice ~> routes ~> check {
response.status shouldEqual StatusCodes.OK
val jsonResponse = response.asJsonObject
jsonResponse("schema") should not be empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import monix.bio.{IO, UIO}
/**
* Operations allowing to perform read-only operations on resources
*/
trait ResourcesPractice {
trait ResourcesTrial {

/**
* Generates the resource and validate it against the provided schema reference
Expand Down Expand Up @@ -69,13 +69,13 @@ trait ResourcesPractice {
): IO[ResourceRejection, ValidationResult]
}

object ResourcesPractice {
object ResourcesTrial {
def apply(
fetchResource: (IdSegmentRef, ProjectRef) => IO[ResourceFetchRejection, DataResource],
validateResource: ValidateResource,
fetchContext: FetchContext[ProjectContextRejection],
contextResolution: ResolverContextResolution
)(implicit api: JsonLdApi, clock: Clock[UIO], uuidF: UUIDF): ResourcesPractice = new ResourcesPractice {
)(implicit api: JsonLdApi, clock: Clock[UIO], uuidF: UUIDF): ResourcesTrial = new ResourcesTrial {

private val sourceParser = JsonLdSourceResolvingParser[ResourceRejection](contextResolution, uuidF)

Expand Down
Loading

0 comments on commit d84c0c1

Please sign in to comment.