• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

knowledgepixels / nanopub-registry / 45412980957

24 Nov 2026 02:20PM UTC coverage: 86.861% (+0.02%) from 86.839%
45412980957

push

github

web-flow
Merge pull request #235 from knowledgepixels/show-quota-authorities

feat: show the quota authorities on the main page and in the info JSON

1406 of 1702 branches covered (82.61%)

Branch coverage included in aggregate %.

3757 of 4242 relevant lines covered (88.57%)

13.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.81
src/main/java/com/knowledgepixels/registry/MainPage.java
1
package com.knowledgepixels.registry;
2

3
import com.mongodb.client.ClientSession;
4
import io.vertx.ext.web.RoutingContext;
5
import org.slf4j.Logger;
6
import org.slf4j.LoggerFactory;
7

8
import java.io.IOException;
9

10
import static com.knowledgepixels.registry.RegistryDB.*;
11

12
public class MainPage extends Page {
13

14
    private static final Logger logger = LoggerFactory.getLogger(MainPage.class);
12 ✔
15

16
    public static void show(RoutingContext context) {
17
        MainPage page;
18
        logger.info("Received main request: {}", context.request().path());
18 ✔
19
        try (ClientSession s = RegistryDB.getClient().startSession()) {
9 ✔
20
            s.startTransaction();
6 ✔
21
            page = new MainPage(s, context);
18 ✔
22
            page.show();
6 ✔
23
        } catch (IOException ex) {
×
24
            logger.warn("Failed to show main page for request {}: {} ({})", context.request().path(), ex.getMessage(), ex.getClass().getSimpleName(), ex);
×
25
        } finally {
26
            logger.debug("Ending response for main request: {}", context.request().path());
18 ✔
27
            context.response().end();
12 ✔
28
            // TODO Clean-up here?
29
        }
30
    }
3 ✔
31

32
    private MainPage(ClientSession mongoSession, RoutingContext context) {
33
        super(mongoSession, context);
12 ✔
34
    }
3 ✔
35

36
    protected void show() throws IOException {
37
        RoutingContext c = getContext();
9 ✔
38
        String format;
39
        String ext = getExtension();
9 ✔
40

41
        logger.debug("Preparing main page response for request: {} (ext={})", getFullRequest(), ext);
18 ✔
42

43
        if ("json".equals(ext)) {
12 ✔
44
            format = "application/json";
9 ✔
45
        } else if (ext == null || "html".equals(ext)) {
18 !
46
            String suppFormats = "application/json,text/html";
6 ✔
47
            format = Utils.getMimeType(c, suppFormats);
12 ✔
48
        } else {
3 ✔
49
            logger.warn("Invalid main request (unsupported extension) for {}: {}", getFullRequest(), ext);
18 ✔
50
            c.response().setStatusCode(400).setStatusMessage("Invalid request: " + getFullRequest());
27 ✔
51
            return;
3 ✔
52
        }
53

54
        if (getPresentationFormat() != null) {
9 !
55
            setRespContentType(getPresentationFormat());
×
56
            logger.debug("Overriding response content type with presentation format: {}", getPresentationFormat());
×
57
        } else {
58
            setRespContentType(format);
9 ✔
59
            logger.debug("Set response content type: {}", format);
12 ✔
60
        }
61

62
        if ("application/json".equals(format)) {
12 ✔
63
            logger.info("Serving main registry info as JSON for {}", getFullRequest());
15 ✔
64
            println(RegistryInfo.getLocal(mongoSession).asJson());
21 ✔
65
        } else {
66
            String status = serverInfo.get("status") != null ? serverInfo.get("status").toString() : "launching";
36 !
67
            printHtmlHeader("Nanopub Registry");
9 ✔
68
            println("<h1>Nanopub Registry</h1>");
9 ✔
69
            if (serverInfo.get("testInstance") != null && (Boolean) serverInfo.get("testInstance")) {
36 !
70
                println("<p style=\"color: red\">This is a test instance.</p>");
9 ✔
71
            }
72
            println("<h3>Formats</h3>");
9 ✔
73
            println("<p>");
9 ✔
74
            println("<a href=\".json\">.json</a> |");
9 ✔
75
            println("<a href=\".json.txt\">.json.txt</a>");
9 ✔
76
            println("</p>");
9 ✔
77
            println("<h3>Server</h3>");
9 ✔
78
            println("<ul>");
9 ✔
79
            println("<li><em>setupId:</em> " + serverInfo.get("setupId") + "</li>");
24 ✔
80
            println("<li><em>coverageTypes:</em> " + (serverInfo.get("coverageTypes") != null ? serverInfo.get("coverageTypes") : "all") + "</li>");
30 !
81
            println("<li><em>coverageAgents:</em> " + (serverInfo.get("coverageAgents") != null ? serverInfo.get("coverageAgents") : "viaSetting") + "</li>");
30 !
82
            // The pubkeys whose quota grants this registry applies, as configured right now.
83
            // They decide quotas here, and registries that list different ones can differ in
84
            // their trust state hash, so they are shown for anyone comparing registries.
85
            StringBuilder quotaAuthorities = new StringBuilder();
12 ✔
86
            for (String authority : AgentFilter.getQuotaAuthorities().stream().sorted().toList()) {
39 ✔
87
                quotaAuthorities.append(" <a href=\"/list/").append(authority).append("\"><code>").append(authority, 0, 10).append("</code></a>");
42 ✔
88
            }
3 ✔
89
            println("<li><em>quotaAuthorities:</em>" + (quotaAuthorities.isEmpty() ? " none" : quotaAuthorities) + "</li>");
30 ✔
90
            println("<li><em>optionalLoadEnabled:</em> " + !"false".equals(Utils.getEnv("REGISTRY_ENABLE_OPTIONAL_LOAD", null)) + "</li>");
36 ✔
91
            println("<li><em>trustCalculationEnabled:</em> " + !"false".equals(Utils.getEnv("REGISTRY_ENABLE_TRUST_CALCULATION", null)) + "</li>");
36 ✔
92
            println("<li><em>localInstance:</em> " + Utils.isLocalInstance() + "</li>");
12 ✔
93
            println("<li><em>status:</em> " + status + "</li>");
12 ✔
94
            println("<li><em>loadCounter:</em> " + getMaxValue(mongoSession, Collection.NANOPUBS.toString(), "counter") + "</li>");
30 ✔
95
            println("<li><em>nanopubCount:</em> " + collection(Collection.NANOPUBS.toString()).estimatedDocumentCount() + "</li>");
21 ✔
96
            println("<li><em>trustStateCounter:</em> " + serverInfo.get("trustStateCounter") + "</li>");
24 ✔
97
            Object lastTimeUpdate = serverInfo.get("lastTrustStateUpdate");
15 ✔
98
            if (lastTimeUpdate != null) {
6 !
99
                println("<li><em>lastTrustStateUpdate:</em> " + lastTimeUpdate.toString().replaceFirst("\\.[^.]*$", "") + "</li>");
27 ✔
100
            } else {
101
                println("<li><em>lastTrustStateUpdate:</em> null</li>");
×
102
            }
103
            Object trustStateHash = serverInfo.get("trustStateHash");
15 ✔
104
            if (trustStateHash != null) {
6 !
105
                trustStateHash = trustStateHash.toString().substring(0, 10);
18 ✔
106
            }
107
            println("<li><em>trustStateHash:</em> " + trustStateHash + "</li>");
15 ✔
108
            String oSetting = getValue(mongoSession, Collection.SETTING.toString(), "original").toString();
24 ✔
109
            println("<li><em>originalSetting:</em> <a href=\"/np/" + oSetting + "\"><code>" + oSetting.substring(0, 10) + "</code></a></li>");
24 ✔
110
            String cSetting = getValue(mongoSession, Collection.SETTING.toString(), "current").toString();
24 ✔
111
            println("<li><em>currentSetting:</em> <a href=\"/np/" + cSetting + "\"><code>" + cSetting.substring(0, 10) + "</code></a></li>");
24 ✔
112
            println("</ul>");
9 ✔
113

114
            if (!"false".equals(Utils.getEnv("REGISTRY_ENABLE_TRUST_CALCULATION", null))) {
18 ✔
115
                println("<h3>Agents</h3>");
9 ✔
116
                if (status.equals("launching") || status.equals("coreLoading")) {
24 !
117
                    println("<p><em>(loading...)</em></p>");
12 ✔
118
                } else {
119
                    println("<p>Count: " + collection(Collection.AGENTS.toString()).countDocuments(mongoSession) + "</p>");
27 ✔
120
                    println("<p><a href=\"/agents\">&gt; agents</a></pi>");
9 ✔
121
                }
122
            }
123

124
            println("<h3>Current Trust State</h3>");
9 ✔
125
            if (status.equals("launching") || status.equals("coreLoading")) {
24 !
126
                println("<p><em>(loading...)</em></p>");
12 ✔
127
            } else {
128
                println("<p>Accounts: " + collection(Collection.ACCOUNTS.toString()).countDocuments(mongoSession) + "</p>");
27 ✔
129
                println("<p><a href=\"/list\">&gt; current trust state</a></pi>");
9 ✔
130
            }
131

132
            println("<h3>Trust State History</h3>");
9 ✔
133
            println("<p>Retained snapshots: " + collection(Collection.TRUST_STATE_SNAPSHOTS.toString()).countDocuments(mongoSession) + "</p>");
27 ✔
134
            println("<p><a href=\"/trust-state\">&gt; trust state history</a></p>");
9 ✔
135

136
            println("<h3>Nanopubs</h3>");
9 ✔
137
            println("<p>Count: " + collection(Collection.NANOPUBS.toString()).estimatedDocumentCount() + "</p>");
21 ✔
138
            println("<p><a href=\"/nanopubs\">&gt; nanopubs</a></pi>");
9 ✔
139
            printHtmlFooter();
6 ✔
140
        }
141
    }
3 ✔
142

143
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc