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

knowledgepixels / nanodash / 17577716955

09 Sep 2025 09:11AM UTC coverage: 13.761% (+0.02%) from 13.745%
17577716955

push

github

web-flow
Merge pull request #247 from knowledgepixels/216-status-display-broken-for-nanopubs-without-date

Fix status display broken for nanopubs without date

408 of 3854 branches covered (10.59%)

Branch coverage included in aggregate %.

1083 of 6981 relevant lines covered (15.51%)

0.69 hits per line

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

0.0
src/main/java/com/knowledgepixels/nanodash/page/ExplorePage.java
1
package com.knowledgepixels.nanodash.page;
2

3
import com.knowledgepixels.nanodash.GrlcQuery;
4
import com.knowledgepixels.nanodash.NanopubElement;
5
import com.knowledgepixels.nanodash.QueryApiAccess;
6
import com.knowledgepixels.nanodash.Utils;
7
import com.knowledgepixels.nanodash.component.*;
8
import jakarta.servlet.http.HttpServletRequest;
9
import net.trustyuri.TrustyUriUtils;
10
import org.apache.wicket.markup.html.WebMarkupContainer;
11
import org.apache.wicket.markup.html.basic.Label;
12
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
13
import org.apache.wicket.markup.html.link.ExternalLink;
14
import org.apache.wicket.request.flow.RedirectToUrlException;
15
import org.apache.wicket.request.mapper.parameter.PageParameters;
16
import org.commonjava.mimeparse.MIMEParse;
17
import org.nanopub.Nanopub;
18
import org.nanopub.extra.security.SignatureUtils;
19
import org.nanopub.extra.services.ApiResponse;
20
import org.nanopub.vocabulary.NTEMPLATE;
21
import org.slf4j.Logger;
22
import org.slf4j.LoggerFactory;
23

24
import java.util.HashMap;
25
import java.util.Map;
26

27
/**
28
 * ExplorePage is a page that allows users to explore a specific Nanopublication or Thing.
29
 */
30
public class ExplorePage extends NanodashPage {
31

32
    private static final long serialVersionUID = 1L;
33
    private static final Logger logger = LoggerFactory.getLogger(ExplorePage.class);
×
34

35
    /**
36
     * The mount path for this page.
37
     */
38
    public static final String MOUNT_PATH = "/explore";
39

40
    /**
41
     * {@inheritDoc}
42
     */
43
    @Override
44
    public String getMountPath() {
45
        return MOUNT_PATH;
×
46
    }
47

48
    /**
49
     * Constructor for ExplorePage.
50
     *
51
     * @param parameters Page parameters containing the ID of the Nanopublication or Thing to explore.
52
     */
53
    public ExplorePage(final PageParameters parameters) {
54
        super(parameters);
×
55

56
        add(new TitleBar("titlebar", this, null));
×
57

58
        String tempRef = parameters.get("id").toString();
×
59

60
        WebMarkupContainer raw = new WebMarkupContainer("raw");
×
61
        add(raw);
×
62

63
        Map<String, String> nanopubParams = new HashMap<>();
×
64
        nanopubParams.put("ref", tempRef);
×
65
        Nanopub np = Utils.getAsNanopub(tempRef);
×
66
        boolean isNanopubId = (np != null);
×
67
        if (isNanopubId) {
×
68
            tempRef = np.getUri().stringValue();
×
69
        }
70
        if (!isNanopubId && tempRef.matches("^(.*[^A-Za-z0-9-_])?RA[A-Za-z0-9-_]{43}[^A-Za-z0-9-_].*$")) {
×
71
            np = Utils.getAsNanopub(tempRef.replaceFirst("^(.*[^A-Za-z0-9-_])?(RA[A-Za-z0-9-_]{43})[^A-Za-z0-9-_].*$", "$2"));
×
72
            if (np != null) {
×
73
                String npId = np.getUri().stringValue();
×
74
                tempRef = npId + tempRef.replaceFirst("^(.*[^A-Za-z0-9-_])?(RA[A-Za-z0-9-_]{43})([^A-Za-z0-9-_].*)$", "$3");
×
75
                Map<String, String> params = new HashMap<>();
×
76
                params.put("thing", tempRef);
×
77
                params.put("np", npId);
×
78
                ApiResponse resp = QueryApiAccess.forcedGet("get-latest-thing-nanopub", params);
×
79
                if (!resp.getData().isEmpty()) {
×
80
                    // TODO We take the most recent in case more than one latest version exists. Make other latest versions visible too.
81
                    npId = resp.getData().get(0).get("latestVersion");
×
82
                }
83
                np = Utils.getAsNanopub(npId);
×
84
            }
85
        }
86
        if (np == null) {
×
87
            raw.setVisible(false);
×
88
            add(new Label("nanopub-header", ""));
×
89
            add(new Label("nanopub", ""));
×
90
            add(new WebMarkupContainer("use-template").setVisible(false));
×
91
            add(new WebMarkupContainer("run-query").setVisible(false));
×
92
        } else {
93

94
            // Check whether we should redirect to Nanopub Registry for machine-friendly formats:
95
            String mimeType = Utils.TYPE_HTML;
×
96
            try {
97
                HttpServletRequest httpRequest = (HttpServletRequest) getRequest().getContainerRequest();
×
98
                mimeType = MIMEParse.bestMatch(Utils.SUPPORTED_TYPES_LIST, httpRequest.getHeader("Accept"));
×
99
            } catch (Exception ex) {
×
100
                logger.error("Error determining MIME type from Accept header.", ex);
×
101
            }
×
102
            if (!mimeType.equals(Utils.TYPE_HTML)) {
×
103
                logger.info("Non-HTML content type: {}", mimeType);
×
104
                // TODO Make this registry URL configurable/dynamic:
105
                String redirectUrl = Utils.getMainRegistryUrl() + "np/" + TrustyUriUtils.getArtifactCode(np.getUri().stringValue());
×
106
                logger.info("Redirecting to: {}", redirectUrl);
×
107
                throw new RedirectToUrlException(redirectUrl, 302);
×
108
            }
109

110
            String nanopubHeaderLabel = "<h4>%s</h4>";
×
111
            if (isNanopubId) {
×
112
                nanopubHeaderLabel = String.format(nanopubHeaderLabel, "Nanopublication");
×
113
            } else {
114
                nanopubHeaderLabel = String.format(nanopubHeaderLabel, "Minted in Nanopublication");
×
115
            }
116
            add(new Label("nanopub-header", nanopubHeaderLabel).setEscapeModelStrings(false));
×
117
            add(new NanopubItem("nanopub", NanopubElement.get(np)));
×
118
            String url = "http://np.knowledgepixels.com/" + TrustyUriUtils.getArtifactCode(np.getUri().stringValue());
×
119
            raw.add(new ExternalLink("trig-txt", url + ".trig.txt"));
×
120
            raw.add(new ExternalLink("jsonld-txt", url + ".jsonld.txt"));
×
121
            raw.add(new ExternalLink("nq-txt", url + ".nq.txt"));
×
122
            raw.add(new ExternalLink("xml-txt", url + ".xml.txt"));
×
123
            raw.add(new ExternalLink("trig", url + ".trig"));
×
124
            raw.add(new ExternalLink("jsonld", url + ".jsonld"));
×
125
            raw.add(new ExternalLink("nq", url + ".nq"));
×
126
            raw.add(new ExternalLink("xml", url + ".xml"));
×
127
            if (Utils.isNanopubOfClass(np, NTEMPLATE.ASSERTION_TEMPLATE)) {
×
128
                add(new WebMarkupContainer("use-template").add(new BookmarkablePageLink<Void>("template-link", PublishPage.class, new PageParameters().add("template", np.getUri()))));
×
129
            } else {
130
                add(new WebMarkupContainer("use-template").setVisible(false));
×
131
            }
132
            if (Utils.isNanopubOfClass(np, GrlcQuery.GRLC_QUERY_CLASS)) {
×
133
                add(new WebMarkupContainer("run-query").add(new BookmarkablePageLink<Void>("query-link", QueryPage.class, new PageParameters().add("id", np.getUri()))));
×
134
            } else {
135
                add(new WebMarkupContainer("run-query").setVisible(false));
×
136
            }
137
        }
138

139
        final String ref = tempRef;
×
140
        final String shortName;
141
        if (parameters.get("label").isEmpty()) {
×
142
            shortName = IriItem.getShortNameFromURI(ref);
×
143
        } else {
144
            shortName = parameters.get("label").toString();
×
145
        }
146
        add(new Label("pagetitle", shortName + " (explore) | nanodash"));
×
147
        add(new Label("termname", shortName));
×
148
        add(new ExternalLink("urilink", ref, ref));
×
149
        if (isNanopubId && SignatureUtils.seemsToHaveSignature(np)) {
×
150
            add(StatusLine.createComponent("statusline", ref));
×
151
        } else {
152
            add(new Label("statusline").setVisible(false));
×
153
        }
154
        add(ThingListPanel.createComponent("classes-panel", ThingListPanel.Mode.CLASSES, ref, "<em>Searching for classes...</em>"));
×
155
        if (isNanopubId) {
×
156
            add(new Label("instances-panel").setVisible(false));
×
157
            add(new Label("parts-panel").setVisible(false));
×
158
            add(new Label("templates-panel").setVisible(false));
×
159
        } else {
160
            add(ThingListPanel.createComponent("instances-panel", ThingListPanel.Mode.INSTANCES, ref, "<em>Searching for instances...</em>"));
×
161
            add(ThingListPanel.createComponent("parts-panel", ThingListPanel.Mode.PARTS, ref, "<em>Searching for parts...</em>"));
×
162
            add(ThingListPanel.createComponent("templates-panel", ThingListPanel.Mode.TEMPLATES, ref, "<em>Searching for templates...</em>"));
×
163
        }
164
        add(ExploreDataTable.createComponent("reftable", ref));
×
165
    }
×
166

167
}
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