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

knowledgepixels / nanodash / 18155160356

01 Oct 2025 07:42AM UTC coverage: 13.788% (-0.03%) from 13.817%
18155160356

push

github

ashleycaselli
docs: add missing or update Javadoc annotations

445 of 4084 branches covered (10.9%)

Branch coverage included in aggregate %.

1155 of 7520 relevant lines covered (15.36%)

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/component/TemplateItem.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.page.PublishPage;
6
import com.knowledgepixels.nanodash.template.Template;
7
import net.trustyuri.TrustyUriUtils;
8
import org.apache.wicket.markup.html.basic.Label;
9
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
10
import org.apache.wicket.markup.html.panel.Panel;
11
import org.apache.wicket.request.mapper.parameter.PageParameters;
12
import org.eclipse.rdf4j.model.IRI;
13
import org.nanopub.SimpleTimestampPattern;
14
import org.nanopub.extra.security.NanopubSignatureElement;
15
import org.nanopub.extra.security.SignatureUtils;
16
import org.nanopub.extra.services.ApiResponseEntry;
17
import org.slf4j.Logger;
18
import org.slf4j.LoggerFactory;
19

20
import java.text.SimpleDateFormat;
21
import java.util.Calendar;
22

23
/**
24
 * A single template item in a list, showing the template name, user, and timestamp.
25
 */
26
public class TemplateItem extends Panel {
27

28
    private static final Logger logger = LoggerFactory.getLogger(TemplateItem.class);
×
29

30
    /**
31
     * A single template item in a list, showing the template name, user, and timestamp.
32
     *
33
     * @param id    the wicket id of this component
34
     * @param entry the API response entry to display
35
     */
36
    public TemplateItem(String id, ApiResponseEntry entry) {
37
        this(id, entry, null);
×
38
    }
×
39

40
    /**
41
     * A single template item in a list, showing the template name, user, and timestamp.
42
     *
43
     * @param id               the wicket id of this component
44
     * @param entry            the API response entry to display
45
     * @param additionalParams additional parameters to add to the link
46
     */
47
    public TemplateItem(String id, ApiResponseEntry entry, PageParameters additionalParams) {
48
        super(id);
×
49

50
        PageParameters params = new PageParameters();
×
51
        params.add("template", entry.get("np"));
×
52
        params.add("template-version", "latest");
×
53
        if (additionalParams != null) params.mergeWith(additionalParams);
×
54
        BookmarkablePageLink<Void> l = new BookmarkablePageLink<Void>("link", PublishPage.class, params);
×
55
        String label = entry.get("label");
×
56
        if (label == null || label.isBlank()) label = TrustyUriUtils.getArtifactCode(entry.get("np")).substring(0, 10);
×
57
        l.add(new Label("name", label));
×
58
        add(l);
×
59
        IRI userIri = null;
×
60
        try {
61
            userIri = Utils.vf.createIRI(entry.get("creator"));
×
62
        } catch (IllegalArgumentException | NullPointerException ex) {
×
63
            logger.error("Error creating IRI from creator string: {}", entry.get("creator"), ex);
×
64
        }
×
65
        String userString = User.getShortDisplayNameForPubkeyhash(userIri, entry.get("pubkeyhash"));
×
66
        add(new Label("user", userString));
×
67
        add(new Label("timestamp", entry.get("date").substring(0, 10)));
×
68
    }
×
69

70
    /**
71
     * A single template item in a list, showing the template name, user, and timestamp.
72
     *
73
     * @param id       the wicket id of this component
74
     * @param template the template to display
75
     */
76
    public TemplateItem(String id, Template template) {
77
        this(id, template, null);
×
78
    }
×
79

80
    /**
81
     * A single template item in a list, showing the template name, user, and timestamp.
82
     *
83
     * @param id               the wicket id of this component
84
     * @param template         the template to display
85
     * @param additionalParams additional parameters to add to the link
86
     */
87
    public TemplateItem(String id, Template template, PageParameters additionalParams) {
88
        super(id);
×
89

90
        PageParameters params = new PageParameters();
×
91
        params.add("template", template.getId());
×
92
        params.add("template-version", "latest");
×
93
        if (additionalParams != null) params.mergeWith(additionalParams);
×
94
        BookmarkablePageLink<Void> l = new BookmarkablePageLink<Void>("link", PublishPage.class, params);
×
95
        l.add(new Label("name", template.getLabel()));
×
96
        add(l);
×
97
        String userString = "somebody";
×
98
        try {
99
            NanopubSignatureElement se = SignatureUtils.getSignatureElement(template.getNanopub());
×
100
            if (se != null) {
×
101
                IRI signer = (se.getSigners().isEmpty() ? null : se.getSigners().iterator().next());
×
102
                String pubkeyHash = Utils.createSha256HexHash(se.getPublicKeyString());
×
103
                userString = User.getShortDisplayNameForPubkeyhash(signer, pubkeyHash);
×
104
            }
105
        } catch (Exception ex) {
×
106
            logger.error("Error getting signature element for template {}", template.getId(), ex);
×
107
        }
×
108
        add(new Label("user", userString));
×
109
        String timeString = "unknown date";
×
110
        Calendar c = SimpleTimestampPattern.getCreationTime(template.getNanopub());
×
111
        if (c != null) {
×
112
            timeString = (new SimpleDateFormat("yyyy-MM-dd")).format(c.getTime());
×
113
        }
114
        add(new Label("timestamp", timeString));
×
115
    }
×
116

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