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

knowledgepixels / nanodash / 17760079101

16 Sep 2025 08:42AM UTC coverage: 13.879% (+0.08%) from 13.799%
17760079101

push

github

ashleycaselli
refactor: replace hardcoded local URI prefix with LocalUri constant and checks with Utils methods

443 of 4012 branches covered (11.04%)

Branch coverage included in aggregate %.

1126 of 7293 relevant lines covered (15.44%)

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/PublishForm.java
1
package com.knowledgepixels.nanodash.component;
2

3
import java.lang.reflect.InvocationTargetException;
4
import java.util.ArrayList;
5
import java.util.Collection;
6
import java.util.HashMap;
7
import java.util.List;
8
import java.util.Map;
9

10
import com.knowledgepixels.nanodash.*;
11
import org.apache.commons.lang3.Strings;
12
import org.apache.wicket.Component;
13
import org.apache.wicket.RestartResponseException;
14
import org.apache.wicket.ajax.AjaxEventBehavior;
15
import org.apache.wicket.ajax.AjaxRequestTarget;
16
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
17
import org.apache.wicket.feedback.FeedbackMessage;
18
import org.apache.wicket.markup.html.WebMarkupContainer;
19
import org.apache.wicket.markup.html.WebPage;
20
import org.apache.wicket.markup.html.basic.Label;
21
import org.apache.wicket.markup.html.form.CheckBox;
22
import org.apache.wicket.markup.html.form.Form;
23
import org.apache.wicket.markup.html.form.FormComponent;
24
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
25
import org.apache.wicket.markup.html.list.ListItem;
26
import org.apache.wicket.markup.html.list.ListView;
27
import org.apache.wicket.markup.html.panel.FeedbackPanel;
28
import org.apache.wicket.markup.html.panel.Panel;
29
import org.apache.wicket.markup.repeater.Item;
30
import org.apache.wicket.markup.repeater.data.DataView;
31
import org.apache.wicket.markup.repeater.data.ListDataProvider;
32
import org.apache.wicket.model.IModel;
33
import org.apache.wicket.model.Model;
34
import org.apache.wicket.request.mapper.parameter.PageParameters;
35
import org.apache.wicket.validation.IValidatable;
36
import org.apache.wicket.validation.IValidator;
37
import org.apache.wicket.validation.ValidationError;
38
import org.eclipse.rdf4j.model.IRI;
39
import org.eclipse.rdf4j.model.Literal;
40
import org.eclipse.rdf4j.model.Statement;
41
import org.eclipse.rdf4j.model.ValueFactory;
42
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
43
import org.eclipse.rdf4j.model.vocabulary.FOAF;
44
import org.eclipse.rdf4j.model.vocabulary.RDFS;
45
import org.nanopub.MalformedNanopubException;
46
import org.nanopub.Nanopub;
47
import org.nanopub.NanopubAlreadyFinalizedException;
48
import org.nanopub.NanopubCreator;
49
import org.nanopub.extra.security.SignNanopub;
50
import org.nanopub.extra.security.SignatureAlgorithm;
51
import org.nanopub.extra.security.TransformContext;
52
import org.nanopub.extra.server.PublishNanopub;
53
import org.nanopub.extra.services.ApiResponseEntry;
54
import org.nanopub.vocabulary.NPX;
55
import org.nanopub.vocabulary.NTEMPLATE;
56
import org.slf4j.Logger;
57
import org.slf4j.LoggerFactory;
58
import org.wicketstuff.select2.ChoiceProvider;
59
import org.wicketstuff.select2.Response;
60
import org.wicketstuff.select2.Select2Choice;
61

62
import com.knowledgepixels.nanodash.page.ExplorePage;
63
import com.knowledgepixels.nanodash.page.NanodashPage;
64
import com.knowledgepixels.nanodash.template.ContextType;
65
import com.knowledgepixels.nanodash.template.Template;
66
import com.knowledgepixels.nanodash.template.TemplateContext;
67
import com.knowledgepixels.nanodash.template.TemplateData;
68
import com.knowledgepixels.nanodash.template.ValueFiller;
69

70
/**
71
 * Form for publishing a nanopublication.
72
 */
73
public class PublishForm extends Panel {
74

75
    private static final long serialVersionUID = 1L;
76
    private static final Logger logger = LoggerFactory.getLogger(PublishForm.class);
×
77

78
    private static ValueFactory vf = SimpleValueFactory.getInstance();
×
79

80
    private static String creatorPubinfoTemplateId = "https://w3id.org/np/RAukAcWHRDlkqxk7H2XNSegc1WnHI569INvNr-xdptDGI";
×
81
    private static String licensePubinfoTempalteId = "https://w3id.org/np/RA0J4vUn_dekg-U1kK3AOEt02p9mT2WO03uGxLDec1jLw";
×
82
    private static String defaultProvTemplateId = "https://w3id.org/np/RA7lSq6MuK_TIC6JMSHvLtee3lpLoZDOqLJCLXevnrPoU";
×
83
    private static String supersedesPubinfoTemplateId = "https://w3id.org/np/RAoTD7udB2KtUuOuAe74tJi1t3VzK0DyWS7rYVAq1GRvw";
×
84
    private static String derivesFromPubinfoTemplateId = "https://w3id.org/np/RARW4MsFkHuwjycNElvEVtuMjpf4yWDL10-0C5l2MqqRQ";
×
85

86
    private static String[] fixedPubInfoTemplates = new String[]{creatorPubinfoTemplateId, licensePubinfoTempalteId};
×
87

88
    /**
89
     * Fill modes for the nanopublication to be created.
90
     */
91
    public enum FillMode {USE, SUPERSEDE, DERIVE}
×
92

93
    protected Form<?> form;
94
    protected FeedbackPanel feedbackPanel;
95
    private final TemplateContext assertionContext;
96
    private TemplateContext provenanceContext;
97
    private List<TemplateContext> pubInfoContexts = new ArrayList<>();
×
98
    private Map<String, TemplateContext> pubInfoContextMap = new HashMap<>();
×
99
    private List<TemplateContext> requiredPubInfoContexts = new ArrayList<>();
×
100
    private String targetNamespace;
101
    private Class<? extends WebPage> confirmPageClass;
102

103
    /**
104
     * Constructor for the PublishForm.
105
     *
106
     * @param id               the Wicket component ID
107
     * @param pageParams       the parameters for the page, which may include information on how to fill the form
108
     * @param publishPageClass the class of the page to redirect to after successful publication
109
     * @param confirmPageClass the class of the confirmation page to show after publication
110
     */
111
    public PublishForm(String id, final PageParameters pageParams, Class<? extends WebPage> publishPageClass, Class<? extends WebPage> confirmPageClass) {
112
        super(id);
×
113
        setOutputMarkupId(true);
×
114
        this.confirmPageClass = confirmPageClass;
×
115

116
        WebMarkupContainer linkMessageItem = new WebMarkupContainer("link-message-item");
×
117
        if (pageParams.get("link-message").isNull()) {
×
118
            linkMessageItem.add(new Label("link-message", ""));
×
119
            linkMessageItem.setVisible(false);
×
120
        } else {
121
            linkMessageItem.add(new Label("link-message", Utils.sanitizeHtml(pageParams.get("link-message").toString())).setEscapeModelStrings(false));
×
122
        }
123
        add(linkMessageItem);
×
124

125
        final Nanopub fillNp;
126
        final FillMode fillMode;
127
        boolean fillOnlyAssertion = false;
×
128
        if (!pageParams.get("use").isNull()) {
×
129
            fillNp = Utils.getNanopub(pageParams.get("use").toString());
×
130
            fillMode = FillMode.USE;
×
131
        } else if (!pageParams.get("use-a").isNull()) {
×
132
            fillNp = Utils.getNanopub(pageParams.get("use-a").toString());
×
133
            fillMode = FillMode.USE;
×
134
            fillOnlyAssertion = true;
×
135
        } else if (!pageParams.get("supersede").isNull()) {
×
136
            fillNp = Utils.getNanopub(pageParams.get("supersede").toString());
×
137
            fillMode = FillMode.SUPERSEDE;
×
138
            targetNamespace = pageParams.get("supersede").toString().replaceFirst("RA[A-Za-z0-9-_]{43}$", "");
×
139
        } else if (!pageParams.get("supersede-a").isNull()) {
×
140
            fillNp = Utils.getNanopub(pageParams.get("supersede-a").toString());
×
141
            fillMode = FillMode.SUPERSEDE;
×
142
            fillOnlyAssertion = true;
×
143
        } else if (!pageParams.get("derive").isNull()) {
×
144
            fillNp = Utils.getNanopub(pageParams.get("derive").toString());
×
145
            fillMode = FillMode.DERIVE;
×
146
        } else if (!pageParams.get("derive-a").isNull()) {
×
147
            fillNp = Utils.getNanopub(pageParams.get("derive-a").toString());
×
148
            fillMode = FillMode.DERIVE;
×
149
            fillOnlyAssertion = true;
×
150
        } else if (!pageParams.get("fill-all").isNull()) {
×
151
            // TODO: This is deprecated and should be removed at some point
152
            fillNp = Utils.getNanopub(pageParams.get("fill-all").toString());
×
153
            fillMode = FillMode.USE;
×
154
        } else if (!pageParams.get("fill").isNull()) {
×
155
            // TODO: This is deprecated and should be removed at some point
156
            fillNp = Utils.getNanopub(pageParams.get("fill").toString());
×
157
            fillMode = FillMode.SUPERSEDE;
×
158
        } else {
159
            fillNp = null;
×
160
            fillMode = null;
×
161
        }
162

163
        final TemplateData td = TemplateData.get();
×
164

165
        // TODO Properly integrate this namespace feature:
166
        String templateId = pageParams.get("template").toString();
×
167
        if (td.getTemplate(templateId).getTargetNamespace() != null) {
×
168
            targetNamespace = td.getTemplate(templateId).getTargetNamespace();
×
169
        }
170
        if (!pageParams.get("target-namespace").isNull()) {
×
171
            targetNamespace = pageParams.get("target-namespace").toString();
×
172
        }
173
        if (targetNamespace == null) {
×
174
            targetNamespace = Template.DEFAULT_TARGET_NAMESPACE;
×
175
        }
176
        String targetNamespaceLabel = targetNamespace + "...";
×
177
        targetNamespace = targetNamespace + "~~~ARTIFACTCODE~~~/";
×
178

179
        assertionContext = new TemplateContext(ContextType.ASSERTION, templateId, "statement", targetNamespace);
×
180
        assertionContext.setFillMode(fillMode);
×
181
        final String prTemplateId;
182
        if (pageParams.get("prtemplate").toString() != null) {
×
183
            prTemplateId = pageParams.get("prtemplate").toString();
×
184
        } else {
185
            if (fillNp != null && !fillOnlyAssertion) {
×
186
                if (td.getProvenanceTemplateId(fillNp) != null) {
×
187
                    prTemplateId = td.getProvenanceTemplateId(fillNp).stringValue();
×
188
                } else {
189
                    prTemplateId = "http://purl.org/np/RAcm8OurwUk15WOgBM9wySo-T3a5h6as4K8YR5MBrrxUc";
×
190
                }
191
            } else if (assertionContext.getTemplate().getDefaultProvenance() != null) {
×
192
                prTemplateId = assertionContext.getTemplate().getDefaultProvenance().stringValue();
×
193
            } else {
194
                prTemplateId = defaultProvTemplateId;
×
195
            }
196
        }
197
        provenanceContext = new TemplateContext(ContextType.PROVENANCE, prTemplateId, "pr-statement", targetNamespace);
×
198
        for (String t : fixedPubInfoTemplates) {
×
199
            // TODO consistently check for latest versions of templates here and below:
200
            TemplateContext c = new TemplateContext(ContextType.PUBINFO, t, "pi-statement", targetNamespace);
×
201
            pubInfoContexts.add(c);
×
202
            pubInfoContextMap.put(c.getTemplate().getId(), c);
×
203
            requiredPubInfoContexts.add(c);
×
204
        }
205
        if (fillMode == FillMode.SUPERSEDE) {
×
206
            TemplateContext c = new TemplateContext(ContextType.PUBINFO, supersedesPubinfoTemplateId, "pi-statement", targetNamespace);
×
207
            pubInfoContexts.add(c);
×
208
            pubInfoContextMap.put(supersedesPubinfoTemplateId, c);
×
209
            //requiredPubInfoContexts.add(c);
210
            c.setParam("np", fillNp.getUri().stringValue());
×
211
        } else if (fillMode == FillMode.DERIVE) {
×
212
            TemplateContext c = new TemplateContext(ContextType.PUBINFO, derivesFromPubinfoTemplateId, "pi-statement", targetNamespace);
×
213
            pubInfoContexts.add(c);
×
214
            pubInfoContextMap.put(derivesFromPubinfoTemplateId, c);
×
215
            c.setParam("np", fillNp.getUri().stringValue());
×
216
        }
217
        for (IRI r : assertionContext.getTemplate().getRequiredPubinfoElements()) {
×
218
            String latestId = QueryApiAccess.getLatestVersionId(r.stringValue());
×
219
            if (pubInfoContextMap.containsKey(r.stringValue()) || pubInfoContextMap.containsKey(latestId)) continue;
×
220
            TemplateContext c = new TemplateContext(ContextType.PUBINFO, r.stringValue(), "pi-statement", targetNamespace);
×
221
            pubInfoContexts.add(c);
×
222
            pubInfoContextMap.put(c.getTemplateId(), c);
×
223
            requiredPubInfoContexts.add(c);
×
224
        }
×
225
        Map<Integer, TemplateContext> piParamIdMap = new HashMap<>();
×
226
        for (String k : pageParams.getNamedKeys()) {
×
227
            if (!k.matches("pitemplate[1-9][0-9]*")) continue;
×
228
            Integer i = Integer.parseInt(k.replaceFirst("^pitemplate([1-9][0-9]*)$", "$1"));
×
229
            String tid = pageParams.get(k).toString();
×
230
            // TODO Allow for automatically using latest template version:
231
            //String piTempalteIdLatest = QueryApiAccess.getLatestVersionId(tid);
232
            TemplateContext c = createPubinfoContext(tid);
×
233
            if (piParamIdMap.containsKey(i)) {
×
234
                // TODO: handle this error better
235
                logger.error("ERROR: pitemplate param identifier assigned multiple times: {}", i);
×
236
            }
237
            piParamIdMap.put(i, c);
×
238
        }
×
239
        if (fillNp != null && !fillOnlyAssertion) {
×
240
            for (IRI piTemplateId : td.getPubinfoTemplateIds(fillNp)) {
×
241
                String piTempalteIdLatest = QueryApiAccess.getLatestVersionId(piTemplateId.stringValue());
×
242
                if (piTempalteIdLatest.equals(supersedesPubinfoTemplateId)) continue;
×
243
                if (!pubInfoContextMap.containsKey(piTempalteIdLatest)) {
×
244
                    // TODO Allow for automatically using latest template version
245
                    createPubinfoContext(piTemplateId.stringValue());
×
246
                }
247
            }
×
248
        }
249
        for (String k : pageParams.getNamedKeys()) {
×
250
            if (k.startsWith("param_")) assertionContext.setParam(k.substring(6), pageParams.get(k).toString());
×
251
            if (k.startsWith("prparam_")) provenanceContext.setParam(k.substring(8), pageParams.get(k).toString());
×
252
            if (k.matches("piparam[1-9][0-9]*_.*")) {
×
253
                Integer i = Integer.parseInt(k.replaceFirst("^piparam([1-9][0-9]*)_.*$", "$1"));
×
254
                if (!piParamIdMap.containsKey(i)) {
×
255
                    // TODO: handle this error better
256
                    logger.error("ERROR: pitemplate param identifier not found: {}", i);
×
257
                    continue;
×
258
                }
259
                String n = k.replaceFirst("^piparam[1-9][0-9]*_(.*)$", "$1");
×
260
                logger.info(n);
×
261
                piParamIdMap.get(i).setParam(n, pageParams.get(k).toString());
×
262
            }
263
        }
×
264

265
        // Init statements only now, in order to pick up parameter values:
266
        assertionContext.initStatements();
×
267
        provenanceContext.initStatements();
×
268
        for (TemplateContext c : pubInfoContexts) {
×
269
            c.initStatements();
×
270
        }
×
271

272
        String latestAssertionId = QueryApiAccess.getLatestVersionId(assertionContext.getTemplateId());
×
273
        if (!assertionContext.getTemplateId().equals(latestAssertionId)) {
×
274
            add(new Label("newversion", "There is a new version of this assertion template:"));
×
275
            PageParameters params = new PageParameters(pageParams);
×
276
            params.set("template", latestAssertionId).remove("formobj");
×
277
            add(new BookmarkablePageLink<Void>("newversionlink", publishPageClass, params));
×
278
            if ("latest".equals(pageParams.get("template-version").toString())) {
×
279
                throw new RestartResponseException(publishPageClass, params);
×
280
            }
281
        } else {
×
282
            add(new Label("newversion", "").setVisible(false));
×
283
            add(new Label("newversionlink", "").setVisible(false));
×
284
        }
285

286
        final Nanopub improveNp;
287
        if (!pageParams.get("improve").isNull()) {
×
288
            improveNp = Utils.getNanopub(pageParams.get("improve").toString());
×
289
        } else {
290
            improveNp = null;
×
291
        }
292

293
        final List<Statement> unusedStatementList = new ArrayList<>();
×
294
        final List<Statement> unusedPrStatementList = new ArrayList<>();
×
295
        final List<Statement> unusedPiStatementList = new ArrayList<>();
×
296
        if (fillNp != null) {
×
297
            ValueFiller filler = new ValueFiller(fillNp, ContextType.ASSERTION, true, fillMode);
×
298
            filler.fill(assertionContext);
×
299
            unusedStatementList.addAll(filler.getUnusedStatements());
×
300

301
            if (!fillOnlyAssertion) {
×
302
                ValueFiller prFiller = new ValueFiller(fillNp, ContextType.PROVENANCE, true);
×
303
                prFiller.fill(provenanceContext);
×
304
                unusedPrStatementList.addAll(prFiller.getUnusedStatements());
×
305

306
                ValueFiller piFiller = new ValueFiller(fillNp, ContextType.PUBINFO, true);
×
307
                if (!assertionContext.getTemplate().getTargetNanopubTypes().isEmpty()) {
×
308
                    for (Statement st : new ArrayList<>(piFiller.getUnusedStatements())) {
×
309
                        if (st.getSubject().stringValue().equals(LocalUri.PREFIX + "nanopub") && st.getPredicate().equals(NPX.HAS_NANOPUB_TYPE)) {
×
310
                            if (assertionContext.getTemplate().getTargetNanopubTypes().contains(st.getObject())) {
×
311
                                piFiller.removeUnusedStatement(st);
×
312
                            }
313
                        }
314
                    }
×
315
                }
316
                for (TemplateContext c : pubInfoContexts) {
×
317
                    piFiller.fill(c);
×
318
                }
×
319
                piFiller.removeUnusedStatements(NanodashSession.get().getUserIri(), FOAF.NAME, null);
×
320
                if (piFiller.hasUnusedStatements()) {
×
321
                    final String handcodedStatementsTemplateId = "https://w3id.org/np/RAMEgudZsQ1bh1fZhfYnkthqH6YSXpghSE_DEN1I-6eAI";
×
322
                    if (!pubInfoContextMap.containsKey(handcodedStatementsTemplateId)) {
×
323
                        TemplateContext c = createPubinfoContext(handcodedStatementsTemplateId);
×
324
                        c.initStatements();
×
325
                        piFiller.fill(c);
×
326
                    }
327
                }
328
                unusedPiStatementList.addAll(piFiller.getUnusedStatements());
×
329
                // TODO: Also use pubinfo templates stated in nanopub to be filled in?
330
//                                Set<IRI> pubinfoTemplateIds = Template.getPubinfoTemplateIds(fillNp);
331
//                                if (!pubinfoTemplateIds.isEmpty()) {
332
//                                        ValueFiller piFiller = new ValueFiller(fillNp, ContextType.PUBINFO);
333
//                                        for (IRI pubinfoTemplateId : pubinfoTemplateIds) {
334
//                                                // TODO: Make smart choice on the ordering in trying to fill in all pubinfo elements
335
//                                                piFiller.fill(pubInfoContextMap.get(pubinfoTemplateId.stringValue()));
336
//                                        }
337
//                                        warningMessage += (piFiller.getWarningMessage() == null ? "" : "Publication info: " + piFiller.getWarningMessage() + " ");
338
//                                }
339
            }
340
        } else if (improveNp != null) {
×
341
            ValueFiller filler = new ValueFiller(improveNp, ContextType.ASSERTION, true);
×
342
            filler.fill(assertionContext);
×
343
            unusedStatementList.addAll(filler.getUnusedStatements());
×
344
        }
345
        if (!unusedStatementList.isEmpty()) {
×
346
            add(new Label("warnings", "Some content from the existing nanopublication could not be filled in:"));
×
347
        } else {
348
            add(new Label("warnings", "").setVisible(false));
×
349
        }
350
        add(new DataView<Statement>("unused-statements", new ListDataProvider<Statement>(unusedStatementList)) {
×
351

352
            private static final long serialVersionUID = 1L;
353

354
            @Override
355
            protected void populateItem(Item<Statement> item) {
356
                item.add(new TripleItem("unused-statement", item.getModelObject(), (fillNp != null ? fillNp : improveNp), null));
×
357
            }
×
358

359
        });
360
        add(new DataView<Statement>("unused-prstatements", new ListDataProvider<Statement>(unusedPrStatementList)) {
×
361

362
            private static final long serialVersionUID = 1L;
363

364
            @Override
365
            protected void populateItem(Item<Statement> item) {
366
                item.add(new TripleItem("unused-prstatement", item.getModelObject(), (fillNp != null ? fillNp : improveNp), null));
×
367
            }
×
368

369
        });
370
        add(new DataView<Statement>("unused-pistatements", new ListDataProvider<Statement>(unusedPiStatementList)) {
×
371

372
            private static final long serialVersionUID = 1L;
373

374
            @Override
375
            protected void populateItem(Item<Statement> item) {
376
                item.add(new TripleItem("unused-pistatement", item.getModelObject(), (fillNp != null ? fillNp : improveNp), null));
×
377
            }
×
378

379
        });
380

381
        // Finalize statements, which picks up parameter values in repetitions:
382
        assertionContext.finalizeStatements();
×
383
        provenanceContext.finalizeStatements();
×
384
        for (TemplateContext c : pubInfoContexts) {
×
385
            c.finalizeStatements();
×
386
        }
×
387

388
        final CheckBox consentCheck = new CheckBox("consentcheck", new Model<>(false));
×
389
        consentCheck.setRequired(true);
×
390
        consentCheck.add(new InvalidityHighlighting());
×
391
        consentCheck.add(new IValidator<Boolean>() {
×
392

393
            private static final long serialVersionUID = 1L;
394

395
            @Override
396
            public void validate(IValidatable<Boolean> validatable) {
397
                if (!Boolean.TRUE.equals(validatable.getValue())) {
×
398
                    validatable.error(new ValidationError("You need to check the checkbox that you understand the consequences."));
×
399
                }
400
            }
×
401

402
        });
403

404
        form = new Form<Void>("form") {
×
405

406
            private static final long serialVersionUID = 1L;
407

408
            @Override
409
            protected void onConfigure() {
410
                super.onConfigure();
×
411
                form.getFeedbackMessages().clear();
×
412
//                                formComponents.clear();
413
            }
×
414

415
            protected void onSubmit() {
416
                logger.info("Publish form submitted");
×
417
                Nanopub signedNp = null;
×
418
                try {
419
                    Nanopub np = createNanopub();
×
420
                    logger.info("Nanopublication created: {}", np.getUri());
×
421
                    TransformContext tc = new TransformContext(SignatureAlgorithm.RSA, NanodashSession.get().getKeyPair(), NanodashSession.get().getUserIri(), false, false, false);
×
422
                    signedNp = SignNanopub.signAndTransform(np, tc);
×
423
                    logger.info("Nanopublication signed: {}", signedNp.getUri());
×
424
                    String npUrl = PublishNanopub.publish(signedNp);
×
425
                    logger.info("Nanopublication published: {}", npUrl);
×
426
                } catch (Exception ex) {
×
427
                    signedNp = null;
×
428
                    logger.error("Nanopublication publishing failed: {}", ex.getMessage());
×
429
                    String message = ex.getClass().getName();
×
430
                    if (ex.getMessage() != null) message = ex.getMessage();
×
431
                    feedbackPanel.error(message);
×
432
                }
×
433
                if (signedNp != null) {
×
434
                    throw new RestartResponseException(getConfirmPage(signedNp, pageParams));
×
435
                } else {
436
                    logger.error("Nanopublication publishing failed");
×
437
                }
438
            }
×
439

440
            @Override
441
            protected void onValidate() {
442
                super.onValidate();
×
443
                for (Component fc : assertionContext.getComponents()) {
×
444
                    processFeedback(fc);
×
445
                }
×
446
                for (Component fc : provenanceContext.getComponents()) {
×
447
                    processFeedback(fc);
×
448
                }
×
449
                for (TemplateContext c : pubInfoContexts) {
×
450
                    for (Component fc : c.getComponents()) {
×
451
                        processFeedback(fc);
×
452
                    }
×
453
                }
×
454
            }
×
455

456
            private void processFeedback(Component c) {
457
                if (c instanceof FormComponent) {
×
458
                    ((FormComponent<?>) c).processInput();
×
459
                }
460
                for (FeedbackMessage fm : c.getFeedbackMessages()) {
×
461
                    form.getFeedbackMessages().add(fm);
×
462
                }
×
463
            }
×
464

465
        };
466
        form.setOutputMarkupId(true);
×
467

468
        form.add(new Label("nanopub-namespace", targetNamespaceLabel));
×
469

470
        form.add(new BookmarkablePageLink<Void>("templatelink", ExplorePage.class, new PageParameters().add("id", assertionContext.getTemplate().getId())));
×
471
        form.add(new Label("templatename", assertionContext.getTemplate().getLabel()));
×
472
        String description = assertionContext.getTemplate().getLabel();
×
473
        if (description == null) description = "";
×
474
        form.add(new Label("templatedesc", assertionContext.getTemplate().getDescription()).setEscapeModelStrings(false));
×
475

476
        form.add(new ListView<StatementItem>("statements", assertionContext.getStatementItems()) {
×
477

478
            private static final long serialVersionUID = 1L;
479

480
            protected void populateItem(ListItem<StatementItem> item) {
481
                item.add(item.getModelObject());
×
482
            }
×
483

484
        });
485

486
        final Map<String, Boolean> handledProvTemplates = new HashMap<>();
×
487
        final String defaultProvTemplateId;
488
        if (assertionContext.getTemplate().getDefaultProvenance() != null) {
×
489
            defaultProvTemplateId = assertionContext.getTemplate().getDefaultProvenance().stringValue();
×
490
            handledProvTemplates.put(defaultProvTemplateId, true);
×
491
        } else {
492
            defaultProvTemplateId = null;
×
493
        }
494
        final List<String> recommendedProvTemplateOptionIds = new ArrayList<>();
×
495
        final List<String> provTemplateOptionIds = new ArrayList<>();
×
496
        if (pageParams.get("prtemplate-options").isNull()) {
×
497
            // TODO Make this dynamic and consider updated templates:
498
            recommendedProvTemplateOptionIds.add("https://w3id.org/np/RA7lSq6MuK_TIC6JMSHvLtee3lpLoZDOqLJCLXevnrPoU");
×
499
            recommendedProvTemplateOptionIds.add("http://purl.org/np/RAcTpoh5Ra0ssqmcpOgWdaZ_YiPE6demO6cpw-2RvSNs8");
×
500
            recommendedProvTemplateOptionIds.add("http://purl.org/np/RA4LGtuOqTIMqVAkjnfBXk1YDcAPNadP5CGiaJiBkdHCQ");
×
501
            recommendedProvTemplateOptionIds.add("http://purl.org/np/RAl_-VTw9Re_uRF8r8y0rjlfnu7FlhTa8xg_8xkcweqiE");
×
502
            recommendedProvTemplateOptionIds.add("https://w3id.org/np/RASORV2mMEVpS4lWh2bwUTEcV-RWjbD9RPbN7J0PIeYAU");
×
503
            recommendedProvTemplateOptionIds.add("http://purl.org/np/RAjkBbM5yQm7hKH1l_Jk3HAUqWi3Bd57TPmAOZCsZmi_M");
×
504
            recommendedProvTemplateOptionIds.add("http://purl.org/np/RAGXx_k9eQMnXaCbsXMsJbGClwZtQEGNg0GVJu6amdAVw");
×
505
            recommendedProvTemplateOptionIds.add("http://purl.org/np/RA1fnITI3Pu1UQ0CHghNpys3JwQrM32LBnjmDLoayp9-4");
×
506
            recommendedProvTemplateOptionIds.add("http://purl.org/np/RAJgbsGeGdTG-zq_gU0TLw4s3raMgoRk-mPlc2DSLXvE0");
×
507
            recommendedProvTemplateOptionIds.add("http://purl.org/np/RA6SXfhUY-xeblZU8HhPddw6tsu-C5NXevG6C_zv4bMxU");
×
508
            for (String s : recommendedProvTemplateOptionIds) {
×
509
                handledProvTemplates.put(s, true);
×
510
            }
×
511

512
            for (ApiResponseEntry t : td.getProvenanceTemplates()) {
×
513
                String tid = t.get("np");
×
514
                if (handledProvTemplates.containsKey(tid)) continue;
×
515
                provTemplateOptionIds.add(tid);
×
516
                handledProvTemplates.put(tid, true);
×
517
            }
×
518
        } else {
519
            for (String s : pageParams.get("prtemplate-options").toString().split(" ")) {
×
520
                if (handledProvTemplates.containsKey(s)) continue;
×
521
                recommendedProvTemplateOptionIds.add(s);
×
522
                handledProvTemplates.put(s, true);
×
523
            }
524
        }
525

526
        ChoiceProvider<String> prTemplateChoiceProvider = new ChoiceProvider<String>() {
×
527

528
            private static final long serialVersionUID = 1L;
529

530
            @Override
531
            public String getDisplayValue(String object) {
532
                if (object == null || object.isEmpty()) return "";
×
533
                Template t = td.getTemplate(object);
×
534
                if (t != null) return t.getLabel();
×
535
                return object;
×
536
            }
537

538
            @Override
539
            public String getIdValue(String object) {
540
                return object;
×
541
            }
542

543
            // Getting strange errors with Tomcat if this method is not overridden:
544
            @Override
545
            public void detach() {
546
            }
×
547

548
            @Override
549
            public void query(String term, int page, Response<String> response) {
550
                if (term == null) term = "";
×
551
                term = term.toLowerCase();
×
552
                if (pageParams.get("prtemplate").toString() != null) {
×
553
                    // Using this work-around with "——" because 'optgroup' is not available through Wicket's Select2 classes
554
                    response.add("—— default for this link ——");
×
555
                    response.add(prTemplateId);
×
556
                }
557
                if (defaultProvTemplateId != null) {
×
558
                    response.add("—— default for this template ——");
×
559
                    response.add(defaultProvTemplateId);
×
560
                }
561
                if (!recommendedProvTemplateOptionIds.isEmpty()) {
×
562
                    if (pageParams.get("prtemplate-options").isNull()) {
×
563
                        response.add("—— recommended ——");
×
564
                    }
565
                    for (String s : recommendedProvTemplateOptionIds) {
×
566
                        if (s.toLowerCase().contains(term) || getDisplayValue(s).toLowerCase().contains(term)) {
×
567
                            response.add(s);
×
568
                        }
569
                    }
×
570
                }
571
                if (!provTemplateOptionIds.isEmpty()) {
×
572
                    response.add("—— others ——");
×
573
                    for (String s : provTemplateOptionIds) {
×
574
                        if (s.toLowerCase().contains(term) || getDisplayValue(s).toLowerCase().contains(term)) {
×
575
                            response.add(s);
×
576
                        }
577
                    }
×
578
                }
579
            }
×
580

581
            @Override
582
            public Collection<String> toChoices(Collection<String> ids) {
583
                return ids;
×
584
            }
585

586
        };
587
        final IModel<String> prTemplateModel = Model.of(provenanceContext.getTemplate().getId());
×
588
        Select2Choice<String> prTemplateChoice = new Select2Choice<String>("prtemplate", prTemplateModel, prTemplateChoiceProvider);
×
589
        prTemplateChoice.setRequired(true);
×
590
        prTemplateChoice.getSettings().setCloseOnSelect(true);
×
591
        prTemplateChoice.add(new AjaxFormComponentUpdatingBehavior("change") {
×
592

593
            private static final long serialVersionUID = 1L;
594

595
            @Override
596
            protected void onUpdate(AjaxRequestTarget target) {
597
                String o = prTemplateModel.getObject();
×
598
                if (o.startsWith("——")) {
×
599
                    o = provenanceContext.getTemplate().getId();
×
600
                    prTemplateModel.setObject(o);
×
601
                }
602
                provenanceContext = new TemplateContext(ContextType.PROVENANCE, prTemplateModel.getObject(), "pr-statement", targetNamespace);
×
603
                provenanceContext.initStatements();
×
604
                refreshProvenance(target);
×
605
                provenanceContext.finalizeStatements();
×
606
            }
×
607

608
        });
609
        form.add(prTemplateChoice);
×
610
        refreshProvenance(null);
×
611

612
        final Map<String, Boolean> handledPiTemplates = new HashMap<>();
×
613
        final List<String> recommendedPiTemplateOptionIds = new ArrayList<>();
×
614
        final List<String> piTemplateOptionIds = new ArrayList<>();
×
615
        // TODO Make this dynamic and consider updated templates:
616
        recommendedPiTemplateOptionIds.add("http://purl.org/np/RAXflINqt3smqxV5Aq7E9lzje4uLdkKIOefa6Bp8oJ8CY");
×
617
        recommendedPiTemplateOptionIds.add("https://w3id.org/np/RARW4MsFkHuwjycNElvEVtuMjpf4yWDL10-0C5l2MqqRQ");
×
618
        recommendedPiTemplateOptionIds.add("https://w3id.org/np/RA16U9Wo30ObhrK1NzH7EsmVRiRtvEuEA_Dfc-u8WkUCA");
×
619
        recommendedPiTemplateOptionIds.add("http://purl.org/np/RAdyqI6k07V5nAS82C6hvIDtNWk179EIV4DV-sLbOFKg4");
×
620
        recommendedPiTemplateOptionIds.add("https://w3id.org/np/RAjvEpLZUE7rMoa8q6mWSsN6utJDp-5FmgO47YGsbgw3w");
×
621
        recommendedPiTemplateOptionIds.add("http://purl.org/np/RAxuGRKID6yNg63V5Mf0ot2NjncOnodh-mkN3qT_1txGI");
×
622
        for (TemplateContext c : pubInfoContexts) {
×
623
            String s = c.getTemplate().getId();
×
624
            handledPiTemplates.put(s, true);
×
625
        }
×
626
        for (String s : recommendedPiTemplateOptionIds) {
×
627
            handledPiTemplates.put(s, true);
×
628
        }
×
629

630
        for (ApiResponseEntry entry : td.getPubInfoTemplates()) {
×
631
            String tid = entry.get("np");
×
632
            if (handledPiTemplates.containsKey(tid)) continue;
×
633
            piTemplateOptionIds.add(tid);
×
634
            handledPiTemplates.put(tid, true);
×
635
        }
×
636

637
        ChoiceProvider<String> piTemplateChoiceProvider = new ChoiceProvider<String>() {
×
638

639
            private static final long serialVersionUID = 1L;
640

641
            @Override
642
            public String getDisplayValue(String object) {
643
                if (object == null || object.isEmpty()) return "";
×
644
                Template t = td.getTemplate(object);
×
645
                if (t != null) return t.getLabel();
×
646
                return object;
×
647
            }
648

649
            @Override
650
            public String getIdValue(String object) {
651
                return object;
×
652
            }
653

654
            // Getting strange errors with Tomcat if this method is not overridden:
655
            @Override
656
            public void detach() {
657
            }
×
658

659
            @Override
660
            public void query(String term, int page, Response<String> response) {
661
                if (term == null) term = "";
×
662
                term = term.toLowerCase();
×
663
                if (!recommendedPiTemplateOptionIds.isEmpty()) {
×
664
                    response.add("—— recommended ——");
×
665
                    for (String s : recommendedPiTemplateOptionIds) {
×
666
                        boolean isAlreadyUsed = false;
×
667
                        for (TemplateContext c : pubInfoContexts) {
×
668
                            // TODO: make this more efficient/nicer
669
                            if (c.getTemplate().getId().equals(s)) {
×
670
                                isAlreadyUsed = true;
×
671
                                break;
×
672
                            }
673
                        }
×
674
                        if (isAlreadyUsed) continue;
×
675
                        if (s.toLowerCase().contains(term) || getDisplayValue(s).toLowerCase().contains(term)) {
×
676
                            response.add(s);
×
677
                        }
678
                    }
×
679
                }
680
                if (!piTemplateOptionIds.isEmpty()) {
×
681
                    response.add("—— others ——");
×
682
                    for (String s : piTemplateOptionIds) {
×
683
                        boolean isAlreadyUsed = false;
×
684
                        for (TemplateContext c : pubInfoContexts) {
×
685
                            // TODO: make this more efficient/nicer
686
                            if (c.getTemplate().getId().equals(s)) {
×
687
                                isAlreadyUsed = true;
×
688
                                break;
×
689
                            }
690
                        }
×
691
                        if (isAlreadyUsed) continue;
×
692
                        if (s.toLowerCase().contains(term) || getDisplayValue(s).toLowerCase().contains(term)) {
×
693
                            response.add(s);
×
694
                        }
695
                    }
×
696
                }
697
            }
×
698

699
            @Override
700
            public Collection<String> toChoices(Collection<String> ids) {
701
                return ids;
×
702
            }
703

704
        };
705
        final IModel<String> newPiTemplateModel = Model.of();
×
706
        Select2Choice<String> piTemplateChoice = new Select2Choice<String>("pitemplate", newPiTemplateModel, piTemplateChoiceProvider);
×
707
        piTemplateChoice.getSettings().setCloseOnSelect(true);
×
708
        piTemplateChoice.getSettings().setPlaceholder("add element...");
×
709
        piTemplateChoice.add(new AjaxFormComponentUpdatingBehavior("change") {
×
710

711
            private static final long serialVersionUID = 1L;
712

713
            @Override
714
            protected void onUpdate(AjaxRequestTarget target) {
715
                if (newPiTemplateModel.getObject().startsWith("——")) {
×
716
                    newPiTemplateModel.setObject(null);
×
717
                    refreshPubInfo(target);
×
718
                    return;
×
719
                }
720
                String id = newPiTemplateModel.getObject();
×
721
                TemplateContext c = new TemplateContext(ContextType.PUBINFO, id, "pi-statement", targetNamespace);
×
722
                c.initStatements();
×
723
                pubInfoContexts.add(c);
×
724
                newPiTemplateModel.setObject(null);
×
725
                refreshPubInfo(target);
×
726
                c.finalizeStatements();
×
727
            }
×
728

729
        });
730
        form.add(piTemplateChoice);
×
731
        refreshPubInfo(null);
×
732

733
        form.add(consentCheck);
×
734
        add(form);
×
735

736
        feedbackPanel = new FeedbackPanel("feedback");
×
737
        feedbackPanel.setOutputMarkupId(true);
×
738
        add(feedbackPanel);
×
739
    }
×
740

741
    private void refreshProvenance(AjaxRequestTarget target) {
742
        if (target != null) {
×
743
            form.remove("prtemplatelink");
×
744
            form.remove("pr-statements");
×
745
            target.add(form);
×
746
            target.appendJavaScript("updateElements();");
×
747
        }
748
        form.add(new BookmarkablePageLink<Void>("prtemplatelink", ExplorePage.class, new PageParameters().add("id", provenanceContext.getTemplate().getId())));
×
749
        ListView<StatementItem> list = new ListView<StatementItem>("pr-statements", provenanceContext.getStatementItems()) {
×
750

751
            private static final long serialVersionUID = 1L;
752

753
            protected void populateItem(ListItem<StatementItem> item) {
754
                item.add(item.getModelObject());
×
755
            }
×
756

757
        };
758
        list.setOutputMarkupId(true);
×
759
        form.add(list);
×
760
    }
×
761

762
    private void refreshPubInfo(AjaxRequestTarget target) {
763
        ListView<TemplateContext> list = new ListView<TemplateContext>("pis", pubInfoContexts) {
×
764

765
            private static final long serialVersionUID = 1L;
766

767
            protected void populateItem(ListItem<TemplateContext> item) {
768
                final TemplateContext pic = item.getModelObject();
×
769
                item.add(new Label("pitemplatename", pic.getTemplate().getLabel()));
×
770
                item.add(new BookmarkablePageLink<Void>("pitemplatelink", ExplorePage.class, new PageParameters().add("id", pic.getTemplate().getId())));
×
771
                Label remove = new Label("piremove", "×");
×
772
                item.add(remove);
×
773
                remove.add(new AjaxEventBehavior("click") {
×
774
                    private static final long serialVersionUID = 1L;
775

776
                    @Override
777
                    protected void onEvent(AjaxRequestTarget target) {
778
                        pubInfoContexts.remove(pic);
×
779
                        target.add(PublishForm.this);
×
780
                        target.appendJavaScript("updateElements();");
×
781
                    }
×
782
                });
783
                if (requiredPubInfoContexts.contains(pic)) remove.setVisible(false);
×
784
                item.add(new ListView<StatementItem>("pi-statements", pic.getStatementItems()) {
×
785

786
                    private static final long serialVersionUID = 1L;
787

788
                    protected void populateItem(ListItem<StatementItem> item) {
789
                        item.add(item.getModelObject());
×
790
                    }
×
791

792
                });
793
            }
×
794

795
        };
796
        list.setOutputMarkupId(true);
×
797
        if (target == null) {
×
798
            form.add(list);
×
799
        } else {
800
            form.remove("pis");
×
801
            form.add(list);
×
802
            target.add(form);
×
803
            target.appendJavaScript("updateElements();");
×
804
        }
805
    }
×
806

807
    private TemplateContext createPubinfoContext(String piTemplateId) {
808
        TemplateContext c;
809
        if (pubInfoContextMap.containsKey(piTemplateId)) {
×
810
            c = pubInfoContextMap.get(piTemplateId);
×
811
        } else {
812
            c = new TemplateContext(ContextType.PUBINFO, piTemplateId, "pi-statement", targetNamespace);
×
813
            pubInfoContextMap.put(piTemplateId, c);
×
814
            pubInfoContexts.add(c);
×
815
        }
816
        return c;
×
817
    }
818

819
    private synchronized Nanopub createNanopub() throws MalformedNanopubException, NanopubAlreadyFinalizedException {
820
        assertionContext.getIntroducedIris().clear();
×
821
        NanopubCreator npCreator = new NanopubCreator(targetNamespace);
×
822
        npCreator.setAssertionUri(vf.createIRI(targetNamespace + "assertion"));
×
823
        assertionContext.propagateStatements(npCreator);
×
824
        provenanceContext.propagateStatements(npCreator);
×
825
        for (TemplateContext c : pubInfoContexts) {
×
826
            c.propagateStatements(npCreator);
×
827
        }
×
828
        for (IRI introducedIri : assertionContext.getIntroducedIris()) {
×
829
            npCreator.addPubinfoStatement(NPX.INTRODUCES, introducedIri);
×
830
        }
×
831
        for (IRI embeddedIri : assertionContext.getEmbeddedIris()) {
×
832
            npCreator.addPubinfoStatement(NPX.EMBEDS, embeddedIri);
×
833
        }
×
834
        npCreator.addNamespace("this", targetNamespace);
×
835
        npCreator.addNamespace("sub", targetNamespace + "/");
×
836
        npCreator.addTimestampNow();
×
837
        IRI templateUri = assertionContext.getTemplate().getNanopub().getUri();
×
838
        npCreator.addPubinfoStatement(NTEMPLATE.WAS_CREATED_FROM_TEMPLATE, templateUri);
×
839
        IRI prTemplateUri = provenanceContext.getTemplate().getNanopub().getUri();
×
840
        npCreator.addPubinfoStatement(NTEMPLATE.WAS_CREATED_FROM_PROVENANCE_TEMPLATE, prTemplateUri);
×
841
        for (TemplateContext c : pubInfoContexts) {
×
842
            IRI piTemplateUri = c.getTemplate().getNanopub().getUri();
×
843
            npCreator.addPubinfoStatement(NTEMPLATE.WAS_CREATED_FROM_PUBINFO_TEMPLATE, piTemplateUri);
×
844
        }
×
845
        String nanopubLabel = getNanopubLabel(npCreator);
×
846
        if (nanopubLabel != null) {
×
847
            npCreator.addPubinfoStatement(RDFS.LABEL, vf.createLiteral(nanopubLabel));
×
848
        }
849
        for (IRI type : assertionContext.getTemplate().getTargetNanopubTypes()) {
×
850
            npCreator.addPubinfoStatement(NPX.HAS_NANOPUB_TYPE, type);
×
851
        }
×
852
        IRI userIri = NanodashSession.get().getUserIri();
×
853
        if (User.getName(userIri) != null) {
×
854
            npCreator.addPubinfoStatement(userIri, FOAF.NAME, vf.createLiteral(User.getName(userIri)));
×
855
            npCreator.addNamespace("foaf", FOAF.NAMESPACE);
×
856
        }
857
        String websiteUrl = NanodashPreferences.get().getWebsiteUrl();
×
858
        if (websiteUrl != null) {
×
859
            npCreator.addPubinfoStatement(NPX.WAS_CREATED_AT, vf.createIRI(websiteUrl));
×
860
        }
861
        return npCreator.finalizeNanopub();
×
862
    }
863

864
    private String getNanopubLabel(NanopubCreator npCreator) {
865
        if (assertionContext.getTemplate().getNanopubLabelPattern() == null) return null;
×
866

867
        Map<IRI, String> labelMap = new HashMap<>();
×
868
        for (Statement st : npCreator.getCurrentPubinfoStatements()) {
×
869
            if (st.getPredicate().equals(RDFS.LABEL) && st.getObject() instanceof Literal objL) {
×
870
                labelMap.put((IRI) st.getSubject(), objL.stringValue());
×
871
            }
872
        }
×
873

874
        String nanopubLabel = assertionContext.getTemplate().getNanopubLabelPattern();
×
875
        while (nanopubLabel.matches(".*\\$\\{[_a-zA-Z0-9-]+\\}.*")) {
×
876
            String placeholderPostfix = nanopubLabel.replaceFirst("^.*\\$\\{([_a-zA-Z0-9-]+)\\}.*$", "$1");
×
877
            IRI placeholderIriHash = vf.createIRI(assertionContext.getTemplateId() + "#" + placeholderPostfix);
×
878
            IRI placeholderIriSlash = vf.createIRI(assertionContext.getTemplateId() + "/" + placeholderPostfix);
×
879
            IRI placeholderIri = null;
×
880
            String placeholderValue = "";
×
881
            if (assertionContext.getComponentModels().get(placeholderIriSlash) != null) {
×
882
                placeholderIri = placeholderIriSlash;
×
883
            } else {
884
                placeholderIri = placeholderIriHash;
×
885
            }
886
            IModel<String> m = assertionContext.getComponentModels().get(placeholderIri);
×
887
            if (m != null) placeholderValue = m.orElse("").getObject();
×
888
            if (placeholderValue == null) placeholderValue = "";
×
889
            String placeholderLabel = placeholderValue;
×
890
            if (assertionContext.getTemplate().isUriPlaceholder(placeholderIri)) {
×
891
                try {
892
                    // TODO Fix this. It doesn't work for placeholders with auto-encode placeholders, etc.
893
                    //      Not sure we need labels for these, but this code should be improved anyway.
894
                    String prefix = assertionContext.getTemplate().getPrefix(placeholderIri);
×
895
                    if (prefix != null) placeholderValue = prefix + placeholderValue;
×
896
                    IRI placeholderValueIri = vf.createIRI(placeholderValue);
×
897
                    String l = assertionContext.getTemplate().getLabel(placeholderValueIri);
×
898
                    if (labelMap.containsKey(placeholderValueIri)) {
×
899
                        l = labelMap.get(placeholderValueIri);
×
900
                    }
901
                    if (l == null) l = GuidedChoiceItem.getLabel(placeholderValue);
×
902
                    if (assertionContext.getTemplate().isAgentPlaceholder(placeholderIri) && !placeholderValue.isEmpty()) {
×
903
                        l = User.getName(vf.createIRI(placeholderValue));
×
904
                    }
905
                    if (l != null && !l.isEmpty()) {
×
906
                        placeholderLabel = l.replaceFirst(" - .*$", "");
×
907
                    } else {
908
                        placeholderLabel = Utils.getShortNameFromURI(placeholderValueIri);
×
909
                    }
910
                } catch (Exception ex) {
×
911
                    logger.error("Nanopub label placeholder IRI error: {}", ex.getMessage());
×
912
                }
×
913
            }
914
            placeholderLabel = placeholderLabel.replaceAll("\\s+", " ");
×
915
            if (placeholderLabel.length() > 100) placeholderLabel = placeholderLabel.substring(0, 97) + "...";
×
916
            nanopubLabel = Strings.CS.replace(nanopubLabel, "${" + placeholderPostfix + "}", placeholderLabel);
×
917
        }
×
918
        return nanopubLabel;
×
919
    }
920

921
    private NanodashPage getConfirmPage(Nanopub signedNp, PageParameters pageParams) {
922
        try {
923
            return (NanodashPage) confirmPageClass.getConstructor(Nanopub.class, PageParameters.class).newInstance(signedNp, pageParams);
×
924
        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException |
×
925
                 InvocationTargetException | NoSuchMethodException | SecurityException ex) {
926
            logger.error("Could not create instance of confirmation page: {}", ex.getMessage());
×
927
        }
928
        return null;
×
929
    }
930

931
    /**
932
     * Returns a hint whether the form is stateless or not.
933
     *
934
     * @return false if the form is stateful, true if it is stateless.
935
     */
936
    // This is supposed to solve the problem that sometimes (but only sometimes) form content is reset
937
    // if the user browses other pages in parallel:
938
    protected boolean getStatelessHint() {
939
        return false;
×
940
    }
941

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