Skip to content

Commit

Permalink
fix for #156
Browse files Browse the repository at this point in the history
  • Loading branch information
manonthegithub committed Feb 8, 2024
1 parent ecf4fb9 commit b35cd21
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/main/scala/org/dbpedia/databus/SparqlClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,22 @@ object RdfConversions {
ShaclValidator.get()
.validate(Shapes.parse(shacl), model.getGraph)
)
def validateWithShacl(file: Array[Byte], modelLang: Lang, shaclGraph: Graph, fileCtx: Option[util.Context]): Try[ValidationReport] =
for {
(model, _) <- readModel(file, modelLang, fileCtx)
re <- validateWithShacl(model, shaclGraph)
} yield re

def validateWithShacl(file: Array[Byte], shaclData: Array[Byte], fileCtx: Option[util.Context], shaclCtx: Option[util.Context], modelLang: Lang): Try[ValidationReport] =
for {
(shaclGra, _) <- readModel(shaclData, DefaultShaclLang, shaclCtx)
(model, _) <- readModel(file, modelLang, fileCtx)
re <- validateWithShacl(model, shaclGra.getGraph)
re <- validateWithShacl(file, modelLang, shaclGra.getGraph, fileCtx)
} yield re

def validateWithShacl(file: Array[Byte], fileCtx: Option[util.Context], shaclUri: String, modelLang: Lang): Try[ValidationReport] =
for {
shaclGra <- Try(RDFDataMgr.loadGraph(shaclUri))
(model, _) <- readModel(file, modelLang, fileCtx)
re <- validateWithShacl(model, shaclGra)
re <- validateWithShacl(file, modelLang, shaclGra, fileCtx)
} yield re

def langToFormat(lang: Lang): RDFFormat = lang match {
Expand Down Expand Up @@ -427,10 +430,14 @@ object RdfConversions {

import org.apache.jena.riot.SysRIOT.fmtMessage

override def warning(message: String, line: Long, col: Long): Unit = {
warnings = warnings :+ Warning(fmtMessage(message, line, col))
defaultEH.warning(message, line, col)
}
override def warning(message: String, line: Long, col: Long): Unit =
// Fix for https://github.com/dbpedia/databus/issues/156, need to convert this to error
if (message.contains("Spaces are not legal in URIs/IRIs")) {
error(message, line, col)
} else {
warnings = warnings :+ Warning(fmtMessage(message, line, col))
defaultEH.warning(message, line, col)
}

override def error(message: String, line: Long, col: Long): Unit =
defaultEH.error(message, line, col)
Expand Down
14 changes: 14 additions & 0 deletions src/test/scala/org/dbpedia/databus/DatabusScalatraTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ class DatabusScalatraTest extends ScalatraFlatSpec with BeforeAndAfter {

}

"Shacl validation" should "report problems in input" in {

val file = "report_syntax_err.jsonld"
val sha = "test.shacl"
val bytes = Paths.get(getClass.getClassLoader.getResource(file).getFile).toFile
val shacl = Paths.get(getClass.getClassLoader.getResource(sha).getFile).toFile

post("/databus/shacl/validate", Map.empty, Map("shacl" -> shacl, "graph" -> bytes)) {
status should equal(400)
body should include("Bad IRI")
}

}

"File read" should "return 404" in {

get("/databus/graph/read?repo=kuckuck&path=pa/not_existing.jsonld") {
Expand Down

0 comments on commit b35cd21

Please sign in to comment.