Search in sources :

Example 1 with MalformedNanopubException

use of org.nanopub.MalformedNanopubException in project nanopub-server by tkuhn.

the class NanopubDb method getNanopub.

public Nanopub getNanopub(String artifactCode) {
    BasicDBObject query = new BasicDBObject("_id", artifactCode);
    DBCursor cursor = getNanopubCollection().find(query);
    if (!cursor.hasNext()) {
        return null;
    }
    String nanopubString = cursor.next().get("nanopub").toString();
    Nanopub np = null;
    try {
        np = new NanopubImpl(nanopubString, internalFormat);
    } catch (MalformedNanopubException ex) {
        throw new RuntimeException("Stored nanopub is not wellformed (this shouldn't happen)", ex);
    } catch (OpenRDFException ex) {
        throw new RuntimeException("Stored nanopub is corrupted (this shouldn't happen)", ex);
    }
    if (ServerConf.get().isCheckNanopubsOnGetEnabled() && !TrustyNanopubUtils.isValidTrustyNanopub(np)) {
        throw new RuntimeException("Stored nanopub is not trusty (this shouldn't happen)");
    }
    return np;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) DBCursor(com.mongodb.DBCursor) Nanopub(org.nanopub.Nanopub) OpenRDFException(org.openrdf.OpenRDFException) MalformedNanopubException(org.nanopub.MalformedNanopubException) NanopubImpl(org.nanopub.NanopubImpl)

Example 2 with MalformedNanopubException

use of org.nanopub.MalformedNanopubException in project nanopub-server by tkuhn.

the class NanopubPage method showIndex.

private void showIndex(Nanopub np) throws IOException {
    try {
        NanopubIndex npi = IndexUtils.castToIndex(np);
        getResp().setContentType("text/html");
        String title, headerTitle;
        if (npi.getName() == null) {
            if (npi.isIncomplete()) {
                headerTitle = "Part of Unnamed Index";
                title = "<em>Part of Unnamed Index</em>";
            } else {
                headerTitle = "Unnamed Index";
                title = "<em>Unnamed Index</em>";
            }
        } else {
            String escapedName = StringEscapeUtils.escapeHtml(npi.getName());
            if (npi.isIncomplete()) {
                headerTitle = "Part of Index '" + escapedName + "'";
                title = "<em>Part of Index</em> '" + escapedName + "'";
            } else {
                headerTitle = escapedName + " (Nanopub Index)";
                title = escapedName + " <em>(Nanopub Index)</em>";
            }
        }
        printHtmlHeader(headerTitle);
        println("<h1>" + title + "</h1>");
        println("<p>[ <a href=\".\" rel=\"home\">home</a> ]</p>");
        println("<h3>This:</h3>");
        println("<table><tbody>");
        printItem(npi.getUri());
        println("</tbody></table>");
        if (!npi.isIncomplete()) {
            if (npi.getDescription() != null) {
                println("<h3>Description:</h3>");
                println("<p>");
                println(StringEscapeUtils.escapeHtml(npi.getDescription()));
                println("</p>");
            }
            if (npi.getCreationTime() != null) {
                println("<h3>Creation Time:</h3>");
                println("<p>" + SimpleDateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(npi.getCreationTime().getTime()) + "</p>");
            }
            if (!npi.getCreators().isEmpty()) {
                println("<h3>Creators:</h3>");
                println("<ul>");
                for (URI uri : npi.getCreators()) {
                    println("<li><a href=\"" + uri + "\" rel=\"nofollow\">" + uri + "</a></li>");
                }
                println("</ul>");
            }
        }
        if (!npi.getSeeAlsoUris().isEmpty()) {
            println("<h3>See Also:</h3>");
            println("<ul>");
            for (URI uri : npi.getSeeAlsoUris()) {
                println("<li><a href=\"" + uri + "\" rel=\"nofollow\">" + uri + "</a></li>");
            }
            println("</ul>");
        }
        if (npi.getAppendedIndex() != null) {
            println("<h3>Appends:</h3>");
            println("<table><tbody>");
            printItem(npi.getAppendedIndex());
            println("</tbody></table>");
        }
        if (!npi.getSubIndexes().isEmpty()) {
            println("<h3>Includes as Sub-Indexes:</h3>");
            println("<table><tbody>");
            for (URI uri : npi.getSubIndexes()) {
                printItem(uri);
            }
            println("</tbody></table>");
        }
        if (!npi.getElements().isEmpty()) {
            println("<h3>Includes as Elements:</h3>");
            println("<table><tbody>");
            for (URI uri : npi.getElements()) {
                printItem(uri);
            }
            println("</tbody></table>");
        }
        printHtmlFooter();
    } catch (MalformedNanopubException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : NanopubIndex(org.nanopub.extra.index.NanopubIndex) MalformedNanopubException(org.nanopub.MalformedNanopubException) URI(org.openrdf.model.URI)

Aggregations

MalformedNanopubException (org.nanopub.MalformedNanopubException)2 BasicDBObject (com.mongodb.BasicDBObject)1 DBCursor (com.mongodb.DBCursor)1 Nanopub (org.nanopub.Nanopub)1 NanopubImpl (org.nanopub.NanopubImpl)1 NanopubIndex (org.nanopub.extra.index.NanopubIndex)1 OpenRDFException (org.openrdf.OpenRDFException)1 URI (org.openrdf.model.URI)1