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

knowledgepixels / nanodash / 17852532121

19 Sep 2025 08:10AM UTC coverage: 13.568% (-0.3%) from 13.87%
17852532121

push

github

tkuhn
feat: Switch to QueryRef provided by nanopub, using multimap

428 of 4008 branches covered (10.68%)

Branch coverage included in aggregate %.

1104 of 7283 relevant lines covered (15.16%)

0.68 hits per line

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

0.0
src/main/java/com/knowledgepixels/nanodash/component/StatusLine.java
1
package com.knowledgepixels.nanodash.component;
2

3
import java.net.URLEncoder;
4
import java.util.ArrayList;
5
import java.util.List;
6

7
import org.apache.wicket.Component;
8
import org.apache.wicket.markup.html.basic.Label;
9
import org.apache.wicket.markup.html.panel.Panel;
10
import org.nanopub.extra.services.ApiResponse;
11
import org.nanopub.extra.services.ApiResponseEntry;
12
import org.nanopub.extra.services.QueryRef;
13

14
import com.github.jsonldjava.shaded.com.google.common.base.Charsets;
15

16
import net.trustyuri.TrustyUriUtils;
17

18
/**
19
 * A component that displays the status of a nanopublication.
20
 */
21
public class StatusLine extends Panel {
22

23
    /**
24
     * Creates a new StatusLine component.
25
     *
26
     * @param markupId the Wicket markup ID for this component
27
     * @param npId     the nanopublication ID to check for newer versions
28
     * @return a new StatusLine component
29
     */
30
    public static Component createComponent(String markupId, String npId) {
31
        // TODO Use the query cache here but with quicker refresh interval?
32
        ApiResultComponent c = new ApiResultComponent("statusline", new QueryRef("get-newer-versions-of-np", "np", npId)) {
×
33

34
            @Override
35
            public Component getApiResultComponent(String markupId, ApiResponse response) {
36
                return new StatusLine(markupId, npId, response);
×
37
            }
38

39
        };
40
        c.setWaitComponentHtml("<h4>Status</h4><div>" + ApiResultComponent.getWaitIconHtml() + "</div>");
×
41
        return c;
×
42
    }
43

44
    /**
45
     * Constructs a StatusLine component with the given markup ID, nanopublication ID, and API response.
46
     *
47
     * @param markupId the Wicket markup ID for this component
48
     * @param npId     the nanopublication ID to check for newer versions
49
     * @param response the API response containing data about newer versions or retractions
50
     */
51
    public StatusLine(String markupId, String npId, ApiResponse response) {
52
        super(markupId);
×
53
        List<String> latest = new ArrayList<>();
×
54
        List<String> retractions = new ArrayList<>();
×
55
        for (ApiResponseEntry e : response.getData()) {
×
56
            String newerVersion = e.get("newerVersion");
×
57
            String retractedBy = e.get("retractedBy");
×
58
            String supersededBy = e.get("supersededBy");
×
59
            if (retractedBy.isEmpty() && supersededBy.isEmpty()) {
×
60
                latest.add(newerVersion);
×
61
            } else if (!retractedBy.isEmpty() && supersededBy.isEmpty()) {
×
62
                retractions.add(retractedBy);
×
63
            }
64
        }
×
65
        String text = null;
×
66
        // TODO Improve HTML/link generation below (do it with Wicket Java code):
67
        if (latest.isEmpty() && retractions.isEmpty()) {
×
68
            text = "<em>This nanopublication doesn't seem to be properly published (yet). This can take a minute or two for new nanopublications.</em>";
×
69
        } else if (latest.size() == 1) {
×
70
            String l = latest.getFirst();
×
71
            if (l.equals(npId)) {
×
72
                text = "This is the latest version.";
×
73
            } else {
74
                text = "This nanopublication has a <strong>newer version</strong>: " + getLink(l);
×
75
            }
76
        } else if (latest.size() > 1) {
×
77
            text = "This nanopublication has <strong>newer versions</strong>:";
×
78
            for (String l : latest) {
×
79
                text += " " + getLink(l);
×
80
            }
×
81
        } else {
82
            text = "This nanopublication has been <strong>retracted</strong>:";
×
83
            for (String r : retractions) {
×
84
                text += " " + getLink(r);
×
85
            }
×
86
        }
87
        add(new Label("statusline", text).setEscapeModelStrings(false));
×
88
    }
×
89

90
    private static String getLink(String npId) {
91
        String shortLabel = TrustyUriUtils.getArtifactCode(npId).substring(0, 10);
×
92
        String encodedLink = URLEncoder.encode(npId, Charsets.UTF_8);
×
93
        return "<a href=\"/explore?id=" + encodedLink + "\">" + shortLabel + "</a>";
×
94
    }
95

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

© 2026 Coveralls, Inc