Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make lastModificationDate mandatory and add UpgradePlugin
- Loading branch information
Showing
4 changed files
with
39 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...c/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/UpgradePluginPR2288.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) | ||
} | ||
} |