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

knowledgepixels / nanodash / 17211438187

25 Aug 2025 02:13PM UTC coverage: 12.474% (+0.03%) from 12.446%
17211438187

push

github

ashleycaselli
build(deps): update org.apache.maven.plugins:maven-compiler-plugin to v3.14.0

330 of 3766 branches covered (8.76%)

Branch coverage included in aggregate %.

982 of 6752 relevant lines covered (14.54%)

0.64 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 com.knowledgepixels.nanodash.template.Template;
9
import jakarta.servlet.http.HttpServletRequest;
10
import net.trustyuri.TrustyUriUtils;
11
import org.apache.wicket.markup.html.WebMarkupContainer;
12
import org.apache.wicket.markup.html.basic.Label;
13
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
14
import org.apache.wicket.markup.html.link.ExternalLink;
15
import org.apache.wicket.request.flow.RedirectToUrlException;
16
import org.apache.wicket.request.mapper.parameter.PageParameters;
17
import org.commonjava.mimeparse.MIMEParse;
18
import org.nanopub.Nanopub;
19
import org.nanopub.extra.security.SignatureUtils;
20
import org.nanopub.extra.services.ApiResponse;
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
            }
×
101
            if (!mimeType.equals(Utils.TYPE_HTML)) {
×
102
                logger.info("Non-HTML content type: " + mimeType);
×
103
                // TODO Make this registry URL configurable/dynamic:
104
                String redirectUrl = Utils.getMainRegistryUrl() + "np/" + TrustyUriUtils.getArtifactCode(np.getUri().stringValue());
×
105
                logger.info("Redirecting to: " + redirectUrl);
×
106
                throw new RedirectToUrlException(redirectUrl, 302);
×
107
            }
108

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

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

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