Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(knora-admin): Remove unused Institution class and its properties (DEV-3365) #3109

Merged
merged 11 commits into from
Mar 14, 2024
2 changes: 0 additions & 2 deletions docs/02-dsp-ontologies/knora-base.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ In Knora, each item of data belongs to some particular project. Each project usi

- `projectDescription` (1-n): A description of the project.

- `belongsToInstitution` (0-1): The `kb:Institution` that the project belongs to.

Ontologies and resources are associated with a project by means of the
`kb:attachedToProject` property, as described in [Ontologies](#ontologies)
and [Properties of Resource](#properties-of-resource)). Users are associated with a project by means of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,6 @@ erDiagram

```

!!! danger "Unclear/Unexpected Stuff"

- User.phone?
- Institution? (name, description, website, phone, address, email)
- Project.belongsToInstitution?

### Overview V2

```mermaid
Expand Down
6 changes: 0 additions & 6 deletions test_data/project_data/admin-data.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
"collection"^^xsd:string ;
knora-admin:projectRestrictedViewSize "!512,512"^^xsd:string ;
knora-admin:projectRestrictedViewWatermark "true"^^xsd:boolean;
knora-admin:belongsToInstitution <http://rdfh.ch/institutions/dhlab-basel> ;
knora-admin:status "true"^^xsd:boolean ;
knora-admin:hasSelfJoinEnabled "false"^^xsd:boolean .

Expand Down Expand Up @@ -141,11 +140,6 @@
knora-admin:hasSelfJoinEnabled "false"^^xsd:boolean .


<http://rdfh.ch/institutions/dhlab-basel>
rdf:type knora-admin:Institution ;
knora-admin:institutionName "Digital Humanities Lab, Basel" .


##########################################################
#
# INCUNABULA PROJECT / USERS / GROUPS
Expand Down
2 changes: 0 additions & 2 deletions test_data/upgrade/pr1746.trig
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

knora-admin:projectRestrictedViewSize "!512,512"^^xsd:string ;

knora-admin:belongsToInstitution <http://rdfh.ch/institutions/dhlab-basel> ;

knora-admin:status "true"^^xsd:boolean ;

knora-admin:hasSelfJoinEnabled "false"^^xsd:boolean .
Expand Down
91 changes: 0 additions & 91 deletions webapi/src/main/resources/knora-ontologies/knora-admin.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@
#################################################################


### http://www.knora.org/ontology/knora-admin#belongsToInstitution

:belongsToInstitution
rdf:type owl:ObjectProperty ;
rdfs:subPropertyOf knora-base:objectCannotBeMarkedAsDeleted ;
rdfs:comment "Indicates which Institution a project belongs to."@en ;
knora-base:subjectClassConstraint :knoraProject ;
knora-base:objectClassConstraint :Institution .


### http://www.knora.org/ontology/knora-admin#belongsToProject

:belongsToProject
Expand Down Expand Up @@ -96,16 +86,6 @@
#
#################################################################


### http://www.knora.org/ontology/knora-admin#address

:address
rdf:type owl:DatatypeProperty ;
rdfs:subPropertyOf knora-base:objectCannotBeMarkedAsDeleted ;
knora-base:objectDatatypeConstraint xsd:string ;
rdfs:comment "The address of a person or an institution"@en .


### http://www.knora.org/ontology/knora-admin#groupName

:groupName
Expand Down Expand Up @@ -139,37 +119,6 @@
knora-base:objectDatatypeConstraint xsd:boolean .


### http://www.knora.org/ontology/knora-admin#institutionName

:institutionName
rdf:type owl:DatatypeProperty ;
rdfs:subPropertyOf knora-base:objectCannotBeMarkedAsDeleted ;
rdfs:comment "The institutions's name."@en ;
rdfs:subPropertyOf <http://xmlns.com/foaf/0.1/name> ;
knora-base:subjectClassConstraint :Institution ;
knora-base:objectDatatypeConstraint xsd:string .


### http://www.knora.org/ontology/knora-admin#institutionDescription

:institutionDescription
rdf:type owl:DatatypeProperty ;
rdfs:subPropertyOf knora-base:objectCannotBeMarkedAsDeleted ;
rdfs:comment "A description of an institution."@en ;
knora-base:subjectClassConstraint :Institution ;
knora-base:objectDatatypeConstraint xsd:string .


### http://www.knora.org/ontology/knora-admin#institutionWebsite

:institutionWebsite
rdf:type owl:DatatypeProperty ;
rdfs:subPropertyOf knora-base:objectCannotBeMarkedAsDeleted ;
rdfs:comment "The URL of a web site."@en ;
knora-base:subjectClassConstraint :Institution ;
knora-base:objectDatatypeConstraint xsd:anyURI .


### http://www.knora.org/ontology/knora-admin#isActiveUser

:isInSystemAdminGroup
Expand Down Expand Up @@ -209,16 +158,6 @@
knora-base:subjectClassConstraint :User ;
knora-base:objectDatatypeConstraint xsd:string .


### http://www.knora.org/ontology/knora-admin#phone

:phone
rdf:type owl:DatatypeProperty ;
rdfs:subPropertyOf knora-base:objectCannotBeMarkedAsDeleted ;
rdfs:comment "The phone number of a person, institution, etc."@en ;
knora-base:objectDatatypeConstraint xsd:string .


### http://www.knora.org/ontology/knora-admin#preferredLanguage

:preferredLanguage
Expand Down Expand Up @@ -345,33 +284,6 @@
#
#################################################################


### http://www.knora.org/ontology/knora-admin#Institution

:Institution
rdf:type owl:Class ;
rdfs:subClassOf foaf:Organization,
[ rdf:type owl:Restriction ;
owl:onProperty :institutionName ;
owl:cardinality "1"^^xsd:nonNegativeInteger ],
[ rdf:type owl:Restriction ;
owl:onProperty :institutionDescription ;
owl:maxCardinality "1"^^xsd:nonNegativeInteger ],
[ rdf:type owl:Restriction ;
owl:onProperty :institutionWebsite ;
owl:minCardinality "0"^^xsd:nonNegativeInteger ],
[ rdf:type owl:Restriction ;
owl:onProperty :phone ;
owl:minCardinality "0"^^xsd:nonNegativeInteger ],
[ rdf:type owl:Restriction ;
owl:onProperty :address ;
owl:minCardinality "0"^^xsd:nonNegativeInteger ],
[ rdf:type owl:Restriction ;
owl:onProperty :email ;
owl:minCardinality "0"^^xsd:nonNegativeInteger ] ;
rdfs:comment "An institution that has data in Knora."@en .


### http://www.knora.org/ontology/knora-admin#User

:User
Expand Down Expand Up @@ -465,9 +377,6 @@
[ rdf:type owl:Restriction ;
owl:onProperty :projectRestrictedViewWatermark ;
owl:maxCardinality "1"^^xsd:nonNegativeInteger ],
[ rdf:type owl:Restriction ;
owl:onProperty :belongsToInstitution ;
owl:maxCardinality "1"^^xsd:nonNegativeInteger ],
[ rdf:type owl:Restriction ;
owl:onProperty :status ;
owl:cardinality "1"^^xsd:nonNegativeInteger ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
rdf:type owl:Ontology ;
rdfs:label "The Knora base ontology"@en ;
:attachedToProject knora-admin:SystemProject ;
:ontologyVersion "knora-base v28" .
:ontologyVersion "knora-base v29" .


#################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@ object OntologyConstants {
val GivenName: IRI = KnoraAdminPrefixExpansion + "givenName"
val FamilyName: IRI = KnoraAdminPrefixExpansion + "familyName"
val Password: IRI = KnoraAdminPrefixExpansion + "password"
val Address: IRI = KnoraAdminPrefixExpansion + "address"
val UsersActiveProject: IRI = KnoraAdminPrefixExpansion + "currentproject"
val PreferredLanguage: IRI = KnoraAdminPrefixExpansion + "preferredLanguage"
val IsInProject: IRI = KnoraAdminPrefixExpansion + "isInProject"
Expand All @@ -478,7 +477,6 @@ object OntologyConstants {
val ProjectLogo: IRI = KnoraAdminPrefixExpansion + "projectLogo"
val ProjectRestrictedViewSize: IRI = KnoraAdminPrefixExpansion + "projectRestrictedViewSize"
val ProjectRestrictedViewWatermark: IRI = KnoraAdminPrefixExpansion + "projectRestrictedViewWatermark"
val BelongsToInstitution: IRI = KnoraAdminPrefixExpansion + "belongsToInstitution"
val HasSelfJoinEnabled: IRI = KnoraAdminPrefixExpansion + "hasSelfJoinEnabled"

/* Group */
Expand All @@ -504,13 +502,6 @@ object OntologyConstants {
ProjectAdmin,
)

/* Institution */
val Institution: IRI = KnoraAdminPrefixExpansion + "Institution"
val InstitutionDescription: IRI = KnoraAdminPrefixExpansion + "institutionDescription"
val InstitutionName: IRI = KnoraAdminPrefixExpansion + "institutionName"
val InstitutionWebsite: IRI = KnoraAdminPrefixExpansion + "institutionWebsite"
val Phone: IRI = KnoraAdminPrefixExpansion + "phone"

/* Permissions */
val Permission: IRI = KnoraAdminPrefixExpansion + "Permission"
val AdministrativePermission: IRI = KnoraAdminPrefixExpansion + "AdministrativePermission"
Expand Down
2 changes: 1 addition & 1 deletion webapi/src/main/scala/org/knora/webapi/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ package object webapi {
* The version of `knora-base` and of the other built-in ontologies that this version of Knora requires.
* Must be the same as the object of `knora-base:ontologyVersion` in the `knora-base` ontology being used.
*/
val KnoraBaseVersion: String = "knora-base v28"
val KnoraBaseVersion: String = "knora-base v29"

/**
* `IRI` is a synonym for `String`, used to improve code readability.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
PluginForKnoraBaseVersion(versionNumber = 26, plugin = new MigrateOnlyBuiltInGraphs), // PR 3003
PluginForKnoraBaseVersion(versionNumber = 27, plugin = new MigrateOnlyBuiltInGraphs), // PR 3026
PluginForKnoraBaseVersion(versionNumber = 28, plugin = new MigrateOnlyBuiltInGraphs), // PR 3038
PluginForKnoraBaseVersion(versionNumber = 29, plugin = new UpgradePluginPR3110()),

Check warning on line 66 in webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/RepositoryUpdatePlan.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/RepositoryUpdatePlan.scala#L66

Added line #L66 was not covered by tests
// KEEP IT ON THE BOTTOM
// From "versionNumber = 6" don't use prBasedVersionString!
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
graphs = pluginsForNeededUpdates
.map(_.plugin.graphsForMigration)
.reduce(_ merge _)
_ <- ZIO.logInfo("Downloading repository file...")
_ <- ZIO.logInfo(s"Downloading .$graphs repository file..")

Check warning on line 207 in webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/RepositoryUpdater.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/RepositoryUpdater.scala#L207

Added line #L207 was not covered by tests
_ <- triplestoreService.downloadRepository(graphsBeforeMigrationFile, graphs)

// Run the transformations to produce an output file.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright © 2021 - 2024 Swiss National Data and Service Center for the Humanities and/or DaSCH Service Platform contributors.
* SPDX-License-Identifier: Apache-2.0
*/

package org.knora.webapi.store.triplestore.upgrade.plugins

import com.typesafe.scalalogging.Logger
import org.apache.jena.query.Dataset
import org.apache.jena.update.UpdateExecutionFactory
import org.apache.jena.update.UpdateFactory
import org.eclipse.rdf4j.sparqlbuilder.core.query.ModifyQuery

import org.knora.webapi.messages.util.rdf.*
import org.knora.webapi.store.triplestore.upgrade.UpgradePlugin

abstract class AbstractSparqlUpdatePlugin extends UpgradePlugin {

private val log: Logger = Logger(this.getClass)

Check warning on line 19 in webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/AbstractSparqlUpdatePlugin.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/AbstractSparqlUpdatePlugin.scala#L19

Added line #L19 was not covered by tests

def getQueries: List[ModifyQuery]

override def transform(model: RdfModel): Unit = {
val dataset = model.asInstanceOf[JenaModel].getDataset
getQueries.foreach(execute(dataset, _))

Check warning on line 25 in webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/AbstractSparqlUpdatePlugin.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/AbstractSparqlUpdatePlugin.scala#L24-L25

Added lines #L24 - L25 were not covered by tests
}

private def execute(dataset: Dataset, query: ModifyQuery) = {
val queryString = query.getQueryString

Check warning on line 29 in webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/AbstractSparqlUpdatePlugin.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/AbstractSparqlUpdatePlugin.scala#L29

Added line #L29 was not covered by tests
log.info(s"Executing SPARQL update: $queryString")
val update = UpdateFactory.create(queryString)
val qExec = UpdateExecutionFactory.create(update, dataset)
qExec.execute()

Check warning on line 33 in webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/AbstractSparqlUpdatePlugin.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/AbstractSparqlUpdatePlugin.scala#L31-L33

Added lines #L31 - L33 were not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright © 2021 - 2024 Swiss National Data and Service Center for the Humanities and/or DaSCH Service Platform contributors.
* SPDX-License-Identifier: Apache-2.0
*/

package org.knora.webapi.store.triplestore.upgrade.plugins

import org.eclipse.rdf4j.model.vocabulary.RDF
import org.eclipse.rdf4j.sparqlbuilder.core.SparqlBuilder.`var` as variable
import org.eclipse.rdf4j.sparqlbuilder.core.query.ModifyQuery
import org.eclipse.rdf4j.sparqlbuilder.core.query.*
import org.eclipse.rdf4j.sparqlbuilder.rdf.Rdf

import org.knora.webapi.messages.OntologyConstants.KnoraAdmin.KnoraAdminPrefixExpansion
import org.knora.webapi.slice.admin.AdminConstants
import org.knora.webapi.slice.admin.repo.rdf.Vocabulary
import org.knora.webapi.store.triplestore.upgrade.GraphsForMigration
import org.knora.webapi.store.triplestore.upgrade.MigrateSpecificGraphs

/**
* After removing `knora-admin:Institution` class and its properties from the knora-admin ontology this cleans up the DB.
* Removes all `knora-admin:Institution` classes from the `knora-admin` named graph.
*/
class UpgradePluginPR3110 extends AbstractSparqlUpdatePlugin {

override def graphsForMigration: GraphsForMigration =
MigrateSpecificGraphs.from(AdminConstants.adminDataNamedGraph)

Check warning on line 27 in webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/UpgradePluginPR3110.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/UpgradePluginPR3110.scala#L27

Added line #L27 was not covered by tests

private val removeAllInstitutions: ModifyQuery = {
val (s, p, o) = (variable("s"), variable("p"), variable("o"))

Check warning on line 30 in webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/UpgradePluginPR3110.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/UpgradePluginPR3110.scala#L30

Added line #L30 was not covered by tests
Queries
.MODIFY()
.prefix(Vocabulary.KnoraAdmin.NS, RDF.NS)
.delete(s.has(p, o))
.where(
s.isA(Rdf.iri(KnoraAdminPrefixExpansion, "Institution"))

Check warning on line 36 in webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/UpgradePluginPR3110.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/UpgradePluginPR3110.scala#L33-L36

Added lines #L33 - L36 were not covered by tests
.andHas(p, o)
.from(Vocabulary.NamedGraphs.knoraAdminIri),

Check warning on line 38 in webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/UpgradePluginPR3110.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/UpgradePluginPR3110.scala#L38

Added line #L38 was not covered by tests
)
}

private val removeAllBelongsToInstitutionTriples: ModifyQuery = {
val (s, o) = (variable("s"), variable("o"))
val belongsToInstitution = Rdf.iri(KnoraAdminPrefixExpansion, "belongsToInstitution")

Check warning on line 44 in webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/UpgradePluginPR3110.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/UpgradePluginPR3110.scala#L43-L44

Added lines #L43 - L44 were not covered by tests
Queries
.MODIFY()
.prefix(Vocabulary.KnoraAdmin.NS, RDF.NS)
.delete(s.has(belongsToInstitution, o))
.where(s.has(belongsToInstitution, o).from(Vocabulary.NamedGraphs.knoraAdminIri))

Check warning on line 49 in webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/UpgradePluginPR3110.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/UpgradePluginPR3110.scala#L47-L49

Added lines #L47 - L49 were not covered by tests
}

override def getQueries: List[ModifyQuery] = List(removeAllInstitutions, removeAllBelongsToInstitutionTriples)

Check warning on line 52 in webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/UpgradePluginPR3110.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/UpgradePluginPR3110.scala#L52

Added line #L52 was not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ object IriTestConstants {

object Class {
val AdministrativePermission: InternalIri = makeEntity(KnoraAdmin.Ontology, "AdministrativePermission")
val Institution: InternalIri = makeEntity(KnoraAdmin.Ontology, "Institution")
val Permission: InternalIri = makeEntity(KnoraAdmin.Ontology, "Permission")
}
}
Expand Down