Updated Branches: refs/heads/develop e7b3ccad4 -> 593ea4fa1
MARMOTTA-239: Added some more info (size) and download links to the context panel. Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/9a3913dc Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/9a3913dc Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/9a3913dc Branch: refs/heads/develop Commit: 9a3913dcae6da41958fb00012a98873a9f3f78e9 Parents: e7b3cca Author: Jakob Frank <[email protected]> Authored: Tue Dec 17 12:02:41 2013 +0100 Committer: Jakob Frank <[email protected]> Committed: Tue Dec 17 12:02:41 2013 +0100 ---------------------------------------------------------------------- .../core/api/triplestore/ContextService.java | 7 ++ .../triplestore/ContextServiceImpl.java | 21 +++++ .../triplestore/ContextWebService.java | 5 +- .../src/main/resources/web/admin/contexts.html | 90 ++++++++++++++------ 4 files changed, 93 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/marmotta/blob/9a3913dc/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/triplestore/ContextService.java ---------------------------------------------------------------------- diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/triplestore/ContextService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/triplestore/ContextService.java index d224654..57d8d36 100644 --- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/triplestore/ContextService.java +++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/triplestore/ContextService.java @@ -158,6 +158,12 @@ public interface ContextService { * @return */ String getContextLabel(URI context); + + /** + * Return the number of triples for the context. + * @param context + */ + long getContextSize(org.openrdf.model.URI context); /** * Import content into the context @@ -186,4 +192,5 @@ public interface ContextService { */ boolean removeContext(URI context); + } http://git-wip-us.apache.org/repos/asf/marmotta/blob/9a3913dc/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/triplestore/ContextServiceImpl.java ---------------------------------------------------------------------- diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/triplestore/ContextServiceImpl.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/triplestore/ContextServiceImpl.java index ea1d698..63c958e 100644 --- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/triplestore/ContextServiceImpl.java +++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/triplestore/ContextServiceImpl.java @@ -314,6 +314,27 @@ public class ContextServiceImpl implements ContextService { } return null; } + + /** + * Return the number of triples for the context. + * @param context + */ + @Override + public long getContextSize(URI context) { + try { + RepositoryConnection conn = sesameService.getConnection(); + try { + conn.begin(); + return conn.size(context); + } finally { + conn.commit(); + conn.close(); + } + } catch (RepositoryException e) { + handleRepositoryException(e, ContextServiceImpl.class); + } + return 0; + } /** * Import content into the context http://git-wip-us.apache.org/repos/asf/marmotta/blob/9a3913dc/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/ContextWebService.java ---------------------------------------------------------------------- diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/ContextWebService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/ContextWebService.java index 18605e9..14b2064 100644 --- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/ContextWebService.java +++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/ContextWebService.java @@ -76,11 +76,12 @@ public class ContextWebService { } return Response.ok().entity(res).build(); } else { - ArrayList<Map<String,String>> result = new ArrayList<Map<String, String>>(); + ArrayList<Map<String,Object>> result = new ArrayList<>(); for(org.openrdf.model.URI r : contextService.listContexts(filter != null)) { - Map<String,String> ctxDesc = new HashMap<String, String>(); + Map<String,Object> ctxDesc = new HashMap<String, Object>(); ctxDesc.put("uri",r.stringValue()); ctxDesc.put("label", contextService.getContextLabel(r)); + ctxDesc.put("size", contextService.getContextSize(r)); result.add(ctxDesc); } return Response.ok().entity(result).build(); http://git-wip-us.apache.org/repos/asf/marmotta/blob/9a3913dc/platform/marmotta-core/src/main/resources/web/admin/contexts.html ---------------------------------------------------------------------- diff --git a/platform/marmotta-core/src/main/resources/web/admin/contexts.html b/platform/marmotta-core/src/main/resources/web/admin/contexts.html index 192309a..7a0127f 100644 --- a/platform/marmotta-core/src/main/resources/web/admin/contexts.html +++ b/platform/marmotta-core/src/main/resources/web/admin/contexts.html @@ -18,7 +18,7 @@ --> <html> -<head> + <head> <!--###BEGIN_HEAD###--> <title>Contexts</title> <link type="text/css" rel="stylesheet" href="../public/js/widgets/configurator/style.css" /> @@ -37,14 +37,19 @@ in SPARQL. </p> <p> - Currently there are <span id="contexts-count">0</span> contexts in Marmotta: + Currently there are <strong><span id="contexts-count">0 contexts</span></strong> in Marmotta: </p> <table id="contexts" class="simple_table"> - <tr class="subtitle"> - <th>Context</th> - <th>Label</th> - <th> </th> - </tr> + <thead> + <tr class="subtitle"> + <th>Label</th> + <th>Context</th> + <th>Size</th> + <th>Download</th> + <th> </th> + </tr> + </thead> + <tbody></tbody> </table> <script type="text/javascript" src="../../webjars/jquery/1.8.2/jquery.min.js"></script> @@ -52,36 +57,65 @@ jQuery(document).ready(function() { function appendContext(ctx, id) { - var uri = ctx["uri"]; - var label = (ctx["label"] ? ctx["label"] : ""); - $("table#contexts > tbody:last").append("<tr id=\"context" + id + "\"><td><a href=\"" + uri + "\">" + uri + "</a></td><td>" + label + "</td><td><a href=\"#contexts\" class=\"deleteContext\">delete</a></td></tr>"); + var uri = ctx["uri"], + label = (ctx["label"] ? ctx["label"] : uri.replace(/.*[\/#](.*)/, "$1")), + size = ctx["size"]; + + $("<tr>", {"id": "context_"+id}) + .append($("<td>", {"text": label})) + .append($("<td>").append($("<a>", {"text": uri, "href": uri}))) + .append($("<td>").append(size?$("<span>", {"text":size+" triple"+(size==1?"":"s")}):$("<em>", {"text":"unknown"}))) + .append(appendDownloadLinks($("<td>"), ctx)) + .append($("<td>").append($("<button>", {"text": "delete"}).click(deleteContext(uri, id, size)))) + .appendTo($("table#contexts > tbody:last")); + } + function appendDownloadLinks(target, ctx) { + function dl(format) { + return _SERVER_URL + "export/download?" + + "context=" + encodeURIComponent(ctx["uri"]) + + "&format=" + encodeURIComponent(format); + } + return target + .append($("<a>", {"text": "rdf+xml", "href": dl("application/rdf+xml")})) + .append(" ") + .append($("<a>", {"text": "turtle", "href": dl("text/turtle")})) + .append(" ") + .append($("<a>", {"text": "ld+json", "href": dl("application/ld+json")})); } - function deleteContext(uri, id) { - $.ajax({ - url: "../../context?graph=" + encodeURIComponent(uri), - type: "DELETE", - success: function(result) { - alert("Context " + uri + " deleted!"); - $("tr#" + id).remove(); - } - }); + function deleteContext(uri, id, size) { + var question = "This will DELETE context <" + uri + ">"; + if (size) { + question += " and all " + size + " triple" + (size==1?"":"s") + " contained in it"; + } + return function() { + if (!confirm(question)) return; + $.ajax({ + url: "../../context?graph=" + encodeURIComponent(uri), + type: "DELETE", + success: function(result) { + alert("Context " + uri + " deleted!"); + $("tr#context_" + id).slideUp(function() { + $(this).remove(); + var c = $("span#contexts-count"), + count = c.attr("data-count") -1; + c.attr("data-count", count) + .text(count + " context" + (count==1?"":"s")); + }); + } + }); + } } $.getJSON("../../context/list", {labels:"true"}, function(data) { var count = 0; for (i in data) { - appendContext(data[i], count); - $("span#contexts-count").html(++count); + appendContext(data[i], count++); } - $("a.deleteContext").click(function() { - var row = $(this).closest("td").closest("tr"); - var uri = row.find("td:first").text(); - var id = row.attr("id"); - deleteContext(uri, id); - }); + $("span#contexts-count") + .attr("data-count", count) + .text(count + " context" + (count==1?"":"s")); }); - }); </script> <!--###END_CONTENT###-->
