Skip to content

Commit

Permalink
refactor: TS writing processes to insert renku:slug along renku:proje…
Browse files Browse the repository at this point in the history
…ctPath (#1638)
  • Loading branch information
jachro authored Aug 1, 2023
1 parent 0121387 commit f5f2d2c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -44,6 +45,7 @@ object ProjectSearchInfoOntology {
),
DataProperties(
nameProperty,
slugProperty,
pathProperty,
visibilityProperty,
dateCreatedProperty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand All @@ -704,6 +707,7 @@ object Project {
ObjectProperty(image, Image.Ontology.typeDef)
),
DataProperties(
slugProperty,
nameProperty,
pathProperty,
DataProperty(renku / "projectNamespace", xsd / "string"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f5f2d2c

Please sign in to comment.