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

knowledgepixels / nanodash / 18220763586

03 Oct 2025 11:16AM UTC coverage: 13.734% (+0.01%) from 13.724%
18220763586

push

github

tkuhn
style: Remove "I"/"me" and just show user name

446 of 4106 branches covered (10.86%)

Branch coverage included in aggregate %.

1154 of 7544 relevant lines covered (15.3%)

0.68 hits per line

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

40.91
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 label          the label to display for the link, or null to derive it from the nanopublication or IRI
49
     */
50
    public NanodashLink(String id, String uri, Nanopub np, IRI templateClass, String label) {
51
        super(id);
3✔
52

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

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

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

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

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

165
    /**
166
     * Creates a link to a nanopublication or an IRI.
167
     *
168
     * @param id             the Wicket component ID
169
     * @param uri            the URI of the nanopublication or IRI
170
     * @param np             the nanopublication, or null if the link is not to a nanopublication
171
     * @param templateClass  the template class of the nanopublication, or null if the link is not to a nanopublication
172
     */
173
    public NanodashLink(String id, String uri, Nanopub np, IRI templateClass) {
174
        this(id, uri, np, templateClass, null);
7✔
175
    }
1✔
176

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

188
    /**
189
     * Creates a link to a nanopublication or an IRI.
190
     *
191
     * @param id  the Wicket component ID
192
     * @param uri the URI of the nanopublication or IRI
193
     */
194
    public NanodashLink(String id, String uri) {
195
        this(id, uri, null, null);
×
196
    }
×
197

198
    private static ValueFactory vf = SimpleValueFactory.getInstance();
3✔
199

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