Skip to content

Commit

Permalink
make lastModificationDate mandatory and add UpgradePlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
seakayone committed Nov 29, 2022
1 parent eaae30b commit 21054c9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
4 changes: 2 additions & 2 deletions knora-ontologies/knora-base.ttl
Expand Up @@ -19,7 +19,7 @@
rdf:type owl:Ontology ;
rdfs:label "The Knora base ontology"@en ;
:attachedToProject knora-admin:SystemProject ;
:ontologyVersion "knora-base v25" .
:ontologyVersion "knora-base v26" .


#################################################################
Expand Down Expand Up @@ -1820,7 +1820,7 @@
owl:cardinality "1"^^xsd:nonNegativeInteger ],
[ rdf:type owl:Restriction ;
owl:onProperty :lastModificationDate ;
owl:maxCardinality "1"^^xsd:nonNegativeInteger ],
owl:cardinality "1"^^xsd:nonNegativeInteger ],
[ rdf:type owl:Restriction ;
owl:onProperty :deleteDate ;
owl:maxCardinality "1"^^xsd:nonNegativeInteger ],
Expand Down
2 changes: 1 addition & 1 deletion webapi/src/main/scala/org/knora/webapi/package.scala
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 v25"
val KnoraBaseVersion: String = "knora-base v26"

/**
* `IRI` is a synonym for `String`, used to improve code readability.
Expand Down
@@ -1,7 +1,6 @@
package org.knora.webapi.store.triplestore.upgrade

import com.typesafe.scalalogging.Logger

import org.knora.webapi.store.triplestore.upgrade.plugins._

/**
Expand Down Expand Up @@ -53,7 +52,8 @@ object RepositoryUpdatePlan {
PluginForKnoraBaseVersion(versionNumber = 22, plugin = new UpgradePluginPR2081(log)),
PluginForKnoraBaseVersion(versionNumber = 23, plugin = new UpgradePluginPR2094(log)),
PluginForKnoraBaseVersion(versionNumber = 24, plugin = new NoopPlugin), // PR 2076
PluginForKnoraBaseVersion(versionNumber = 25, plugin = new UpgradePluginPR2255(log))
PluginForKnoraBaseVersion(versionNumber = 25, plugin = new UpgradePluginPR2255(log)),
PluginForKnoraBaseVersion(versionNumber = 26, plugin = new UpgradePluginPR2288(log))
// KEEP IT ON THE BOTTOM
// From "versionNumber = 6" don't use prBasedVersionString!
)
Expand Down
@@ -0,0 +1,34 @@
package org.knora.webapi.store.triplestore.upgrade.plugins

import com.typesafe.scalalogging.Logger
import org.knora.webapi.messages.util.rdf.{RdfFeatureFactory, RdfModel, Statement}
import org.knora.webapi.store.triplestore.upgrade.UpgradePlugin

import scala.concurrent.duration.DurationLong

class UpgradePluginPR2288(log: Logger) extends UpgradePlugin {
private val nodeFactory = RdfFeatureFactory.getRdfNodeFactory()

private val creationDateIri = nodeFactory.makeIriNode("http://www.knora.org/ontology/knora-base#creationDate")
private val lastModDateIri = nodeFactory.makeIriNode("http://www.knora.org/ontology/knora-base#lastModificationDate")

override def transform(model: RdfModel): Unit = {
val t0 = System.nanoTime()
log.info(s"Starting ${this.getClass.getSimpleName}")

val statementsWithCreationDateIri =
LazyList.from(model.find(subj = None, pred = Some(creationDateIri), obj = None))

val subjectHasNoLastModificationDate: Statement => Boolean = statement =>
model.find(subj = Some(statement.subj), pred = Some(lastModDateIri), obj = None).isEmpty

val newStatements = statementsWithCreationDateIri
.filter(subjectHasNoLastModificationDate)
.map(s => nodeFactory.makeStatement(s.subj, lastModDateIri, s.obj, s.context))

model.addStatements(newStatements.toSet)

log.info(s"Created ${newStatements.size} new statements:\n${newStatements.mkString("++ ", "\n", "")}")
log.info(s"Finished ${this.getClass.getSimpleName} in " + (System.nanoTime() - t0).nanos.toCoarsest.toString())
}
}

0 comments on commit 21054c9

Please sign in to comment.