From f5f2d2cbf68afdbdd8a3b1c95549a796bf4fb028 Mon Sep 17 00:00:00 2001 From: Jakub Chrobasik Date: Tue, 1 Aug 2023 19:05:18 +0200 Subject: [PATCH] refactor: TS writing processes to insert renku:slug along renku:projectPath (#1638) --- .../projects/commands/Encoders.scala | 1 + .../searchgraphs/projects/ontology.scala | 2 + .../projects/commands/EncodersSpec.scala | 8 ++-- .../commands/ProjectInfoDeleteQuerySpec.scala | 47 ++++++++----------- .../renku/graph/model/entities/Project.scala | 4 ++ .../graph/model/entities/ProjectSpec.scala | 5 ++ 6 files changed, 36 insertions(+), 31 deletions(-) diff --git a/entities-search/src/main/scala/io/renku/entities/searchgraphs/projects/commands/Encoders.scala b/entities-search/src/main/scala/io/renku/entities/searchgraphs/projects/commands/Encoders.scala index e232750f42..e093783ee8 100644 --- a/entities-search/src/main/scala/io/renku/entities/searchgraphs/projects/commands/Encoders.scala +++ b/entities-search/src/main/scala/io/renku/entities/searchgraphs/projects/commands/Encoders.scala @@ -71,6 +71,7 @@ private object Encoders { Set( searchInfoQuad(rdf / "type", ProjectSearchInfoOntology.typeDef.clazz.id).some, searchInfoQuad(ProjectSearchInfoOntology.nameProperty.id, info.name.asObject).some, + searchInfoQuad(ProjectSearchInfoOntology.slugProperty.id, info.slug.asObject).some, searchInfoQuad(ProjectSearchInfoOntology.pathProperty.id, info.slug.asObject).some, searchInfoQuad(ProjectSearchInfoOntology.visibilityProperty.id, info.visibility.asObject).some, searchInfoQuad(ProjectSearchInfoOntology.dateCreatedProperty.id, info.dateCreated.asObject).some, diff --git a/entities-search/src/main/scala/io/renku/entities/searchgraphs/projects/ontology.scala b/entities-search/src/main/scala/io/renku/entities/searchgraphs/projects/ontology.scala index 0f25e699e5..b6c64656b5 100644 --- a/entities-search/src/main/scala/io/renku/entities/searchgraphs/projects/ontology.scala +++ b/entities-search/src/main/scala/io/renku/entities/searchgraphs/projects/ontology.scala @@ -27,6 +27,7 @@ import io.renku.jsonld.ontology._ object ProjectSearchInfoOntology { val nameProperty: DataProperty.Def = Project.Ontology.nameProperty + val slugProperty: DataProperty.Def = Project.Ontology.slugProperty val pathProperty: DataProperty.Def = Project.Ontology.pathProperty val visibilityProperty: DataProperty.Def = Project.Ontology.visibilityProperty val dateCreatedProperty: DataProperty.Def = Project.Ontology.dateCreatedProperty @@ -44,6 +45,7 @@ object ProjectSearchInfoOntology { ), DataProperties( nameProperty, + slugProperty, pathProperty, visibilityProperty, dateCreatedProperty, diff --git a/entities-search/src/test/scala/io/renku/entities/searchgraphs/projects/commands/EncodersSpec.scala b/entities-search/src/test/scala/io/renku/entities/searchgraphs/projects/commands/EncodersSpec.scala index 012362ad2c..fc131a8d00 100644 --- a/entities-search/src/test/scala/io/renku/entities/searchgraphs/projects/commands/EncodersSpec.scala +++ b/entities-search/src/test/scala/io/renku/entities/searchgraphs/projects/commands/EncodersSpec.scala @@ -82,6 +82,7 @@ class EncodersSpec extends AnyWordSpec with should.Matchers { searchInfo.asQuads shouldBe Set( ProjectsQuad(searchInfo.id, rdf / "type", renku / "DiscoverableProject"), ProjectsQuad(searchInfo.id, ProjectSearchInfoOntology.nameProperty.id, searchInfo.name.asObject), + ProjectsQuad(searchInfo.id, ProjectSearchInfoOntology.slugProperty.id, searchInfo.slug.asObject), ProjectsQuad(searchInfo.id, ProjectSearchInfoOntology.pathProperty.id, searchInfo.slug.asObject), ProjectsQuad(searchInfo.id, ProjectSearchInfoOntology.visibilityProperty.id, searchInfo.visibility.asObject), ProjectsQuad(searchInfo.id, ProjectSearchInfoOntology.dateCreatedProperty.id, searchInfo.dateCreated.asObject), @@ -95,10 +96,9 @@ class EncodersSpec extends AnyWordSpec with should.Matchers { } private def creatorToQuads(searchInfo: ProjectSearchInfo): Set[Quad] = - searchInfo.maybeCreator.toSet - .flatMap((pi: PersonInfo) => - pi.asQuads + ProjectsQuad(searchInfo.id, ProjectSearchInfoOntology.creatorProperty, pi.resourceId.asEntityId) - ) + searchInfo.maybeCreator.toSet.flatMap((pi: PersonInfo) => + pi.asQuads + ProjectsQuad(searchInfo.id, ProjectSearchInfoOntology.creatorProperty, pi.resourceId.asEntityId) + ) private def keywordsToQuads(searchInfo: ProjectSearchInfo): Set[Quad] = searchInfo.keywords diff --git a/entities-search/src/test/scala/io/renku/entities/searchgraphs/projects/commands/ProjectInfoDeleteQuerySpec.scala b/entities-search/src/test/scala/io/renku/entities/searchgraphs/projects/commands/ProjectInfoDeleteQuerySpec.scala index c9b1f98b8a..c26c90e410 100644 --- a/entities-search/src/test/scala/io/renku/entities/searchgraphs/projects/commands/ProjectInfoDeleteQuerySpec.scala +++ b/entities-search/src/test/scala/io/renku/entities/searchgraphs/projects/commands/ProjectInfoDeleteQuerySpec.scala @@ -26,49 +26,42 @@ import io.renku.graph.model import io.renku.graph.model.testentities._ import io.renku.graph.model.{GraphClass, entities} import io.renku.interpreters.TestLogger -import io.renku.testtools.IOSpec +import io.renku.testtools.CustomAsyncIOSpec import io.renku.triplesstore.SparqlQuery.Prefixes import io.renku.triplesstore._ import io.renku.triplesstore.client.syntax._ +import org.scalatest.flatspec.AsyncFlatSpec import org.scalatest.matchers.should -import org.scalatest.wordspec.AnyWordSpec import org.typelevel.log4cats.Logger class ProjectInfoDeleteQuerySpec - extends AnyWordSpec + extends AsyncFlatSpec + with CustomAsyncIOSpec with should.Matchers with InMemoryJenaForSpec with ProjectsDataset - with SearchInfoDatasets - with IOSpec { + with SearchInfoDatasets { - "the delete query" should { + it should "generate query that removes data of a single project info" in { - "generate query that removes data of a single project info" in { + val project1 = anyProjectEntities.generateOne.to[entities.Project] + val project2 = anyProjectEntities.generateOne.to[entities.Project] - val project1 = anyProjectEntities.generateOne.to[entities.Project] - val project2 = anyProjectEntities.generateOne.to[entities.Project] - - IOBody { - insertSearchInfo(project1) >> - insertSearchInfo(project2) >> - findProjects.map(_ should contain only (project1.resourceId, project2.resourceId)) >> - runUpdate(on = projectsDataset, ProjectInfoDeleteQuery(project1.resourceId)) >> - findProjects.map(_ shouldBe List(project2.resourceId)) - } - } + insertSearchInfo(project1) >> + insertSearchInfo(project2) >> + findProjects.asserting(_ should contain only (project1.resourceId, project2.resourceId)) >> + runUpdate(on = projectsDataset, ProjectInfoDeleteQuery(project1.resourceId)) >> + findProjects.asserting(_ shouldBe List(project2.resourceId)) + } - "generate query that removes all the data of the project" in { + it should "generate query that removes all the data of the project" in { - val project = anyProjectEntities.generateOne.to[entities.Project] + val project = anyProjectEntities.generateOne.to[entities.Project] - IOBody { - insertSearchInfo(project) >> - findProjects.map(_ shouldBe List(project.resourceId)) >> - runUpdate(on = projectsDataset, ProjectInfoDeleteQuery(project.resourceId)) >> - triplesCount(on = projectsDataset, graphId = GraphClass.Projects.id).map(_ shouldBe 0L) - } - } + insertSearchInfo(project) >> + findProjects.asserting(_ shouldBe List(project.resourceId)) >> + runUpdate(on = projectsDataset, ProjectInfoDeleteQuery(project.resourceId)) >> + triplesCount(on = projectsDataset, graphId = GraphClass.Projects.id).asserting(_ shouldBe 0L) } implicit override val ioLogger: Logger[IO] = TestLogger[IO]() diff --git a/renku-model/src/main/scala/io/renku/graph/model/entities/Project.scala b/renku-model/src/main/scala/io/renku/graph/model/entities/Project.scala index 813f13c78b..79bddab6d2 100644 --- a/renku-model/src/main/scala/io/renku/graph/model/entities/Project.scala +++ b/renku-model/src/main/scala/io/renku/graph/model/entities/Project.scala @@ -620,6 +620,7 @@ object Project { project.resourceId.asEntityId, entityTypes, schema / "name" -> project.name.asJsonLD, + renku / "slug" -> project.slug.asJsonLD, renku / "projectPath" -> project.slug.asJsonLD, renku / "projectNamespace" -> project.slug.toNamespace.asJsonLD, renku / "projectNamespaces" -> project.namespaces.asJsonLD, @@ -650,6 +651,7 @@ object Project { project.resourceId.asEntityId, entityTypes, schema / "name" -> project.name.asJsonLD, + renku / "slug" -> project.slug.asJsonLD, renku / "projectPath" -> project.slug.asJsonLD, renku / "projectNamespace" -> project.slug.toNamespace.asJsonLD, renku / "projectNamespaces" -> project.namespaces.asJsonLD, @@ -679,6 +681,7 @@ object Project { val image: Property = schema / "image" val nameProperty: DataProperty.Def = DataProperty(schema / "name", xsd / "string") + val slugProperty: DataProperty.Def = DataProperty(renku / "slug", xsd / "string") val pathProperty: DataProperty.Def = DataProperty(renku / "projectPath", xsd / "string") val descriptionProperty: DataProperty.Def = DataProperty(schema / "description", xsd / "string") val dateCreatedProperty: DataProperty.Def = DataProperty(schema / "dateCreated", xsd / "dateTime") @@ -704,6 +707,7 @@ object Project { ObjectProperty(image, Image.Ontology.typeDef) ), DataProperties( + slugProperty, nameProperty, pathProperty, DataProperty(renku / "projectNamespace", xsd / "string"), diff --git a/renku-model/src/test/scala/io/renku/graph/model/entities/ProjectSpec.scala b/renku-model/src/test/scala/io/renku/graph/model/entities/ProjectSpec.scala index 29701deb1e..f17b0581d5 100644 --- a/renku-model/src/test/scala/io/renku/graph/model/entities/ProjectSpec.scala +++ b/renku-model/src/test/scala/io/renku/graph/model/entities/ProjectSpec.scala @@ -1008,6 +1008,7 @@ class ProjectSpec EntityId.of(project.resourceId.show), entities.Project.entityTypes, schema / "name" -> project.name.asJsonLD, + renku / "slug" -> project.slug.asJsonLD, renku / "projectPath" -> project.slug.asJsonLD, renku / "projectNamespace" -> project.slug.toNamespace.asJsonLD, renku / "projectNamespaces" -> project.namespaces.asJsonLD, @@ -1044,6 +1045,7 @@ class ProjectSpec EntityId.of(project.resourceId.show), entities.Project.entityTypes, schema / "name" -> project.name.asJsonLD, + renku / "slug" -> project.slug.asJsonLD, renku / "projectPath" -> project.slug.asJsonLD, renku / "projectNamespace" -> project.slug.toNamespace.asJsonLD, renku / "projectNamespaces" -> project.namespaces.asJsonLD, @@ -1085,6 +1087,7 @@ class ProjectSpec EntityId.of(project.resourceId.show), entities.Project.entityTypes, schema / "name" -> project.name.asJsonLD, + renku / "slug" -> project.slug.asJsonLD, renku / "projectPath" -> project.slug.asJsonLD, renku / "projectNamespace" -> project.slug.toNamespace.asJsonLD, renku / "projectNamespaces" -> project.namespaces.asJsonLD, @@ -1125,6 +1128,7 @@ class ProjectSpec EntityId.of(project.resourceId.show), entities.Project.entityTypes, schema / "name" -> project.name.asJsonLD, + renku / "slug" -> project.slug.asJsonLD, renku / "projectPath" -> project.slug.asJsonLD, renku / "projectNamespace" -> project.slug.toNamespace.asJsonLD, renku / "projectNamespaces" -> project.namespaces.asJsonLD, @@ -1168,6 +1172,7 @@ class ProjectSpec EntityId.of(project.resourceId.show), entities.Project.entityTypes, schema / "name" -> project.name.asJsonLD, + renku / "slug" -> project.slug.asJsonLD, renku / "projectPath" -> project.slug.asJsonLD, renku / "projectNamespace" -> project.slug.toNamespace.asJsonLD, renku / "projectNamespaces" -> project.namespaces.asJsonLD,