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

knowledgepixels / nanodash / 17380144000

01 Sep 2025 02:12PM UTC coverage: 12.03% (+0.05%) from 11.978%
17380144000

push

github

ashleycaselli
refactor: replace printStackTrace with logger.error for better error handling

330 of 3850 branches covered (8.57%)

Branch coverage included in aggregate %.

958 of 6857 relevant lines covered (13.97%)

0.62 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 long serialVersionUID = 1L;
29
    private static final Logger logger = LoggerFactory.getLogger(TemplateItem.class);
×
30

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

41
    public TemplateItem(String id, ApiResponseEntry entry, PageParameters additionalParams) {
42
        super(id);
×
43

44
        PageParameters params = new PageParameters();
×
45
        params.add("template", entry.get("np"));
×
46
        params.add("template-version", "latest");
×
47
        if (additionalParams != null) params.mergeWith(additionalParams);
×
48
        BookmarkablePageLink<Void> l = new BookmarkablePageLink<Void>("link", PublishPage.class, params);
×
49
        String label = entry.get("label");
×
50
        if (label == null || label.isBlank()) label = TrustyUriUtils.getArtifactCode(entry.get("np")).substring(0, 10);
×
51
        l.add(new Label("name", label));
×
52
        add(l);
×
53
        IRI userIri = null;
×
54
        try {
55
            userIri = Utils.vf.createIRI(entry.get("creator"));
×
56
        } catch (IllegalArgumentException | NullPointerException ex) {
×
57
        }
×
58
        String userString = User.getShortDisplayNameForPubkeyhash(userIri, entry.get("pubkeyhash"));
×
59
        add(new Label("user", userString));
×
60
        add(new Label("timestamp", entry.get("date").substring(0, 10)));
×
61
    }
×
62

63

64
    public TemplateItem(String id, Template template) {
65
        this(id, template, null);
×
66
    }
×
67

68
    /**
69
     * A single template item in a list, showing the template name, user, and timestamp.
70
     *
71
     * @param id               the wicket id of this component
72
     * @param template         the template to display
73
     * @param additionalParams additional parameters to add to the link
74
     */
75
    public TemplateItem(String id, Template template, PageParameters additionalParams) {
76
        super(id);
×
77

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

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