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

knowledgepixels / nanodash / 17837235071

18 Sep 2025 05:58PM UTC coverage: 13.87%. Remained the same
17837235071

push

github

tkuhn
chore: Remove serialVersionUIDs

443 of 4022 branches covered (11.01%)

Branch coverage included in aggregate %.

1133 of 7341 relevant lines covered (15.43%)

0.68 hits per line

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

39.87
src/main/java/com/knowledgepixels/nanodash/component/NanodashLink.java
1
package com.knowledgepixels.nanodash.component;
2

3
import com.knowledgepixels.nanodash.User;
4
import com.knowledgepixels.nanodash.Utils;
5
import com.knowledgepixels.nanodash.connector.ios.DsConfig;
6
import com.knowledgepixels.nanodash.connector.ios.DsNanopubPage;
7
import com.knowledgepixels.nanodash.connector.pensoft.BdjConfig;
8
import com.knowledgepixels.nanodash.connector.pensoft.BdjNanopubPage;
9
import com.knowledgepixels.nanodash.connector.pensoft.RioConfig;
10
import com.knowledgepixels.nanodash.connector.pensoft.RioNanopubPage;
11
import com.knowledgepixels.nanodash.page.ExplorePage;
12
import com.knowledgepixels.nanodash.template.Template;
13
import com.knowledgepixels.nanodash.template.TemplateData;
14
import net.trustyuri.TrustyUriUtils;
15
import org.apache.commons.codec.Charsets;
16
import org.apache.wicket.Component;
17
import org.apache.wicket.behavior.AttributeAppender;
18
import org.apache.wicket.markup.html.basic.Label;
19
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
20
import org.apache.wicket.markup.html.link.ExternalLink;
21
import org.apache.wicket.markup.html.panel.Panel;
22
import org.apache.wicket.model.Model;
23
import org.apache.wicket.request.mapper.parameter.PageParameters;
24
import org.eclipse.rdf4j.model.IRI;
25
import org.eclipse.rdf4j.model.Statement;
26
import org.eclipse.rdf4j.model.ValueFactory;
27
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
28
import org.eclipse.rdf4j.model.vocabulary.RDFS;
29
import org.nanopub.Nanopub;
30
import org.nanopub.vocabulary.NP;
31
import org.nanopub.vocabulary.NTEMPLATE;
32

33
import java.net.URLEncoder;
34
import java.util.*;
35

36
/**
37
 * A Wicket component that creates a link to a nanopublication or an IRI.
38
 */
39
public class NanodashLink extends Panel {
40

41
    /**
42
     * Creates a link to a nanopublication or an IRI.
43
     *
44
     * @param id             the Wicket component ID
45
     * @param uri            the URI of the nanopublication or IRI
46
     * @param np             the nanopublication, or null if the link is not to a nanopublication
47
     * @param templateClass  the template class of the nanopublication, or null if the link is not to a nanopublication
48
     * @param objectPosition if true, the link is to an object position in a template, otherwise it is to a subject position
49
     * @param label          the label to display for the link, or null to derive it from the nanopublication or IRI
50
     */
51
    public NanodashLink(String id, String uri, Nanopub np, IRI templateClass, boolean objectPosition, String label) {
52
        super(id);
3✔
53

54
        final List<Template> templates = new ArrayList<>();
4✔
55
        final Map<IRI, String> labels = new HashMap<>();
4✔
56
        if (np != null) {
2!
57
            for (Statement st : np.getPubinfo()) {
11✔
58
                if (st.getPredicate().equals(NTEMPLATE.HAS_LABEL_FROM_API) || st.getPredicate().equals(RDFS.LABEL)) {
10!
59
                    labels.put((IRI) st.getSubject(), st.getObject().stringValue());
×
60
                }
61
            }
1✔
62
        }
63

64
        final TemplateData td = TemplateData.get();
2✔
65

66
        if (NTEMPLATE.ASSERTION_TEMPLATE.equals(templateClass)) {
4!
67
            IRI templateId = td.getTemplateId(np);
×
68
            if (templateId != null) {
×
69
                templates.add(td.getTemplate(templateId.stringValue()));
×
70
            }
71
        } else if (NTEMPLATE.PROVENANCE_TEMPLATE.equals(templateClass)) {
4!
72
            IRI templateId = td.getProvenanceTemplateId(np);
×
73
            if (templateId != null) {
×
74
                templates.add(td.getTemplate(templateId.stringValue()));
×
75
            }
76
        } else if (NTEMPLATE.PUBINFO_TEMPLATE.equals(templateClass)) {
4!
77
            Set<IRI> templateIds = td.getPubinfoTemplateIds(np);
×
78
            for (IRI templateId : templateIds) {
×
79
                templates.add(td.getTemplate(templateId.stringValue()));
×
80
            }
×
81
        }
82

83
        final IRI iriObj = vf.createIRI(uri);
4✔
84
        if (np != null && uri.equals(np.getUri().stringValue())) {
8!
85
            ExternalLink link = new ExternalLink("link", ExplorePage.MOUNT_PATH + "?id=" + URLEncoder.encode(uri, Charsets.UTF_8), "this");
×
86
            add(link);
×
87
            add(new Label("description", "this specific nanopublication"));
×
88
        } else if (np != null && uri.equals(np.getAssertionUri().stringValue())) {
8!
89
            ExternalLink link = new ExternalLink("link", ExplorePage.MOUNT_PATH + "?id=" + URLEncoder.encode(uri, Charsets.UTF_8), "this assertion");
×
90
            link.add(new AttributeAppender("class", " nanopub-assertion "));
×
91
            add(link);
×
92
            add(new Label("description", "the assertion of this specific nanopublication"));
×
93
        } else if (uri.equals(NP.HAS_ASSERTION.stringValue())) {
5!
94
            ExternalLink link = new ExternalLink("link", ExplorePage.MOUNT_PATH + "?id=" + URLEncoder.encode(uri, Charsets.UTF_8), "assertion");
×
95
            link.add(new AttributeAppender("class", " nanopub-assertion "));
×
96
            add(link);
×
97
            add(new Label("description", "links a nanopublication to its assertion"));
×
98
        } else if (uri.equals(NP.HAS_PROVENANCE.stringValue())) {
5!
99
            ExternalLink link = new ExternalLink("link", ExplorePage.MOUNT_PATH + "?id=" + URLEncoder.encode(uri, Charsets.UTF_8), "provenance");
×
100
            link.add(new AttributeAppender("class", " nanopub-provenance "));
×
101
            add(link);
×
102
            add(new Label("description", "links a nanopublication to its provenance"));
×
103
        } else if (uri.equals(NP.HAS_PUBINFO.stringValue())) {
5!
104
            ExternalLink link = new ExternalLink("link", ExplorePage.MOUNT_PATH + "?id=" + URLEncoder.encode(uri, Charsets.UTF_8), "pubinfo");
×
105
            link.add(new AttributeAppender("class", " nanopub-pubinfo "));
×
106
            add(link);
×
107
            add(new Label("description", "links a nanopublication to its pubinfo"));
×
108
        } else {
×
109
            if (label == null || label.isBlank()) {
2!
110
                label = IriItem.getShortNameFromURI(uri);
3✔
111
                if (iriObj.equals(User.getSignatureOwnerIri(np))) {
5!
112
                    if (objectPosition) {
×
113
                        label = "me (" + User.getShortDisplayName(iriObj) + ")";
×
114
                    } else {
115
                        label = "I (" + User.getShortDisplayName(iriObj) + ")";
×
116
                    }
117
                } else if (User.getName(iriObj) != null) {
3!
118
                    label = User.getShortDisplayName(iriObj);
×
119
                } else {
120
                    for (Template template : templates) {
6!
121
                        // TODO For pubinfo templates, we don't consider which triple came from which template (which is non-trivial):
122
                        String l = template.getLabel(iriObj);
×
123
                        if (l != null) {
×
124
                            label = l;
×
125
                            break;
×
126
                        }
127
                        l = labels.get(iriObj);
×
128
                        if (l != null) {
×
129
                            label = l;
×
130
                            break;
×
131
                        }
132
                    }
×
133
                }
134
            }
135
            String shortLabel = label.replaceFirst(" - [\\s\\S]*$", "");
5✔
136
            add(createLink("link", uri, shortLabel));
12✔
137
            String description = "";
2✔
138
            if (np != null && uri.startsWith(np.getUri().stringValue())) {
8!
139
                description = "This is a local identifier that was minted when the nanopublication was created.";
×
140
            }
141
            if (label.contains(" - ")) description = label.replaceFirst("^.* - ", "");
4!
142
            add(new Label("description", description));
13✔
143
        }
144
        add(Utils.getUriLink("uri", uri));
11✔
145
    }
1✔
146

147
    /**
148
     * <p>createLink.</p>
149
     *
150
     * @param markupId a {@link java.lang.String} object
151
     * @param uri      a {@link java.lang.String} object
152
     * @param label    a {@link java.lang.String} object
153
     * @return a {@link org.apache.wicket.Component} object
154
     */
155
    public static Component createLink(String markupId, String uri, String label) {
156
        boolean isNp = TrustyUriUtils.isPotentialTrustyUri(uri);
3✔
157
        // TODO Improve this
158
        if (isNp && uri.startsWith(DsConfig.get().getTargetNamespace())) {
2!
159
            return new BookmarkablePageLink<Void>(markupId, DsNanopubPage.class, new PageParameters().add("id", uri).add("mode", "final")).setBody(Model.of(label));
×
160
        } else if (isNp && uri.startsWith(BdjConfig.get().getTargetNamespace())) {
2!
161
            return new BookmarkablePageLink<Void>(markupId, BdjNanopubPage.class, new PageParameters().add("id", uri).add("mode", "final")).setBody(Model.of(label));
×
162
        } else if (isNp && uri.startsWith(RioConfig.get().getTargetNamespace())) {
2!
163
            return new BookmarkablePageLink<Void>(markupId, RioNanopubPage.class, new PageParameters().add("id", uri).add("mode", "final")).setBody(Model.of(label));
×
164
        } else {
165
            return new BookmarkablePageLink<Void>(markupId, ExplorePage.class, new PageParameters().add("id", uri).add("label", label)).setBody(Model.of(label));
18✔
166
        }
167
    }
168

169
    /**
170
     * Creates a link to a nanopublication or an IRI.
171
     *
172
     * @param id             the Wicket component ID
173
     * @param uri            the URI of the nanopublication or IRI
174
     * @param np             the nanopublication, or null if the link is not to a nanopublication
175
     * @param templateClass  the template class of the nanopublication, or null if the link is not to a nanopublication
176
     * @param objectPosition if true, the link is to an object position in a template, otherwise it is to a subject position
177
     */
178
    public NanodashLink(String id, String uri, Nanopub np, IRI templateClass, boolean objectPosition) {
179
        this(id, uri, np, templateClass, objectPosition, null);
8✔
180
    }
1✔
181

182
    /**
183
     * Creates a link to a nanopublication or an IRI.
184
     *
185
     * @param id  the Wicket component ID
186
     * @param uri the URI of the nanopublication or IRI
187
     * @param np  the nanopublication, or null if the link is not to a nanopublication
188
     */
189
    public NanodashLink(String id, String uri, Nanopub np) {
190
        this(id, uri, np, null, false);
×
191
    }
×
192

193
    /**
194
     * Creates a link to a nanopublication or an IRI.
195
     *
196
     * @param id  the Wicket component ID
197
     * @param uri the URI of the nanopublication or IRI
198
     */
199
    public NanodashLink(String id, String uri) {
200
        this(id, uri, null, null, false);
×
201
    }
×
202

203
    private static ValueFactory vf = SimpleValueFactory.getInstance();
3✔
204

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