diff --git a/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/html/Routes.java b/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/html/Routes.java index 9f1d9a6f56036776e9714d089f6b0f84d4c667a1..4e6b100dd85e6c09dbd13ba28602f5b75876c605 100644 --- a/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/html/Routes.java +++ b/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/html/Routes.java @@ -1,10 +1,10 @@ package info.mathhub.uloapi.html; import info.mathhub.uloapi.config.Config; +import info.mathhub.uloapi.query.Meta; import info.mathhub.uloapi.query.Query; import info.mathhub.uloapi.query.Statistics; import info.mathhub.uloapi.query.Timer; -import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Literal; import org.eclipse.rdf4j.model.Statement; import org.slf4j.Logger; @@ -82,10 +82,12 @@ public class Routes { final String base64uri = request.params("base64uri"); final String uri = Base64.decode(base64uri); + final Meta meta = query.getMeta(uri); final List<PrintableIRI> uses = PrintableIRI.convert(query.getUses(uri)); final Map<String, Object> model = new HashMap<>(); model.put("uri", uri); + model.put("meta", meta); model.put("uses", uses); return new ModelAndView(withGlobals(model), "explore_node.flt"); diff --git a/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/query/Meta.java b/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/query/Meta.java new file mode 100644 index 0000000000000000000000000000000000000000..cbd263d314057d73aa8b29714764f1184c1a48a0 --- /dev/null +++ b/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/query/Meta.java @@ -0,0 +1,50 @@ +package info.mathhub.uloapi.query; + +import info.mathhub.uloapi.ontology.ULO; +import org.eclipse.rdf4j.model.IRI; + +/** + * Contains meta information for a given URI. + */ +public class Meta { + /** + * IRI of the object. + */ + public IRI iri; + + /** + * {@link ULO#name} of the object. + */ + public String name; + + /** + * {@link ULO#sourceref} of the object. + */ + public String sourceref; + + /** + * {@link ULO#paratype} of this object. + */ + public String paratype; + + public String getName() { + return this.name; + } + + public String getSourceref() { + return this.sourceref; + } + + public String getParatype() { + return this.paratype; + } + + @Override + public String toString() { + return String.format( + "Meta(iri=%s name=%s sourceref=%s paratype=%s)", + this.iri.toString(), this.name, this.sourceref, this.paratype + ); + } + +} diff --git a/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/query/Query.java b/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/query/Query.java index 3b694472af0f8422ae274664e6c569088d3545d9..118db8b41510d7895f36720be4e99582e2f35d93 100644 --- a/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/query/Query.java +++ b/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/query/Query.java @@ -197,4 +197,49 @@ public class Query { return GraphDB.execute(this.serverUrl, this.repository, operation); } + + /** + * Try to create a {@link Meta} object for argument {@code nodeuri}. + * + * @param nodeuri The URI of the node for which we query the meta data. + * @return A {@link Meta} object for argument {@code nodeuri}. Never {@code null}, + * but the returned object can contain {@code null} fields. + */ + public Meta getMeta(String nodeuri) { + final GraphDB.Operation<Meta> operation = (manager, repository, connection) -> { + final IRI iri = IRIs.fromString(nodeuri); + + final Meta meta = new Meta(); + meta.iri = iri; + + meta.name = this.getSingleValueOrNull(iri, ULO.name); + meta.sourceref = this.getSingleValueOrNull(iri, ULO.sourceref); + meta.paratype = this.getSingleValueOrNull(iri, ULO.paratype); + + return meta; + }; + + return GraphDB.execute(this.serverUrl, this.repository, operation); + } + + /** + * Given subject and predicate, return the first matching object. + * + * @return The object as returned by the database, converted to a {@link String}. + * If no element was found, this method returns {@code null}. + */ + private String getSingleValueOrNull(IRI subject, IRI predicate) { + final GraphDB.Operation<String> operation = (manager, repository, connection) -> { + final RepositoryResult<Statement> result = connection.getStatements(subject, predicate, null); + + if (!result.hasNext()) { + return null; + } + + final Value object = result.next().getObject(); + return object.stringValue(); + }; + + return GraphDB.execute(this.serverUrl, this.repository, operation); + } } diff --git a/src/ulo-storage-applications/src/main/resources/spark/template/freemarker/explore_node.flt b/src/ulo-storage-applications/src/main/resources/spark/template/freemarker/explore_node.flt index 7d2caae0d490b73c03c7f430bfed2e361b1060b3..2cf4638fb15494e489e7ee2996b6e68c0fd8a9e5 100644 --- a/src/ulo-storage-applications/src/main/resources/spark/template/freemarker/explore_node.flt +++ b/src/ulo-storage-applications/src/main/resources/spark/template/freemarker/explore_node.flt @@ -19,6 +19,30 @@ </li> </ul> + <h3>Name</h3> + + <ul> + <li> + <code>${meta.name}</code> + </li> + </ul> + + <h3>Paragraph Type (<code>ulo:paratype</code>)</h3> + + <ul> + <li> + <code>${meta.paratype}</code> + </li> + </ul> + + <h3>Source Reference (<code>ulo:sourceref</code>)</h3> + + <ul> + <li> + <code>${meta.sourceref}</code> + </li> + </ul> + <h3>Node uses...</h3> <ul>