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

knowledgepixels / nanodash / 17424747928

03 Sep 2025 06:13AM UTC coverage: 12.048% (-0.02%) from 12.066%
17424747928

push

github

tkuhn
Update dependencies and adapt to new exceptions in nanopub-java

331 of 3866 branches covered (8.56%)

Branch coverage included in aggregate %.

967 of 6908 relevant lines covered (14.0%)

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

58
import java.lang.reflect.InvocationTargetException;
59
import java.util.*;
60

61
/**
62
 * Form for publishing a nanopublication.
63
 */
64
public class PublishForm extends Panel {
65

66
    private static final long serialVersionUID = 1L;
67
    private static final Logger logger = LoggerFactory.getLogger(PublishForm.class);
×
68

69
    private static ValueFactory vf = SimpleValueFactory.getInstance();
×
70

71
    private static String creatorPubinfoTemplateId = "https://w3id.org/np/RAukAcWHRDlkqxk7H2XNSegc1WnHI569INvNr-xdptDGI";
×
72
    private static String licensePubinfoTempalteId = "https://w3id.org/np/RA0J4vUn_dekg-U1kK3AOEt02p9mT2WO03uGxLDec1jLw";
×
73
    private static String defaultProvTemplateId = "https://w3id.org/np/RA7lSq6MuK_TIC6JMSHvLtee3lpLoZDOqLJCLXevnrPoU";
×
74
    private static String supersedesPubinfoTemplateId = "https://w3id.org/np/RAoTD7udB2KtUuOuAe74tJi1t3VzK0DyWS7rYVAq1GRvw";
×
75
    private static String derivesFromPubinfoTemplateId = "https://w3id.org/np/RARW4MsFkHuwjycNElvEVtuMjpf4yWDL10-0C5l2MqqRQ";
×
76

77
    private static String[] fixedPubInfoTemplates = new String[]{creatorPubinfoTemplateId, licensePubinfoTempalteId};
×
78

79
    /**
80
     * Fill modes for the nanopublication to be created.
81
     */
82
    public enum FillMode {USE, SUPERSEDE, DERIVE}
×
83

84
    protected Form<?> form;
85
    protected FeedbackPanel feedbackPanel;
86
    private final TemplateContext assertionContext;
87
    private TemplateContext provenanceContext;
88
    private List<TemplateContext> pubInfoContexts = new ArrayList<>();
×
89
    private Map<String, TemplateContext> pubInfoContextMap = new HashMap<>();
×
90
    private List<TemplateContext> requiredPubInfoContexts = new ArrayList<>();
×
91
    private String targetNamespace;
92
    private Class<? extends WebPage> confirmPageClass;
93

94
    /**
95
     * Constructor for the PublishForm.
96
     *
97
     * @param id               the Wicket component ID
98
     * @param pageParams       the parameters for the page, which may include information on how to fill the form
99
     * @param publishPageClass the class of the page to redirect to after successful publication
100
     * @param confirmPageClass the class of the confirmation page to show after publication
101
     */
102
    public PublishForm(String id, final PageParameters pageParams, Class<? extends WebPage> publishPageClass, Class<? extends WebPage> confirmPageClass) {
103
        super(id);
×
104
        setOutputMarkupId(true);
×
105
        this.confirmPageClass = confirmPageClass;
×
106

107
        WebMarkupContainer linkMessageItem = new WebMarkupContainer("link-message-item");
×
108
        if (pageParams.get("link-message").isNull()) {
×
109
            linkMessageItem.add(new Label("link-message", ""));
×
110
            linkMessageItem.setVisible(false);
×
111
        } else {
112
            linkMessageItem.add(new Label("link-message", Utils.sanitizeHtml(pageParams.get("link-message").toString())).setEscapeModelStrings(false));
×
113
        }
114
        add(linkMessageItem);
×
115

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

154
        final TemplateData td = TemplateData.get();
×
155

156
        // TODO Properly integrate this namespace feature:
157
        String templateId = pageParams.get("template").toString();
×
158
        if (td.getTemplate(templateId).getTargetNamespace() != null) {
×
159
            targetNamespace = td.getTemplate(templateId).getTargetNamespace();
×
160
        }
161
        if (!pageParams.get("target-namespace").isNull()) {
×
162
            targetNamespace = pageParams.get("target-namespace").toString();
×
163
        }
164
        if (targetNamespace == null) {
×
165
            targetNamespace = Template.DEFAULT_TARGET_NAMESPACE;
×
166
        }
167
        String targetNamespaceLabel = targetNamespace + "...";
×
168
        targetNamespace = targetNamespace + "ARTIFACTCODE-PLACEHOLDER/";
×
169

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

256
        // Init statements only now, in order to pick up parameter values:
257
        assertionContext.initStatements();
×
258
        provenanceContext.initStatements();
×
259
        for (TemplateContext c : pubInfoContexts) {
×
260
            c.initStatements();
×
261
        }
×
262

263
        String latestAssertionId = QueryApiAccess.getLatestVersionId(assertionContext.getTemplateId());
×
264
        if (!assertionContext.getTemplateId().equals(latestAssertionId)) {
×
265
            add(new Label("newversion", "There is a new version of this assertion template:"));
×
266
            PageParameters params = new PageParameters(pageParams);
×
267
            params.set("template", latestAssertionId).remove("formobj");
×
268
            add(new BookmarkablePageLink<Void>("newversionlink", publishPageClass, params));
×
269
            if ("latest".equals(pageParams.get("template-version").toString())) {
×
270
                throw new RestartResponseException(publishPageClass, params);
×
271
            }
272
        } else {
×
273
            add(new Label("newversion", "").setVisible(false));
×
274
            add(new Label("newversionlink", "").setVisible(false));
×
275
        }
276

277
        final Nanopub improveNp;
278
        if (!pageParams.get("improve").isNull()) {
×
279
            improveNp = Utils.getNanopub(pageParams.get("improve").toString());
×
280
        } else {
281
            improveNp = null;
×
282
        }
283

284
        final List<Statement> unusedStatementList = new ArrayList<>();
×
285
        final List<Statement> unusedPrStatementList = new ArrayList<>();
×
286
        final List<Statement> unusedPiStatementList = new ArrayList<>();
×
287
        if (fillNp != null) {
×
288
            ValueFiller filler = new ValueFiller(fillNp, ContextType.ASSERTION, true, fillMode);
×
289
            filler.fill(assertionContext);
×
290
            unusedStatementList.addAll(filler.getUnusedStatements());
×
291

292
            if (!fillOnlyAssertion) {
×
293
                ValueFiller prFiller = new ValueFiller(fillNp, ContextType.PROVENANCE, true);
×
294
                prFiller.fill(provenanceContext);
×
295
                unusedPrStatementList.addAll(prFiller.getUnusedStatements());
×
296

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

343
            private static final long serialVersionUID = 1L;
344

345
            @Override
346
            protected void populateItem(Item<Statement> item) {
347
                item.add(new TripleItem("unused-statement", item.getModelObject(), (fillNp != null ? fillNp : improveNp), null));
×
348
            }
×
349

350
        });
351
        add(new DataView<Statement>("unused-prstatements", new ListDataProvider<Statement>(unusedPrStatementList)) {
×
352

353
            private static final long serialVersionUID = 1L;
354

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

360
        });
361
        add(new DataView<Statement>("unused-pistatements", new ListDataProvider<Statement>(unusedPiStatementList)) {
×
362

363
            private static final long serialVersionUID = 1L;
364

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

370
        });
371

372
        // Finalize statements, which picks up parameter values in repetitions:
373
        assertionContext.finalizeStatements();
×
374
        provenanceContext.finalizeStatements();
×
375
        for (TemplateContext c : pubInfoContexts) {
×
376
            c.finalizeStatements();
×
377
        }
×
378

379
        final CheckBox consentCheck = new CheckBox("consentcheck", new Model<>(false));
×
380
        consentCheck.setRequired(true);
×
381
        consentCheck.add(new InvalidityHighlighting());
×
382
        consentCheck.add(new IValidator<Boolean>() {
×
383

384
            private static final long serialVersionUID = 1L;
385

386
            @Override
387
            public void validate(IValidatable<Boolean> validatable) {
388
                if (!Boolean.TRUE.equals(validatable.getValue())) {
×
389
                    validatable.error(new ValidationError("You need to check the checkbox that you understand the consequences."));
×
390
                }
391
            }
×
392

393
        });
394

395
        form = new Form<Void>("form") {
×
396

397
            private static final long serialVersionUID = 1L;
398

399
            @Override
400
            protected void onConfigure() {
401
                super.onConfigure();
×
402
                form.getFeedbackMessages().clear();
×
403
//                                formComponents.clear();
404
            }
×
405

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

431
            @Override
432
            protected void onValidate() {
433
                super.onValidate();
×
434
                for (Component fc : assertionContext.getComponents()) {
×
435
                    processFeedback(fc);
×
436
                }
×
437
                for (Component fc : provenanceContext.getComponents()) {
×
438
                    processFeedback(fc);
×
439
                }
×
440
                for (TemplateContext c : pubInfoContexts) {
×
441
                    for (Component fc : c.getComponents()) {
×
442
                        processFeedback(fc);
×
443
                    }
×
444
                }
×
445
            }
×
446

447
            private void processFeedback(Component c) {
448
                if (c instanceof FormComponent) {
×
449
                    ((FormComponent<?>) c).processInput();
×
450
                }
451
                for (FeedbackMessage fm : c.getFeedbackMessages()) {
×
452
                    form.getFeedbackMessages().add(fm);
×
453
                }
×
454
            }
×
455

456
        };
457
        form.setOutputMarkupId(true);
×
458

459
        form.add(new Label("nanopub-namespace", targetNamespaceLabel));
×
460

461
        form.add(new BookmarkablePageLink<Void>("templatelink", ExplorePage.class, new PageParameters().add("id", assertionContext.getTemplate().getId())));
×
462
        form.add(new Label("templatename", assertionContext.getTemplate().getLabel()));
×
463
        String description = assertionContext.getTemplate().getLabel();
×
464
        if (description == null) description = "";
×
465
        form.add(new Label("templatedesc", assertionContext.getTemplate().getDescription()).setEscapeModelStrings(false));
×
466

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

469
            private static final long serialVersionUID = 1L;
470

471
            protected void populateItem(ListItem<StatementItem> item) {
472
                item.add(item.getModelObject());
×
473
            }
×
474

475
        });
476

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

503
            for (ApiResponseEntry t : td.getProvenanceTemplates()) {
×
504
                String tid = t.get("np");
×
505
                if (handledProvTemplates.containsKey(tid)) continue;
×
506
                provTemplateOptionIds.add(tid);
×
507
                handledProvTemplates.put(tid, true);
×
508
            }
×
509
        } else {
510
            for (String s : pageParams.get("prtemplate-options").toString().split(" ")) {
×
511
                if (handledProvTemplates.containsKey(s)) continue;
×
512
                recommendedProvTemplateOptionIds.add(s);
×
513
                handledProvTemplates.put(s, true);
×
514
            }
515
        }
516

517
        ChoiceProvider<String> prTemplateChoiceProvider = new ChoiceProvider<String>() {
×
518

519
            private static final long serialVersionUID = 1L;
520

521
            @Override
522
            public String getDisplayValue(String object) {
523
                if (object == null || object.isEmpty()) return "";
×
524
                Template t = td.getTemplate(object);
×
525
                if (t != null) return t.getLabel();
×
526
                return object;
×
527
            }
528

529
            @Override
530
            public String getIdValue(String object) {
531
                return object;
×
532
            }
533

534
            // Getting strange errors with Tomcat if this method is not overridden:
535
            @Override
536
            public void detach() {
537
            }
×
538

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

572
            @Override
573
            public Collection<String> toChoices(Collection<String> ids) {
574
                return ids;
×
575
            }
576

577
        };
578
        final IModel<String> prTemplateModel = Model.of(provenanceContext.getTemplate().getId());
×
579
        Select2Choice<String> prTemplateChoice = new Select2Choice<String>("prtemplate", prTemplateModel, prTemplateChoiceProvider);
×
580
        prTemplateChoice.setRequired(true);
×
581
        prTemplateChoice.getSettings().setCloseOnSelect(true);
×
582
        prTemplateChoice.add(new AjaxFormComponentUpdatingBehavior("change") {
×
583

584
            private static final long serialVersionUID = 1L;
585

586
            @Override
587
            protected void onUpdate(AjaxRequestTarget target) {
588
                String o = prTemplateModel.getObject();
×
589
                if (o.startsWith("——")) {
×
590
                    o = provenanceContext.getTemplate().getId();
×
591
                    prTemplateModel.setObject(o);
×
592
                }
593
                provenanceContext = new TemplateContext(ContextType.PROVENANCE, prTemplateModel.getObject(), "pr-statement", targetNamespace);
×
594
                provenanceContext.initStatements();
×
595
                refreshProvenance(target);
×
596
                provenanceContext.finalizeStatements();
×
597
            }
×
598

599
        });
600
        form.add(prTemplateChoice);
×
601
        refreshProvenance(null);
×
602

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

621
        for (ApiResponseEntry entry : td.getPubInfoTemplates()) {
×
622
            String tid = entry.get("np");
×
623
            if (handledPiTemplates.containsKey(tid)) continue;
×
624
            piTemplateOptionIds.add(tid);
×
625
            handledPiTemplates.put(tid, true);
×
626
        }
×
627

628
        ChoiceProvider<String> piTemplateChoiceProvider = new ChoiceProvider<String>() {
×
629

630
            private static final long serialVersionUID = 1L;
631

632
            @Override
633
            public String getDisplayValue(String object) {
634
                if (object == null || object.isEmpty()) return "";
×
635
                Template t = td.getTemplate(object);
×
636
                if (t != null) return t.getLabel();
×
637
                return object;
×
638
            }
639

640
            @Override
641
            public String getIdValue(String object) {
642
                return object;
×
643
            }
644

645
            // Getting strange errors with Tomcat if this method is not overridden:
646
            @Override
647
            public void detach() {
648
            }
×
649

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

690
            @Override
691
            public Collection<String> toChoices(Collection<String> ids) {
692
                return ids;
×
693
            }
694

695
        };
696
        final IModel<String> newPiTemplateModel = Model.of();
×
697
        Select2Choice<String> piTemplateChoice = new Select2Choice<String>("pitemplate", newPiTemplateModel, piTemplateChoiceProvider);
×
698
        piTemplateChoice.getSettings().setCloseOnSelect(true);
×
699
        piTemplateChoice.getSettings().setPlaceholder("add element...");
×
700
        piTemplateChoice.add(new AjaxFormComponentUpdatingBehavior("change") {
×
701

702
            private static final long serialVersionUID = 1L;
703

704
            @Override
705
            protected void onUpdate(AjaxRequestTarget target) {
706
                if (newPiTemplateModel.getObject().startsWith("——")) {
×
707
                    newPiTemplateModel.setObject(null);
×
708
                    refreshPubInfo(target);
×
709
                    return;
×
710
                }
711
                String id = newPiTemplateModel.getObject();
×
712
                TemplateContext c = new TemplateContext(ContextType.PUBINFO, id, "pi-statement", targetNamespace);
×
713
                c.initStatements();
×
714
                pubInfoContexts.add(c);
×
715
                newPiTemplateModel.setObject(null);
×
716
                refreshPubInfo(target);
×
717
                c.finalizeStatements();
×
718
            }
×
719

720
        });
721
        form.add(piTemplateChoice);
×
722
        refreshPubInfo(null);
×
723

724
        form.add(consentCheck);
×
725
        add(form);
×
726

727
        feedbackPanel = new FeedbackPanel("feedback");
×
728
        feedbackPanel.setOutputMarkupId(true);
×
729
        add(feedbackPanel);
×
730
    }
×
731

732
    private void refreshProvenance(AjaxRequestTarget target) {
733
        if (target != null) {
×
734
            form.remove("prtemplatelink");
×
735
            form.remove("pr-statements");
×
736
            target.add(form);
×
737
            target.appendJavaScript("updateElements();");
×
738
        }
739
        form.add(new BookmarkablePageLink<Void>("prtemplatelink", ExplorePage.class, new PageParameters().add("id", provenanceContext.getTemplate().getId())));
×
740
        ListView<StatementItem> list = new ListView<StatementItem>("pr-statements", provenanceContext.getStatementItems()) {
×
741

742
            private static final long serialVersionUID = 1L;
743

744
            protected void populateItem(ListItem<StatementItem> item) {
745
                item.add(item.getModelObject());
×
746
            }
×
747

748
        };
749
        list.setOutputMarkupId(true);
×
750
        form.add(list);
×
751
    }
×
752

753
    private void refreshPubInfo(AjaxRequestTarget target) {
754
        ListView<TemplateContext> list = new ListView<TemplateContext>("pis", pubInfoContexts) {
×
755

756
            private static final long serialVersionUID = 1L;
757

758
            protected void populateItem(ListItem<TemplateContext> item) {
759
                final TemplateContext pic = item.getModelObject();
×
760
                item.add(new Label("pitemplatename", pic.getTemplate().getLabel()));
×
761
                item.add(new BookmarkablePageLink<Void>("pitemplatelink", ExplorePage.class, new PageParameters().add("id", pic.getTemplate().getId())));
×
762
                Label remove = new Label("piremove", "×");
×
763
                item.add(remove);
×
764
                remove.add(new AjaxEventBehavior("click") {
×
765
                    private static final long serialVersionUID = 1L;
766

767
                    @Override
768
                    protected void onEvent(AjaxRequestTarget target) {
769
                        pubInfoContexts.remove(pic);
×
770
                        target.add(PublishForm.this);
×
771
                        target.appendJavaScript("updateElements();");
×
772
                    }
×
773
                });
774
                if (requiredPubInfoContexts.contains(pic)) remove.setVisible(false);
×
775
                item.add(new ListView<StatementItem>("pi-statements", pic.getStatementItems()) {
×
776

777
                    private static final long serialVersionUID = 1L;
778

779
                    protected void populateItem(ListItem<StatementItem> item) {
780
                        item.add(item.getModelObject());
×
781
                    }
×
782

783
                });
784
            }
×
785

786
        };
787
        list.setOutputMarkupId(true);
×
788
        if (target == null) {
×
789
            form.add(list);
×
790
        } else {
791
            form.remove("pis");
×
792
            form.add(list);
×
793
            target.add(form);
×
794
            target.appendJavaScript("updateElements();");
×
795
        }
796
    }
×
797

798
    private TemplateContext createPubinfoContext(String piTemplateId) {
799
        TemplateContext c;
800
        if (pubInfoContextMap.containsKey(piTemplateId)) {
×
801
            c = pubInfoContextMap.get(piTemplateId);
×
802
        } else {
803
            c = new TemplateContext(ContextType.PUBINFO, piTemplateId, "pi-statement", targetNamespace);
×
804
            pubInfoContextMap.put(piTemplateId, c);
×
805
            pubInfoContexts.add(c);
×
806
        }
807
        return c;
×
808
    }
809

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

855
    private String getNanopubLabel(NanopubCreator npCreator) {
856
        if (assertionContext.getTemplate().getNanopubLabelPattern() == null) return null;
×
857

858
        Map<IRI, String> labelMap = new HashMap<>();
×
859
        for (Statement st : npCreator.getCurrentPubinfoStatements()) {
×
860
            if (st.getPredicate().equals(RDFS.LABEL) && st.getObject() instanceof Literal objL) {
×
861
                labelMap.put((IRI) st.getSubject(), objL.stringValue());
×
862
            }
863
        }
×
864

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

912
    private NanodashPage getConfirmPage(Nanopub signedNp, PageParameters pageParams) {
913
        try {
914
            return (NanodashPage) confirmPageClass.getConstructor(Nanopub.class, PageParameters.class).newInstance(signedNp, pageParams);
×
915
        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException |
×
916
                 InvocationTargetException | NoSuchMethodException | SecurityException ex) {
917
            logger.error("Could not create instance of confirmation page: {}", ex.getMessage());
×
918
        }
919
        return null;
×
920
    }
921

922
    /**
923
     * Returns a hint whether the form is stateless or not.
924
     *
925
     * @return false if the form is stateful, true if it is stateless.
926
     */
927
    // This is supposed to solve the problem that sometimes (but only sometimes) form content is reset
928
    // if the user browses other pages in parallel:
929
    protected boolean getStatelessHint() {
930
        return false;
×
931
    }
932

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