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

knowledgepixels / nanodash / 17426932060

03 Sep 2025 07:58AM UTC coverage: 12.064% (+0.02%) from 12.048%
17426932060

push

github

tkuhn
Support "~~ARTIFACTCODE~~" as placeholder within IRIs in templates

331 of 3866 branches covered (8.56%)

Branch coverage included in aggregate %.

969 of 6910 relevant lines covered (14.02%)

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

61
import com.knowledgepixels.nanodash.NanodashPreferences;
62
import com.knowledgepixels.nanodash.NanodashSession;
63
import com.knowledgepixels.nanodash.QueryApiAccess;
64
import com.knowledgepixels.nanodash.User;
65
import com.knowledgepixels.nanodash.Utils;
66
import com.knowledgepixels.nanodash.page.ExplorePage;
67
import com.knowledgepixels.nanodash.page.NanodashPage;
68
import com.knowledgepixels.nanodash.template.ContextType;
69
import com.knowledgepixels.nanodash.template.Template;
70
import com.knowledgepixels.nanodash.template.TemplateContext;
71
import com.knowledgepixels.nanodash.template.TemplateData;
72
import com.knowledgepixels.nanodash.template.ValueFiller;
73

74
/**
75
 * Form for publishing a nanopublication.
76
 */
77
public class PublishForm extends Panel {
78

79
    private static final long serialVersionUID = 1L;
80
    private static final Logger logger = LoggerFactory.getLogger(PublishForm.class);
×
81

82
    private static ValueFactory vf = SimpleValueFactory.getInstance();
×
83

84
    private static String creatorPubinfoTemplateId = "https://w3id.org/np/RAukAcWHRDlkqxk7H2XNSegc1WnHI569INvNr-xdptDGI";
×
85
    private static String licensePubinfoTempalteId = "https://w3id.org/np/RA0J4vUn_dekg-U1kK3AOEt02p9mT2WO03uGxLDec1jLw";
×
86
    private static String defaultProvTemplateId = "https://w3id.org/np/RA7lSq6MuK_TIC6JMSHvLtee3lpLoZDOqLJCLXevnrPoU";
×
87
    private static String supersedesPubinfoTemplateId = "https://w3id.org/np/RAoTD7udB2KtUuOuAe74tJi1t3VzK0DyWS7rYVAq1GRvw";
×
88
    private static String derivesFromPubinfoTemplateId = "https://w3id.org/np/RARW4MsFkHuwjycNElvEVtuMjpf4yWDL10-0C5l2MqqRQ";
×
89

90
    private static String[] fixedPubInfoTemplates = new String[]{creatorPubinfoTemplateId, licensePubinfoTempalteId};
×
91

92
    /**
93
     * Fill modes for the nanopublication to be created.
94
     */
95
    public enum FillMode {USE, SUPERSEDE, DERIVE}
×
96

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

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

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

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

167
        final TemplateData td = TemplateData.get();
×
168

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

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

269
        // Init statements only now, in order to pick up parameter values:
270
        assertionContext.initStatements();
×
271
        provenanceContext.initStatements();
×
272
        for (TemplateContext c : pubInfoContexts) {
×
273
            c.initStatements();
×
274
        }
×
275

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

290
        final Nanopub improveNp;
291
        if (!pageParams.get("improve").isNull()) {
×
292
            improveNp = Utils.getNanopub(pageParams.get("improve").toString());
×
293
        } else {
294
            improveNp = null;
×
295
        }
296

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

305
            if (!fillOnlyAssertion) {
×
306
                ValueFiller prFiller = new ValueFiller(fillNp, ContextType.PROVENANCE, true);
×
307
                prFiller.fill(provenanceContext);
×
308
                unusedPrStatementList.addAll(prFiller.getUnusedStatements());
×
309

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

356
            private static final long serialVersionUID = 1L;
357

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

363
        });
364
        add(new DataView<Statement>("unused-prstatements", new ListDataProvider<Statement>(unusedPrStatementList)) {
×
365

366
            private static final long serialVersionUID = 1L;
367

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

373
        });
374
        add(new DataView<Statement>("unused-pistatements", new ListDataProvider<Statement>(unusedPiStatementList)) {
×
375

376
            private static final long serialVersionUID = 1L;
377

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

383
        });
384

385
        // Finalize statements, which picks up parameter values in repetitions:
386
        assertionContext.finalizeStatements();
×
387
        provenanceContext.finalizeStatements();
×
388
        for (TemplateContext c : pubInfoContexts) {
×
389
            c.finalizeStatements();
×
390
        }
×
391

392
        final CheckBox consentCheck = new CheckBox("consentcheck", new Model<>(false));
×
393
        consentCheck.setRequired(true);
×
394
        consentCheck.add(new InvalidityHighlighting());
×
395
        consentCheck.add(new IValidator<Boolean>() {
×
396

397
            private static final long serialVersionUID = 1L;
398

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

406
        });
407

408
        form = new Form<Void>("form") {
×
409

410
            private static final long serialVersionUID = 1L;
411

412
            @Override
413
            protected void onConfigure() {
414
                super.onConfigure();
×
415
                form.getFeedbackMessages().clear();
×
416
//                                formComponents.clear();
417
            }
×
418

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

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

460
            private void processFeedback(Component c) {
461
                if (c instanceof FormComponent) {
×
462
                    ((FormComponent<?>) c).processInput();
×
463
                }
464
                for (FeedbackMessage fm : c.getFeedbackMessages()) {
×
465
                    form.getFeedbackMessages().add(fm);
×
466
                }
×
467
            }
×
468

469
        };
470
        form.setOutputMarkupId(true);
×
471

472
        form.add(new Label("nanopub-namespace", targetNamespaceLabel));
×
473

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

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

482
            private static final long serialVersionUID = 1L;
483

484
            protected void populateItem(ListItem<StatementItem> item) {
485
                item.add(item.getModelObject());
×
486
            }
×
487

488
        });
489

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

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

530
        ChoiceProvider<String> prTemplateChoiceProvider = new ChoiceProvider<String>() {
×
531

532
            private static final long serialVersionUID = 1L;
533

534
            @Override
535
            public String getDisplayValue(String object) {
536
                if (object == null || object.isEmpty()) return "";
×
537
                Template t = td.getTemplate(object);
×
538
                if (t != null) return t.getLabel();
×
539
                return object;
×
540
            }
541

542
            @Override
543
            public String getIdValue(String object) {
544
                return object;
×
545
            }
546

547
            // Getting strange errors with Tomcat if this method is not overridden:
548
            @Override
549
            public void detach() {
550
            }
×
551

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

585
            @Override
586
            public Collection<String> toChoices(Collection<String> ids) {
587
                return ids;
×
588
            }
589

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

597
            private static final long serialVersionUID = 1L;
598

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

612
        });
613
        form.add(prTemplateChoice);
×
614
        refreshProvenance(null);
×
615

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

634
        for (ApiResponseEntry entry : td.getPubInfoTemplates()) {
×
635
            String tid = entry.get("np");
×
636
            if (handledPiTemplates.containsKey(tid)) continue;
×
637
            piTemplateOptionIds.add(tid);
×
638
            handledPiTemplates.put(tid, true);
×
639
        }
×
640

641
        ChoiceProvider<String> piTemplateChoiceProvider = new ChoiceProvider<String>() {
×
642

643
            private static final long serialVersionUID = 1L;
644

645
            @Override
646
            public String getDisplayValue(String object) {
647
                if (object == null || object.isEmpty()) return "";
×
648
                Template t = td.getTemplate(object);
×
649
                if (t != null) return t.getLabel();
×
650
                return object;
×
651
            }
652

653
            @Override
654
            public String getIdValue(String object) {
655
                return object;
×
656
            }
657

658
            // Getting strange errors with Tomcat if this method is not overridden:
659
            @Override
660
            public void detach() {
661
            }
×
662

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

703
            @Override
704
            public Collection<String> toChoices(Collection<String> ids) {
705
                return ids;
×
706
            }
707

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

715
            private static final long serialVersionUID = 1L;
716

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

733
        });
734
        form.add(piTemplateChoice);
×
735
        refreshPubInfo(null);
×
736

737
        form.add(consentCheck);
×
738
        add(form);
×
739

740
        feedbackPanel = new FeedbackPanel("feedback");
×
741
        feedbackPanel.setOutputMarkupId(true);
×
742
        add(feedbackPanel);
×
743
    }
×
744

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

755
            private static final long serialVersionUID = 1L;
756

757
            protected void populateItem(ListItem<StatementItem> item) {
758
                item.add(item.getModelObject());
×
759
            }
×
760

761
        };
762
        list.setOutputMarkupId(true);
×
763
        form.add(list);
×
764
    }
×
765

766
    private void refreshPubInfo(AjaxRequestTarget target) {
767
        ListView<TemplateContext> list = new ListView<TemplateContext>("pis", pubInfoContexts) {
×
768

769
            private static final long serialVersionUID = 1L;
770

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

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

790
                    private static final long serialVersionUID = 1L;
791

792
                    protected void populateItem(ListItem<StatementItem> item) {
793
                        item.add(item.getModelObject());
×
794
                    }
×
795

796
                });
797
            }
×
798

799
        };
800
        list.setOutputMarkupId(true);
×
801
        if (target == null) {
×
802
            form.add(list);
×
803
        } else {
804
            form.remove("pis");
×
805
            form.add(list);
×
806
            target.add(form);
×
807
            target.appendJavaScript("updateElements();");
×
808
        }
809
    }
×
810

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

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

868
    private String getNanopubLabel(NanopubCreator npCreator) {
869
        if (assertionContext.getTemplate().getNanopubLabelPattern() == null) return null;
×
870

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

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

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

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

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