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

knowledgepixels / nanodash / 17581065640

09 Sep 2025 11:22AM UTC coverage: 13.608% (-0.1%) from 13.73%
17581065640

push

github

ashleycaselli
chore: add error logging for exception handling in various components

406 of 3854 branches covered (10.53%)

Branch coverage included in aggregate %.

1072 of 7007 relevant lines covered (15.3%)

0.68 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
            logger.error("Error creating IRI from creator string: {}", entry.get("creator"), ex);
×
58
        }
×
59
        String userString = User.getShortDisplayNameForPubkeyhash(userIri, entry.get("pubkeyhash"));
×
60
        add(new Label("user", userString));
×
61
        add(new Label("timestamp", entry.get("date").substring(0, 10)));
×
62
    }
×
63

64

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

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

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

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