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

knowledgepixels / nanodash / 28789064412

06 Jul 2026 11:44AM UTC coverage: 28.51% (+0.008%) from 28.502%
28789064412

push

github

web-flow
Merge pull request #535 from knowledgepixels/feat/navigation-context

feat: persistent navigation context with back-link and post-publish forwarding

1811 of 7177 branches covered (25.23%)

Branch coverage included in aggregate %.

3710 of 12188 relevant lines covered (30.44%)

4.52 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.domain.User;
4
import com.knowledgepixels.nanodash.NavigationContext;
5
import com.knowledgepixels.nanodash.Utils;
6
import com.knowledgepixels.nanodash.page.NanodashPage;
7
import com.knowledgepixels.nanodash.page.PublishPage;
8
import com.knowledgepixels.nanodash.template.Template;
9
import net.trustyuri.TrustyUriUtils;
10

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

24
import java.text.SimpleDateFormat;
25
import java.util.Calendar;
26

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

32
    private static final Logger logger = LoggerFactory.getLogger(TemplateItem.class);
×
33

34
    /**
35
     * Parameters of the publish link, kept so the page's navigation context can be
36
     * added in {@link #onInitialize()} (the page is not available in the constructor).
37
     */
38
    private PageParameters publishLinkParams;
39

40
    @Override
41
    protected void onInitialize() {
42
        super.onInitialize();
×
43
        if (getPage() instanceof NanodashPage nanodashPage) {
×
44
            NavigationContext.withContext(publishLinkParams, nanodashPage.getContextId());
×
45
        }
46
    }
×
47

48
    /**
49
     * A single template item in a list, showing the template name, user, and timestamp.
50
     *
51
     * @param id    the wicket id of this component
52
     * @param entry the API response entry to display
53
     */
54
    public TemplateItem(String id, ApiResponseEntry entry) {
55
        this(id, entry, null, true);
×
56
    }
×
57

58
    /**
59
     * A single template item in a list, showing the template name, user, and timestamp.
60
     *
61
     * @param id               the wicket id of this component
62
     * @param entry            the API response entry to display
63
     * @param additionalParams additional parameters to add to the link
64
     */
65
    public TemplateItem(String id, ApiResponseEntry entry, PageParameters additionalParams, boolean extended) {
66
        super(id);
×
67

68
        PageParameters params = new PageParameters();
×
69
        params.set("template", entry.get("np"));
×
70
        params.set("template-version", "latest");
×
71
        if (additionalParams != null) params.mergeWith(additionalParams);
×
72
        publishLinkParams = params;
×
73
        BookmarkablePageLink<Void> l = new BookmarkablePageLink<Void>("link", PublishPage.class, params);
×
74
        String label = entry.get("label");
×
75
        if (label == null || label.isBlank()) label = TrustyUriUtils.getArtifactCode(entry.get("np")).substring(0, 10);
×
76
        l.add(new Label("name", label));
×
77
        add(l);
×
78
        WebMarkupContainer statusPart = new WebMarkupContainer("status");
×
79
        if (extended) {
×
80
            IRI userIri = null;
×
81
            String creator = entry.get("creator");
×
82
            if (creator != null && !creator.isBlank()) {
×
83
                try {
84
                    userIri = Utils.vf.createIRI(creator);
×
85
                } catch (IllegalArgumentException | NullPointerException ex) {
×
86
                    logger.error("Error creating IRI from creator string: {}", creator, ex);
×
87
                }
×
88
            }
89
            String userString = User.getShortDisplayNameForPubkeyhash(userIri, entry.get("pubkeyhash"));
×
90
            statusPart.add(new Label("user", userString));
×
91
            statusPart.add(new Label("timestamp", entry.get("date").substring(0, 10)));
×
92
        } else {
×
93
            statusPart.setVisible(false);
×
94
        }
95
        add(statusPart);
×
96
    }
×
97

98
    /**
99
     * A single template item in a list, showing the template name, user, and timestamp.
100
     *
101
     * @param id       the wicket id of this component
102
     * @param template the template to display
103
     */
104
    public TemplateItem(String id, Template template) {
105
        this(id, template, null, true);
×
106
    }
×
107

108
    /**
109
     * A single template item in a list, showing the template name, user, and timestamp.
110
     *
111
     * @param id               the wicket id of this component
112
     * @param template         the template to display
113
     * @param additionalParams additional parameters to add to the link
114
     */
115
    public TemplateItem(String id, Template template, PageParameters additionalParams, boolean extended) {
116
        super(id);
×
117

118
        PageParameters params = new PageParameters();
×
119
        params.set("template", template.getId());
×
120
        params.set("template-version", "latest");
×
121
        if (additionalParams != null) params.mergeWith(additionalParams);
×
122
        publishLinkParams = params;
×
123
        BookmarkablePageLink<Void> l = new BookmarkablePageLink<Void>("link", PublishPage.class, params);
×
124
        l.add(new Label("name", template.getLabel()));
×
125
        add(l);
×
126
        WebMarkupContainer statusPart = new WebMarkupContainer("status");
×
127
        if (extended) {
×
128
            String userString = "somebody";
×
129
            try {
130
                NanopubSignatureElement se = SignatureUtils.getSignatureElement(template.getNanopub());
×
131
                if (se != null) {
×
132
                    IRI signer = (se.getSigners().isEmpty() ? null : se.getSigners().iterator().next());
×
133
                    String pubkeyHash = Utils.createSha256HexHash(se.getPublicKeyString());
×
134
                    userString = User.getShortDisplayNameForPubkeyhash(signer, pubkeyHash);
×
135
                }
136
            } catch (Exception ex) {
×
137
                logger.error("Error getting signature element for template {}", template.getId(), ex);
×
138
            }
×
139
            statusPart.add(new Label("user", userString));
×
140
            String timeString = "unknown date";
×
141
            Calendar c = SimpleTimestampPattern.getCreationTime(template.getNanopub());
×
142
            if (c != null) {
×
143
                timeString = (new SimpleDateFormat("yyyy-MM-dd")).format(c.getTime());
×
144
            }
145
            statusPart.add(new Label("timestamp", timeString));
×
146
        } else {
×
147
            statusPart.setVisible(false);
×
148
        }
149
        add(statusPart);
×
150
    }
×
151

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