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

knowledgepixels / nanodash / 18221996852

03 Oct 2025 12:17PM UTC coverage: 13.699% (-0.02%) from 13.723%
18221996852

push

github

tkuhn
style(Spaces): Hide status info for template/query items in Spaces

446 of 4114 branches covered (10.84%)

Branch coverage included in aggregate %.

1154 of 7566 relevant lines covered (15.25%)

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

9
import org.apache.wicket.markup.html.WebMarkupContainer;
10
import org.apache.wicket.markup.html.basic.Label;
11
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
12
import org.apache.wicket.markup.html.panel.Panel;
13
import org.apache.wicket.request.mapper.parameter.PageParameters;
14
import org.eclipse.rdf4j.model.IRI;
15
import org.nanopub.SimpleTimestampPattern;
16
import org.nanopub.extra.security.NanopubSignatureElement;
17
import org.nanopub.extra.security.SignatureUtils;
18
import org.nanopub.extra.services.ApiResponseEntry;
19
import org.slf4j.Logger;
20
import org.slf4j.LoggerFactory;
21

22
import java.text.SimpleDateFormat;
23
import java.util.Calendar;
24

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

30
    private static final Logger logger = LoggerFactory.getLogger(TemplateItem.class);
×
31

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

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

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

78
    /**
79
     * A single template item in a list, showing the template name, user, and timestamp.
80
     *
81
     * @param id       the wicket id of this component
82
     * @param template the template to display
83
     */
84
    public TemplateItem(String id, Template template) {
85
        this(id, template, null, true);
×
86
    }
×
87

88
    /**
89
     * A single template item in a list, showing the template name, user, and timestamp.
90
     *
91
     * @param id               the wicket id of this component
92
     * @param template         the template to display
93
     * @param additionalParams additional parameters to add to the link
94
     */
95
    public TemplateItem(String id, Template template, PageParameters additionalParams, boolean extended) {
96
        super(id);
×
97

98
        PageParameters params = new PageParameters();
×
99
        params.add("template", template.getId());
×
100
        params.add("template-version", "latest");
×
101
        if (additionalParams != null) params.mergeWith(additionalParams);
×
102
        BookmarkablePageLink<Void> l = new BookmarkablePageLink<Void>("link", PublishPage.class, params);
×
103
        l.add(new Label("name", template.getLabel()));
×
104
        add(l);
×
105
        WebMarkupContainer statusPart = new WebMarkupContainer("status");
×
106
        if (extended) {
×
107
            String userString = "somebody";
×
108
            try {
109
                NanopubSignatureElement se = SignatureUtils.getSignatureElement(template.getNanopub());
×
110
                if (se != null) {
×
111
                    IRI signer = (se.getSigners().isEmpty() ? null : se.getSigners().iterator().next());
×
112
                    String pubkeyHash = Utils.createSha256HexHash(se.getPublicKeyString());
×
113
                    userString = User.getShortDisplayNameForPubkeyhash(signer, pubkeyHash);
×
114
                }
115
            } catch (Exception ex) {
×
116
                logger.error("Error getting signature element for template {}", template.getId(), ex);
×
117
            }
×
118
            statusPart.add(new Label("user", userString));
×
119
            String timeString = "unknown date";
×
120
            Calendar c = SimpleTimestampPattern.getCreationTime(template.getNanopub());
×
121
            if (c != null) {
×
122
                timeString = (new SimpleDateFormat("yyyy-MM-dd")).format(c.getTime());
×
123
            }
124
            statusPart.add(new Label("timestamp", timeString));
×
125
        } else {
×
126
            statusPart.setVisible(false);
×
127
        }
128
        add(statusPart);
×
129
    }
×
130

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