Commit 18c00ddc authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Catch resource without type error!

parent 4e2f5c34
Pipeline #16451 passed with stage
in 2 minutes and 24 seconds
package ch.memobase.rdf
class InvalidInputException(message: String) : Exception(message)
......@@ -24,8 +24,12 @@ class MemobaseModel : ModelCom(Factory.createGraphMem()) {
fun listRicoResourceSubjects(): Iterable<RicoResource> {
return this.listSubjects().mapWith {
RicoResource(it)
}.toList()
try {
RicoResource(it)
} catch (ex: InvalidInputException) {
null
}
}.toList().filterNotNull()
}
override fun toString(): String {
......
......@@ -8,6 +8,7 @@ import org.apache.jena.rdf.model.RDFNode
import org.apache.jena.rdf.model.Statement
import org.apache.jena.riot.RDFDataMgr
import org.apache.jena.riot.RDFFormat
import org.apache.logging.log4j.LogManager
import org.memobase.rdf.RDF
import org.memobase.rdf.RICO
......@@ -17,9 +18,21 @@ class RicoResource(val resource: Resource) {
resource.addProperty(RDF.type, rdfType).addProperty(RICO.type, ricoType)
)
private var rdfType = resource.getProperty(RDF.type).resource
private val log = LogManager.getLogger("RicoResource")
private var rdfType = retrieveRdfType(resource)
private val ricoType: String? = resource.getProperty(RICO.type)?.string
private fun retrieveRdfType(resource: Resource): Resource {
return try {
resource.getProperty(RDF.type).resource
} catch (ex: IllegalStateException) {
val message = "Resource without a ricoType: $resource." + ex.localizedMessage
log.error(message)
throw InvalidInputException(message)
}
}
private fun getLabel(): String {
return when (rdfType) {
RICO.Identifier -> getStringLiteral(RICO.identifier).orEmpty()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment