Skip to content
Snippets Groups Projects
Commit 895107c3 authored by Andreas Schärtl's avatar Andreas Schärtl
Browse files

app:set up /explore/node page

parent 0fb866c7
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,7 @@ public class Main { ...@@ -18,6 +18,7 @@ public class Main {
get("/queries", Routes.queries, new FreeMarkerEngine()); get("/queries", Routes.queries, new FreeMarkerEngine());
get("/explore", Routes.explore, new FreeMarkerEngine()); get("/explore", Routes.explore, new FreeMarkerEngine());
get("/explore/contributor/:contributor", Routes.exploreContributor, new FreeMarkerEngine()); get("/explore/contributor/:contributor", Routes.exploreContributor, new FreeMarkerEngine());
get("/explore/node/:base64uri", Routes.exploreNode, new FreeMarkerEngine());
internalServerError(Errors.internalServerError); internalServerError(Errors.internalServerError);
notFound(Errors.notFound); notFound(Errors.notFound);
......
...@@ -76,6 +76,21 @@ public class Routes { ...@@ -76,6 +76,21 @@ public class Routes {
return new ModelAndView(withGlobals(model), "explore_contributor.flt"); return new ModelAndView(withGlobals(model), "explore_contributor.flt");
}; };
public static final TemplateViewRoute exploreNode = (Request request, Response response) -> {
final Query query = Query.getSingleton();
final String base64uri = request.params("base64uri");
final String uri = Base64.decode(base64uri);
final List<IRI> uses = query.getUses(uri);
final Map<String, Object> model = new HashMap<>();
model.put("uri", uri);
model.put("uses", uses);
return new ModelAndView(withGlobals(model), "explore_node.flt");
};
/** /**
* Add some global values we always need to argument {@code model}. * Add some global values we always need to argument {@code model}.
* *
......
package info.mathhub.uloapi.query;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
public class IRIs {
private IRIs() {}
/**
* Create an {@link IRI} from argument {@code value}.
*
* @param value The argument to turn into an {@link IRI}.
* @return An {@link IRI} that contains argument {@code value}.
*/
public static IRI fromString(String value) {
if (value == null) {
throw new NullPointerException("argument value must not be null");
}
final ValueFactory valueFactory = SimpleValueFactory.getInstance();
return valueFactory.createIRI(value);
}
}
...@@ -167,4 +167,34 @@ public class Query { ...@@ -167,4 +167,34 @@ public class Query {
return GraphDB.execute(this.serverUrl, this.repository, operation); return GraphDB.execute(this.serverUrl, this.repository, operation);
} }
/**
* Return a list of works used by another given node.
*
* @param nodeuri The URI of the node.
*/
public List<IRI> getUses(String nodeuri) {
final GraphDB.Operation<List<IRI>> operation = (manager, repository, connection) -> {
final Set<IRI> uses = new HashSet<>();
final IRI subject = IRIs.fromString(nodeuri);
final RepositoryResult<Statement> result = connection.getStatements(subject, ULO.uses, null);
for (final Statement statement : result) {
final Value object = statement.getObject();
if (!(object instanceof IRI)) {
log.warn("found object that is not an IRI");
continue;
}
final IRI asIri = (IRI) object;
uses.add(asIri);
}
return new ArrayList<>(uses);
};
return GraphDB.execute(this.serverUrl, this.repository, operation);
}
} }
<#ftl output_format="HTML" auto_esc=false>
<#setting url_escaping_charset='UTF-8'>
<#include "base.flt">
<#macro page_title>
Explore Node
</#macro>
<#macro page_main>
<h2>Explore Node</h2>
<h3>URI</h3>
<ul>
<li>
<code>${uri}</code>
</li>
</ul>
<h3>Node uses...</h3>
<ul>
<#list uses as use>
<li>
<code>${use}</code>
</li>
</#list>
</ul>
</#macro>
<@display_page/>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment