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

knowledgepixels / nanodash / 19131417454

06 Nov 2025 09:43AM UTC coverage: 14.306% (+0.1%) from 14.205%
19131417454

push

github

tkuhn
chore: Use PageParameters#set instead of #add (mostly)

518 of 4522 branches covered (11.46%)

Branch coverage included in aggregate %.

1332 of 8410 relevant lines covered (15.84%)

0.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

7.56
src/main/java/com/knowledgepixels/nanodash/component/NanopubItem.java
1
package com.knowledgepixels.nanodash.component;
2

3
import java.text.SimpleDateFormat;
4
import java.util.ArrayList;
5
import java.util.Arrays;
6
import java.util.HashMap;
7
import java.util.List;
8
import java.util.Map;
9
import java.util.Set;
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.markup.repeater.Item;
16
import org.apache.wicket.markup.repeater.data.DataView;
17
import org.apache.wicket.markup.repeater.data.ListDataProvider;
18
import org.apache.wicket.model.Model;
19
import org.apache.wicket.request.mapper.parameter.PageParameters;
20
import org.eclipse.rdf4j.model.IRI;
21
import org.eclipse.rdf4j.model.Statement;
22
import org.nanopub.SimpleCreatorPattern;
23
import org.nanopub.extra.security.MalformedCryptoElementException;
24
import org.nanopub.extra.security.SignatureUtils;
25
import org.nanopub.vocabulary.NPX;
26
import org.nanopub.vocabulary.NTEMPLATE;
27
import org.slf4j.Logger;
28
import org.slf4j.LoggerFactory;
29

30
import com.knowledgepixels.nanodash.NanodashPreferences;
31
import com.knowledgepixels.nanodash.NanodashSession;
32
import com.knowledgepixels.nanodash.NanopubElement;
33
import com.knowledgepixels.nanodash.User;
34
import com.knowledgepixels.nanodash.Utils;
35
import com.knowledgepixels.nanodash.action.NanopubAction;
36
import com.knowledgepixels.nanodash.action.RetractionAction;
37
import com.knowledgepixels.nanodash.page.ListPage;
38
import com.knowledgepixels.nanodash.page.UserPage;
39
import com.knowledgepixels.nanodash.template.ContextType;
40
import com.knowledgepixels.nanodash.template.Template;
41
import com.knowledgepixels.nanodash.template.TemplateContext;
42
import com.knowledgepixels.nanodash.template.TemplateData;
43
import com.knowledgepixels.nanodash.template.ValueFiller;
44

45
/**
46
 * A panel that displays a nanopublication with its header, footer, assertion, provenance, and pubinfo.
47
 */
48
public class NanopubItem extends Panel {
49

50
    /**
51
     * Date format for displaying the creation date and time of the nanopub.
52
     */
53
    public static SimpleDateFormat simpleDateTimeFormat = new SimpleDateFormat("d MMM yyyy, HH:mm:ss zzz");
5✔
54
    /**
55
     * Date format for displaying the creation time of the nanopub without time.
56
     */
57
    public static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("d MMM yyyy");
5✔
58

59
    private boolean isInitialized = false;
3✔
60
    private NanopubElement n;
61
    private boolean hideAssertion = false;
3✔
62
    private boolean hideProvenance = false;
3✔
63
    private boolean hidePubinfo = false;
3✔
64
    private boolean hideHeader = false;
3✔
65
    private boolean hideFooter = false;
3✔
66
    private boolean hideActionMenu = false;
3✔
67
    private List<NanopubAction> actions;
68
    private IRI signerId;
69
    private String templateId;
70
    private static final Logger logger = LoggerFactory.getLogger(NanopubItem.class);
4✔
71

72
    /**
73
     * Creates a NanopubItem panel.
74
     *
75
     * @param id         the Wicket component ID
76
     * @param n          the NanopubElement to display
77
     * @param templateId the ID of the template to use for rendering the assertion.
78
     */
79
    public NanopubItem(String id, NanopubElement n, String templateId) {
80
        super(id);
3✔
81
        this.n = n;
3✔
82
        this.templateId = templateId;
3✔
83
    }
1✔
84

85
    /**
86
     * Creates a NanopubItem panel with a default template ID.
87
     *
88
     * @param id the Wicket component ID
89
     * @param n  the NanopubElement to display
90
     */
91
    public NanopubItem(String id, NanopubElement n) {
92
        this(id, n, null);
×
93
    }
×
94

95
    private void initialize() {
96
        if (isInitialized) return;
×
97

98
        String pubkey = n.getPubkey();
×
99
        String pubkeyhash = n.getPubkeyhash();
×
100
        signerId = n.getSignerId();
×
101

102
        if (hideHeader) {
×
103
            add(new Label("header", "").setVisible(false));
×
104
        } else {
105
            WebMarkupContainer header = new WebMarkupContainer("header");
×
106
            String labelString = n.getLabel();
×
107
            if (labelString == null || labelString.isBlank()) labelString = Utils.getShortNanopubId(n.getUri());
×
108
            header.add(NanodashLink.createLink("nanopub-id-link", n.getUri(), labelString, null));
×
109
            if (!hideActionMenu && (actions == null || !actions.isEmpty())) {
×
110
                NanodashSession session = NanodashSession.get();
×
111
                final boolean isOwnNanopub = (session.getUserIri() != null && session.getUserIri().equals(User.getUserData().getUserIriForPubkeyhash(pubkeyhash, false))) ||
×
112
                                             ((pubkey != null) && pubkey.equals(session.getPubkeyString()));
×
113
                final boolean hasLocalPubkey = session.getUserIri() != null && session.getPubkeyString() != null && session.getPubkeyString().equals(pubkey);
×
114
                final List<NanopubAction> actionList = new ArrayList<>();
×
115
                final Map<String, NanopubAction> actionMap = new HashMap<>();
×
116
                List<NanopubAction> allActions = new ArrayList<>();
×
117
                if (actions == null) {
×
118
                    allActions.addAll(Arrays.asList(NanopubAction.defaultActions));
×
119
                    allActions.addAll(NanopubAction.getActionsFromPreferences(NanodashPreferences.get()));
×
120
                } else {
121
                    allActions.addAll(actions);
×
122
                }
123
                for (NanopubAction action : allActions) {
×
124
                    if (isOwnNanopub && !action.isApplicableToOwnNanopubs()) continue;
×
125
                    if (isOwnNanopub && !hasLocalPubkey && !action.isApplicableToOthersNanopubs() && !Utils.hasNanodashLocation(pubkeyhash))
×
126
                        continue;
×
127
                    if (!isOwnNanopub && !action.isApplicableToOthersNanopubs()) continue;
×
128
                    if (!action.isApplicableTo(n.getNanopub())) continue;
×
129
                    if (action instanceof RetractionAction && isOwnNanopub &&
×
130
                        n.getNanopub().getPubinfo()
×
131
                                .stream()
×
132
                                .anyMatch(statement -> statement.getPredicate().equals(NPX.HAS_NANOPUB_TYPE) && statement.getObject().equals(NPX.RETRACTS))) {
×
133
                        continue;
×
134
                    }
135
                    actionList.add(action);
×
136
                    actionMap.put(action.getLinkLabel(n.getNanopub()), action);
×
137
                }
×
138
                header.add(new ActionMenu("action-menu", actionList, n));
×
139
            } else {
×
140
                header.add(new Label("action-menu", "").setVisible(false));
×
141
            }
142
            header.add(new DataView<IRI>("typespan", new ListDataProvider<IRI>(Utils.getTypes(n.getNanopub()))) {
×
143

144
                @Override
145
                protected void populateItem(Item<IRI> item) {
146
                    IRI typeIri = item.getModelObject();
×
147
                    String label = Utils.getTypeLabel(typeIri);
×
148
                    item.add(new BookmarkablePageLink<Void>("type", ListPage.class, new PageParameters().add("type", typeIri)).setBody(Model.of(label)));
×
149
                }
×
150

151
            });
152
            add(header);
×
153
        }
154

155
        if (hideFooter) {
×
156
            add(new Label("footer", "").setVisible(false));
×
157
        } else {
158
            WebMarkupContainer footer = new WebMarkupContainer("footer");
×
159
            if (n.getCreationTime() != null) {
×
160
                footer.add(new Label("datetime", simpleDateTimeFormat.format(n.getCreationTime().getTime())));
×
161
            } else {
162
                footer.add(new Label("datetime", "(undated)"));
×
163
            }
164

165
            List<IRI> authors = SimpleCreatorPattern.getAuthorList(n.getNanopub());
×
166
            WebMarkupContainer authorsSpan = new WebMarkupContainer("authors-span");
×
167
            if (authors.isEmpty()) {
×
168
                authorsSpan.setVisible(false);
×
169
                footer.add(new Label("creator-post", "").setVisible(false));
×
170
            } else {
171
                IRI mainAuthor = authors.getFirst();
×
172
                BookmarkablePageLink<Void> mainAuthorLink = new BookmarkablePageLink<Void>("main-author-link", UserPage.class, new PageParameters().set("id", mainAuthor));
×
173
                String authorName = n.getFoafNameMap().get(mainAuthor.stringValue());
×
174
                if (authorName == null) {
×
175
                    authorName = User.getShortDisplayName(mainAuthor);
×
176
                }
177
                mainAuthorLink.add(new Label("main-author-text", authorName));
×
178
                authorsSpan.add(mainAuthorLink);
×
179
                if (authors.size() > 1) {
×
180
                    authorsSpan.add(new Label("authors-post", " et al. (authors)"));
×
181
                } else {
182
                    authorsSpan.add(new Label("authors-post", " (author)"));
×
183
                }
184
                footer.add(new Label("creator-post", " (creator)"));
×
185
            }
186
            footer.add(authorsSpan);
×
187

188
            PageParameters params = new PageParameters();
×
189

190
            // ----------
191
            // TODO Clean this up and move to helper method:
192
            IRI uIri = User.findSingleIdForPubkeyhash(pubkeyhash);
×
193
            if (uIri == null) {
×
194
                try {
195
                    Set<IRI> signers = SignatureUtils.getSignatureElement(n.getNanopub()).getSigners();
×
196
                    if (signers.size() == 1) {
×
197
                        uIri = signers.iterator().next();
×
198
                    } else {
199
                        Set<IRI> creators = SimpleCreatorPattern.getCreators(n.getNanopub());
×
200
                        if (creators.size() == 1) uIri = creators.iterator().next();
×
201
                    }
202
                } catch (MalformedCryptoElementException ex) {
×
203
                    logger.error("Error getting signer from nanopub {}", n.getUri(), ex);
×
204
                }
×
205
            }
206
            // ----------
207

208
            if (uIri != null) params.add("id", uIri);
×
209
            BookmarkablePageLink<Void> userLink = new BookmarkablePageLink<Void>("creator-link", UserPage.class, params);
×
210
            String userString;
211
            if (signerId != null) {
×
212
                userString = User.getShortDisplayNameForPubkeyhash(signerId, pubkeyhash);
×
213
            } else {
214
                userString = User.getShortDisplayNameForPubkeyhash(uIri, pubkeyhash);
×
215
            }
216
            userLink.add(new Label("creator-text", userString));
×
217
            footer.add(userLink);
×
218

219
            String positiveNotes = "";
×
220
            String negativeNotes = "";
×
221
            if (n.seemsToHaveSignature()) {
×
222
                try {
223
                    if (!n.hasValidSignature()) {
×
224
                        negativeNotes = "- invalid signature";
×
225
                    }
226
                } catch (Exception ex) {
×
227
                    logger.error("Error checking signature validity for nanopub {}", n.getUri(), ex);
×
228
                    negativeNotes = "- malformed or legacy signature";
×
229
                }
×
230
            }
231
            footer.add(new Label("positive-notes", positiveNotes));
×
232
            footer.add(new Label("negative-notes", negativeNotes));
×
233
            add(footer);
×
234
        }
235

236
        final TemplateData td = TemplateData.get();
×
237

238
        WebMarkupContainer assertion = new WebMarkupContainer("assertion");
×
239

240
        if (hideAssertion) {
×
241
            assertion.setVisible(false);
×
242
        } else {
243
            Template assertionTemplate = td.getTemplate(n.getNanopub());
×
244
            if (templateId != null) assertionTemplate = td.getTemplate(templateId);
×
245
            if (assertionTemplate == null) {
×
246
                assertionTemplate = td.getTemplate("http://purl.org/np/RAFu2BNmgHrjOTJ8SKRnKaRp-VP8AOOb7xX88ob0DZRsU");
×
247
            }
248
            List<StatementItem> assertionStatements = new ArrayList<>();
×
249
            ValueFiller assertionFiller = new ValueFiller(n.getNanopub(), ContextType.ASSERTION, false);
×
250
            TemplateContext context = new TemplateContext(ContextType.ASSERTION, assertionTemplate.getId(), "assertion-statement", n.getNanopub());
×
251
            populateStatementItemList(context, assertionFiller, assertionStatements);
×
252

253
            assertion.add(createStatementView("assertion-statements", assertionStatements));
×
254
            assertion.add(new DataView<Statement>("unused-assertion-statements", new ListDataProvider<Statement>(assertionFiller.getUnusedStatements())) {
×
255

256
                @Override
257
                protected void populateItem(Item<Statement> item) {
258
                    item.add(new TripleItem("unused-assertion-statement", item.getModelObject(), n.getNanopub(), null));
×
259
                }
×
260

261
            });
262
        }
263
        add(assertion);
×
264

265
        WebMarkupContainer provenance = new WebMarkupContainer("provenance");
×
266
        if (hideProvenance) {
×
267
            provenance.setVisible(false);
×
268
        } else {
269
            Template provenanceTemplate = td.getProvenanceTemplate(n.getNanopub());
×
270
            if (provenanceTemplate == null)
×
271
                provenanceTemplate = td.getTemplate("http://purl.org/np/RA3Jxq5JJjluUNEpiMtxbiIHa7Yt-w8f9FiyexEstD5R4");
×
272
            List<StatementItem> provenanceStatements = new ArrayList<>();
×
273
            ValueFiller provenanceFiller = new ValueFiller(n.getNanopub(), ContextType.PROVENANCE, false);
×
274
            TemplateContext prContext = new TemplateContext(ContextType.PROVENANCE, provenanceTemplate.getId(), "provenance-statement", n.getNanopub());
×
275
            populateStatementItemList(prContext, provenanceFiller, provenanceStatements);
×
276
            provenance.add(createStatementView("provenance-statements", provenanceStatements));
×
277
            provenance.add(new DataView<Statement>("unused-provenance-statements", new ListDataProvider<Statement>(provenanceFiller.getUnusedStatements())) {
×
278

279
                @Override
280
                protected void populateItem(Item<Statement> item) {
281
                    item.add(new TripleItem("unused-provenance-statement", item.getModelObject(), n.getNanopub(), null));
×
282
                }
×
283

284
            });
285
        }
286
        add(provenance);
×
287

288
        WebMarkupContainer pubInfo = new WebMarkupContainer("pubinfo");
×
289
        if (hidePubinfo) {
×
290
            pubInfo.setVisible(false);
×
291
        } else {
292
            ValueFiller pubinfoFiller = new ValueFiller(n.getNanopub(), ContextType.PUBINFO, false);
×
293

294
            // TODO We should do this better:
295
            List<String> pubinfoAuthorTemplateIds = new ArrayList<>();
×
296
            List<String> pubinfoTemplateIds = new ArrayList<>();
×
297
            for (IRI iri : td.getPubinfoTemplateIds(n.getNanopub())) {
×
298
                if (iri.stringValue().equals("https://w3id.org/np/RA16U9Wo30ObhrK1NzH7EsmVRiRtvEuEA_Dfc-u8WkUCA")) { // author list
×
299
                    pubinfoAuthorTemplateIds.add(iri.stringValue());
×
300
                } else if (iri.stringValue().equals("http://purl.org/np/RA4vTctL3Luaj8oI_sPiN7I_8xEnR_hkdz5gN7bCvZpNY")) { // authors
×
301
                    pubinfoAuthorTemplateIds.add(iri.stringValue());
×
302
                } else if (iri.stringValue().equals("http://purl.org/np/RAA2MfqdBCzmz9yVWjKLXNbyfBNcwsMmOqcNUxkk1maIM")) { // creator
×
303
                    pubinfoTemplateIds.add(0, iri.stringValue());
×
304
                } else {
305
                    pubinfoTemplateIds.add(iri.stringValue());
×
306
                }
307
            }
×
308
            pubinfoTemplateIds.addAll(0, pubinfoAuthorTemplateIds);
×
309
            pubinfoTemplateIds.add("https://w3id.org/np/RAXVsr624oEAJvCt1WZXoUJ90lFYC5LUMoYHgEUOwmrLw"); // user name
×
310
            pubinfoTemplateIds.add("https://w3id.org/np/RARJj78P72NR5edKOnu_f4ePE9NYYuW2m2pM-fEoobMBk"); // nanopub label
×
311
            pubinfoTemplateIds.add("https://w3id.org/np/RA8iXbwvOC7BwVHuvAhFV235j2582SyAYJ2sfov19ZOlg"); // nanopub type
×
312
            pubinfoTemplateIds.add("https://w3id.org/np/RALmzqHlrRfeTD8ESZdKFyDNYY6eFuyQ8GAe_4N5eVytc"); // timestamp
×
313
            pubinfoTemplateIds.add("https://w3id.org/np/RADVnztsdSc36ffAXTxiIdXpYEMLiJrRENqaJ2Qn2LX3Y"); // templates
×
314
            pubinfoTemplateIds.add("https://w3id.org/np/RAvqXPNKPf56b2226oqhKzARyvIhnpnTrRpLGC1cYweMw"); // introductions
×
315
            pubinfoTemplateIds.add("https://w3id.org/np/RAgIlomuR39mN-Z39bbv59-h2DgQBnLyNdL22YmOJ_VHM"); // labels from APIs
×
316
            pubinfoTemplateIds.add("https://w3id.org/np/RAoWx0AJvNw-WqkGgZO4k8udNCg6kMcGZARN3DgO_5TII"); // contributor names
×
317
            pubinfoTemplateIds.add("https://w3id.org/np/RAY_M7GUmyOTjXQbJArzhVVzQ5XvgHt0JR7h2LZo6TXvY"); // signature
×
318
            pubinfoTemplateIds.add("https://w3id.org/np/RA_TZ9tvF6sBewmbIGbTFguLOPUUS70huklacisZrYtYw"); // creation site
×
319
            pubinfoTemplateIds.add("https://w3id.org/np/RAE-zsHxw2VoE6emhSY_Fkr5p_li5Qb8FrREqUwdWdzyM"); // generic
×
320

321
            List<TemplateContext> contexts = new ArrayList<>();
×
322
            List<TemplateContext> genericContexts = new ArrayList<>();
×
323
            for (String s : pubinfoTemplateIds) {
×
324
                TemplateContext piContext = new TemplateContext(ContextType.PUBINFO, s, "pubinfo-statement", n.getNanopub());
×
325
                if (piContext.willMatchAnyTriple()) {
×
326
                    genericContexts.add(piContext);
×
327
                } else if (piContext.getTemplateId().equals("https://w3id.org/np/RAE-zsHxw2VoE6emhSY_Fkr5p_li5Qb8FrREqUwdWdzyM")) {
×
328
                    // TODO: This is a work-around; check why this template doesn't give true to willMatchAnyTriple()
329
                    genericContexts.add(piContext);
×
330
                } else {
331
                    contexts.add(piContext);
×
332
                }
333
            }
×
334
            contexts.addAll(genericContexts);  // make sure the generic one are at the end
×
335
            List<WebMarkupContainer> elements = new ArrayList<>();
×
336
            for (TemplateContext piContext : contexts) {
×
337
                WebMarkupContainer pubInfoElement = new WebMarkupContainer("pubinfo-element");
×
338
                List<StatementItem> pubinfoStatements = new ArrayList<>();
×
339
                populateStatementItemList(piContext, pubinfoFiller, pubinfoStatements);
×
340
                if (!pubinfoStatements.isEmpty()) {
×
341
                    pubInfoElement.add(createStatementView("pubinfo-statements", pubinfoStatements));
×
342
                    elements.add(pubInfoElement);
×
343
                }
344
            }
×
345
            pubInfo.add(new DataView<WebMarkupContainer>("pubinfo-elements", new ListDataProvider<WebMarkupContainer>(elements)) {
×
346

347
                @Override
348
                protected void populateItem(Item<WebMarkupContainer> item) {
349
                    item.add(item.getModelObject());
×
350
                }
×
351

352
            });
353
        }
354
        add(pubInfo);
×
355

356
        isInitialized = true;
×
357
    }
×
358

359
    /**
360
     * Hides the provenance part of the nanopub item.
361
     *
362
     * @return this NanopubItem instance for method chaining
363
     */
364
    public NanopubItem hideProvenance() {
365
        if (isInitialized) throw new RuntimeException("Nanopub item is already initialized");
×
366
        hideProvenance = true;
×
367
        return this;
×
368
    }
369

370
    /**
371
     * Sets whether the provenance part of the nanopub item should be hidden.
372
     *
373
     * @param hideProvenance true to hide provenance, false to show it
374
     * @return this NanopubItem instance for method chaining
375
     */
376
    public NanopubItem setProvenanceHidden(boolean hideProvenance) {
377
        if (isInitialized) throw new RuntimeException("Nanopub item is already initialized");
3!
378
        this.hideProvenance = hideProvenance;
3✔
379
        return this;
2✔
380
    }
381

382
    /**
383
     * Hides the pubinfo part of the nanopub item.
384
     *
385
     * @return this NanopubItem instance for method chaining
386
     */
387
    public NanopubItem hidePubinfo() {
388
        if (isInitialized) throw new RuntimeException("Nanopub item is already initialized");
×
389
        hidePubinfo = true;
×
390
        return this;
×
391
    }
392

393
    /**
394
     * Sets whether the pubinfo part of the nanopub item should be hidden.
395
     *
396
     * @param hidePubinfo true to hide pubinfo, false to show it
397
     * @return this NanopubItem instance for method chaining
398
     */
399
    public NanopubItem setPubinfoHidden(boolean hidePubinfo) {
400
        if (isInitialized) throw new RuntimeException("Nanopub item is already initialized");
3!
401
        this.hidePubinfo = hidePubinfo;
3✔
402
        return this;
2✔
403
    }
404

405
    /**
406
     * Hides the header part of the nanopub item.
407
     *
408
     * @return this NanopubItem instance for method chaining
409
     */
410
    public NanopubItem hideHeader() {
411
        if (isInitialized) throw new RuntimeException("Nanopub item is already initialized");
×
412
        hideHeader = true;
×
413
        return this;
×
414
    }
415

416
    /**
417
     * Sets whether the header part of the nanopub item should be hidden.
418
     *
419
     * @param hideHeader true to hide header, false to show it
420
     * @return this NanopubItem instance for method chaining
421
     */
422
    public NanopubItem setHeaderHidden(boolean hideHeader) {
423
        if (isInitialized) throw new RuntimeException("Nanopub item is already initialized");
3!
424
        this.hideHeader = hideHeader;
3✔
425
        return this;
2✔
426
    }
427

428
    /**
429
     * Hides the footer part of the nanopub item.
430
     *
431
     * @return this NanopubItem instance for method chaining
432
     */
433
    public NanopubItem hideFooter() {
434
        if (isInitialized) throw new RuntimeException("Nanopub item is already initialized");
×
435
        hideFooter = true;
×
436
        return this;
×
437
    }
438

439
    /**
440
     * Sets whether the footer part of the nanopub item should be hidden.
441
     *
442
     * @param hideFooter true to hide footer, false to show it
443
     * @return this NanopubItem instance for method chaining
444
     */
445
    public NanopubItem setFooterHidden(boolean hideFooter) {
446
        if (isInitialized) throw new RuntimeException("Nanopub item is already initialized");
3!
447
        this.hideFooter = hideFooter;
3✔
448
        return this;
2✔
449
    }
450

451
    /**
452
     * Sets the nanopub item to a minimal state, hiding assertion, action menu, provenance, and pubinfo.
453
     *
454
     * @return this NanopubItem instance for method chaining
455
     */
456
    public NanopubItem setMinimal() {
457
        if (isInitialized) throw new RuntimeException("Nanopub item is already initialized");
×
458
        this.hideAssertion = true;
×
459
        this.hideActionMenu = true;
×
460
        setProvenanceHidden(true).setPubinfoHidden(true);
×
461
        return this;
×
462
    }
463

464
    /**
465
     * Adds the given actions to the nanopub item.
466
     *
467
     * @param a a {@link com.knowledgepixels.nanodash.action.NanopubAction} object
468
     * @return this NanopubItem instance for method chaining
469
     */
470
    public NanopubItem addActions(NanopubAction... a) {
471
        if (isInitialized) throw new RuntimeException("Nanopub item is already initialized");
×
472
        if (actions == null) actions = new ArrayList<>();
×
473
        for (NanopubAction na : a) {
×
474
            actions.add(na);
×
475
        }
476
        return this;
×
477
    }
478

479
    /**
480
     * Sets the nanopub item to have no actions.
481
     *
482
     * @return this NanopubItem instance for method chaining
483
     */
484
    public NanopubItem noActions() {
485
        if (isInitialized) throw new RuntimeException("Nanopub item is already initialized");
×
486
        actions = new ArrayList<>();
×
487
        return this;
×
488
    }
489

490
    /**
491
     * {@inheritDoc}
492
     */
493
    @Override
494
    protected void onBeforeRender() {
495
        initialize();
×
496
        super.onBeforeRender();
×
497
    }
×
498

499
    private void populateStatementItemList(TemplateContext context, ValueFiller filler, List<StatementItem> list) {
500
        context.initStatements();
×
501
        if (signerId != null) {
×
502
            context.getComponentModels().put(NTEMPLATE.CREATOR_PLACEHOLDER, Model.of(signerId.stringValue()));
×
503
        }
504
        filler.fill(context);
×
505
        for (StatementItem si : context.getStatementItems()) {
×
506
            if (si.isMatched()) {
×
507
                list.add(si);
×
508
            }
509
        }
×
510
    }
×
511

512
    private DataView<StatementItem> createStatementView(String elementId, List<StatementItem> list) {
513
        return new DataView<StatementItem>(elementId, new ListDataProvider<StatementItem>(list)) {
×
514

515
            @Override
516
            protected void populateItem(Item<StatementItem> item) {
517
                item.add(item.getModelObject());
×
518
            }
×
519

520
        };
521
    }
522

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