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

knowledgepixels / nanodash / 20268226543

16 Dec 2025 12:39PM UTC coverage: 14.107% (-1.3%) from 15.358%
20268226543

push

github

ashleycaselli
refactor: replace VocabUtils with the ones defined in the nanopub-java library

526 of 4946 branches covered (10.63%)

Branch coverage included in aggregate %.

1452 of 9075 relevant lines covered (16.0%)

2.11 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.Strings;
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.*;
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 Logger logger = LoggerFactory.getLogger(PublishForm.class);
×
67

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

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

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

78
    /**
79
     * Fill modes for the nanopublication to be created.
80
     */
81
    public enum FillMode {
×
82
        /**
83
         * Use fill mode
84
         */
85
        USE,
×
86
        /**
87
         * Supersede fill mode
88
         */
89
        SUPERSEDE,
×
90
        /**
91
         * Derive fill mode
92
         */
93
        DERIVE
×
94
    }
95

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

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

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

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

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

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

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

255
            String mapping = pageParams.get("values-from-query-mapping").toString();
×
256
            String mapsFrom, mapsTo;
257
            if (mapping.contains(":")) {
×
258
                mapsFrom = mapping.split(":")[0];
×
259
                mapsTo = mapping.split(":")[1];
×
260
            } else {
261
                mapsFrom = mapping;
×
262
                mapsTo = mapping;
×
263
            }
264
            try {
265
                ApiResponse resp = QueryApiAccess.get(QueryRef.parseString(querySpec));
×
266
                int i = 0;
×
267
                for (ApiResponseEntry e : resp.getData()) {
×
268
                    String mapsToSuffix = "";
×
269
                    if (i > 0) mapsToSuffix = "__" + i;
×
270
                    assertionContext.setParam(mapsTo + mapsToSuffix, e.get(mapsFrom));
×
271
                    i++;
×
272
                }
×
273
            } catch (FailedApiCallException | APINotReachableException | NotEnoughAPIInstancesException |
×
274
                     NullPointerException ex) {
275
                ex.printStackTrace();
×
276
            }
×
277
        }
278
        for (String k : pageParams.getNamedKeys()) {
×
279
            if (k.startsWith("param_")) assertionContext.setParam(k.substring(6), pageParams.get(k).toString());
×
280
            if (k.startsWith("prparam_")) provenanceContext.setParam(k.substring(8), pageParams.get(k).toString());
×
281
            if (k.matches("piparam[1-9][0-9]*_.*")) {
×
282
                Integer i = Integer.parseInt(k.replaceFirst("^piparam([1-9][0-9]*)_.*$", "$1"));
×
283
                if (!piParamIdMap.containsKey(i)) {
×
284
                    // TODO: handle this error better
285
                    logger.error("ERROR: pitemplate param identifier not found: {}", i);
×
286
                    continue;
×
287
                }
288
                String n = k.replaceFirst("^piparam[1-9][0-9]*_(.*)$", "$1");
×
289
                logger.info(n);
×
290
                piParamIdMap.get(i).setParam(n, pageParams.get(k).toString());
×
291
            }
292
        }
×
293

294
        // Init statements only now, in order to pick up parameter values:
295
        assertionContext.initStatements();
×
296
        provenanceContext.initStatements();
×
297
        for (TemplateContext c : pubInfoContexts) {
×
298
            c.initStatements();
×
299
        }
×
300

301
        String latestAssertionId = QueryApiAccess.getLatestVersionId(assertionContext.getTemplateId());
×
302
        if (!assertionContext.getTemplateId().equals(latestAssertionId)) {
×
303
            add(new Label("newversion", "There is a new version of this assertion template:"));
×
304
            PageParameters params = new PageParameters(pageParams);
×
305
            params.set("template", latestAssertionId).remove("formobj");
×
306
            add(new BookmarkablePageLink<Void>("newversionlink", publishPageClass, params));
×
307
            if ("latest".equals(pageParams.get("template-version").toString())) {
×
308
                throw new RestartResponseException(publishPageClass, params);
×
309
            }
310
        } else {
×
311
            add(new Label("newversion", "").setVisible(false));
×
312
            add(new Label("newversionlink", "").setVisible(false));
×
313
        }
314

315
        final Nanopub improveNp;
316
        if (!pageParams.get("improve").isNull()) {
×
317
            improveNp = Utils.getNanopub(pageParams.get("improve").toString());
×
318
        } else {
319
            improveNp = null;
×
320
        }
321

322
        final List<Statement> unusedStatementList = new ArrayList<>();
×
323
        final List<Statement> unusedPrStatementList = new ArrayList<>();
×
324
        final List<Statement> unusedPiStatementList = new ArrayList<>();
×
325
        if (fillNp != null) {
×
326
            ValueFiller filler = new ValueFiller(fillNp, ContextType.ASSERTION, true, fillMode);
×
327
            filler.fill(assertionContext);
×
328
            unusedStatementList.addAll(filler.getUnusedStatements());
×
329

330
            if (!fillOnlyAssertion) {
×
331
                ValueFiller prFiller = new ValueFiller(fillNp, ContextType.PROVENANCE, true);
×
332
                prFiller.fill(provenanceContext);
×
333
                unusedPrStatementList.addAll(prFiller.getUnusedStatements());
×
334

335
                ValueFiller piFiller = new ValueFiller(fillNp, ContextType.PUBINFO, true);
×
336
                if (!assertionContext.getTemplate().getTargetNanopubTypes().isEmpty()) {
×
337
                    for (Statement st : new ArrayList<>(piFiller.getUnusedStatements())) {
×
338
                        if (st.getSubject().stringValue().equals(LocalUri.of("nanopub").stringValue()) && st.getPredicate().equals(NPX.HAS_NANOPUB_TYPE)) {
×
339
                            if (assertionContext.getTemplate().getTargetNanopubTypes().contains(st.getObject())) {
×
340
                                piFiller.removeUnusedStatement(st);
×
341
                            }
342
                        }
343
                    }
×
344
                }
345
                for (TemplateContext c : pubInfoContexts) {
×
346
                    piFiller.fill(c);
×
347
                }
×
348
                piFiller.removeUnusedStatements(NanodashSession.get().getUserIri(), FOAF.NAME, null);
×
349
                if (piFiller.hasUnusedStatements()) {
×
350
                    final String handcodedStatementsTemplateId = "https://w3id.org/np/RAMEgudZsQ1bh1fZhfYnkthqH6YSXpghSE_DEN1I-6eAI";
×
351
                    if (!pubInfoContextMap.containsKey(handcodedStatementsTemplateId)) {
×
352
                        TemplateContext c = createPubinfoContext(handcodedStatementsTemplateId);
×
353
                        c.initStatements();
×
354
                        piFiller.fill(c);
×
355
                    }
356
                }
357
                unusedPiStatementList.addAll(piFiller.getUnusedStatements());
×
358
                // TODO: Also use pubinfo templates stated in nanopub to be filled in?
359
//                                Set<IRI> pubinfoTemplateIds = Template.getPubinfoTemplateIds(fillNp);
360
//                                if (!pubinfoTemplateIds.isEmpty()) {
361
//                                        ValueFiller piFiller = new ValueFiller(fillNp, ContextType.PUBINFO);
362
//                                        for (IRI pubinfoTemplateId : pubinfoTemplateIds) {
363
//                                                // TODO: Make smart choice on the ordering in trying to fill in all pubinfo elements
364
//                                                piFiller.fill(pubInfoContextMap.get(pubinfoTemplateId.stringValue()));
365
//                                        }
366
//                                        warningMessage += (piFiller.getWarningMessage() == null ? "" : "Publication info: " + piFiller.getWarningMessage() + " ");
367
//                                }
368
            }
369
        } else if (improveNp != null) {
×
370
            ValueFiller filler = new ValueFiller(improveNp, ContextType.ASSERTION, true);
×
371
            filler.fill(assertionContext);
×
372
            unusedStatementList.addAll(filler.getUnusedStatements());
×
373
        }
374
        if (!unusedStatementList.isEmpty()) {
×
375
            add(new Label("warnings", "Some content from the existing nanopublication could not be filled in:"));
×
376
        } else {
377
            add(new Label("warnings", "").setVisible(false));
×
378
        }
379
        add(new DataView<Statement>("unused-statements", new ListDataProvider<Statement>(unusedStatementList)) {
×
380

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

386
        });
387
        add(new DataView<Statement>("unused-prstatements", new ListDataProvider<Statement>(unusedPrStatementList)) {
×
388

389
            @Override
390
            protected void populateItem(Item<Statement> item) {
391
                item.add(new TripleItem("unused-prstatement", item.getModelObject(), (fillNp != null ? fillNp : improveNp), null));
×
392
            }
×
393

394
        });
395
        add(new DataView<Statement>("unused-pistatements", new ListDataProvider<Statement>(unusedPiStatementList)) {
×
396

397
            @Override
398
            protected void populateItem(Item<Statement> item) {
399
                item.add(new TripleItem("unused-pistatement", item.getModelObject(), (fillNp != null ? fillNp : improveNp), null));
×
400
            }
×
401

402
        });
403

404
        // Finalize statements, which picks up parameter values in repetitions:
405
        assertionContext.finalizeStatements();
×
406
        provenanceContext.finalizeStatements();
×
407
        for (TemplateContext c : pubInfoContexts) {
×
408
            c.finalizeStatements();
×
409
        }
×
410

411
        final CheckBox consentCheck = new CheckBox("consentcheck", new Model<>(false));
×
412
        consentCheck.setRequired(true);
×
413
        consentCheck.add(new InvalidityHighlighting());
×
414
        consentCheck.add(new IValidator<Boolean>() {
×
415

416
            @Override
417
            public void validate(IValidatable<Boolean> validatable) {
418
                if (!Boolean.TRUE.equals(validatable.getValue())) {
×
419
                    validatable.error(new ValidationError("You need to check the checkbox that you understand the consequences."));
×
420
                }
421
            }
×
422

423
        });
424

425
        form = new Form<Void>("form") {
×
426

427
            @Override
428
            protected void onConfigure() {
429
                super.onConfigure();
×
430
                form.getFeedbackMessages().clear();
×
431
//                                formComponents.clear();
432
            }
×
433

434
            protected void onSubmit() {
435
                logger.info("Publish form submitted");
×
436
                Nanopub signedNp = null;
×
437
                try {
438
                    Nanopub np = createNanopub();
×
439
                    logger.info("Nanopublication created: {}", np.getUri());
×
440
                    TransformContext tc = new TransformContext(SignatureAlgorithm.RSA, NanodashSession.get().getKeyPair(), NanodashSession.get().getUserIri(), false, false, false);
×
441
                    signedNp = SignNanopub.signAndTransform(np, tc);
×
442
                    logger.info("Nanopublication signed: {}", signedNp.getUri());
×
443
                    String npUrl = PublishNanopub.publish(signedNp);
×
444
                    logger.info("Nanopublication published: {}", npUrl);
×
445
                } catch (Exception ex) {
×
446
                    signedNp = null;
×
447
                    logger.error("Nanopublication publishing failed: {}", ex);
×
448
                    String message = ex.getClass().getName();
×
449
                    if (ex.getMessage() != null) {
×
450
                        message = ex.getMessage();
×
451
                    }
452
                    feedbackPanel.error(message);
×
453
                }
×
454
                if (!pageParams.get("refresh-upon-publish").isEmpty()) {
×
455
                    String toRefresh = pageParams.get("refresh-upon-publish").toString();
×
456
                    if (toRefresh.equals("spaces")) {
×
457
                        Space.forceRootRefresh(3 * 1000);
×
458
                    } else if (toRefresh.equals("maintainedResources")) {
×
459
                        MaintainedResource.forceRootRefresh(3 * 1000);
×
460
                    } else if (ProfiledResource.isProfiledResource(toRefresh)) {
×
461
                        ProfiledResource.forceRefresh(toRefresh, 3 * 1000);
×
462
                    } else {
463
                        QueryRef queryRef = QueryRef.parseString(toRefresh);
×
464
                        // Make sure the next cache update happens not before 3 seconds from now, at which point the
465
                        // published nanopub should show up in the Nanopub Query instances:
466
                        ApiCache.clearCache(queryRef, 3 * 1000);
×
467
                    }
468
                }
469
                if (signedNp != null) {
×
470
                    throw new RestartResponseException(getConfirmPage(signedNp, pageParams));
×
471
                } else {
472
                    logger.error("Nanopublication publishing failed");
×
473
                }
474
            }
×
475

476
            @Override
477
            protected void onValidate() {
478
                super.onValidate();
×
479
                for (Component fc : assertionContext.getComponents()) {
×
480
                    processFeedback(fc);
×
481
                }
×
482
                for (Component fc : provenanceContext.getComponents()) {
×
483
                    processFeedback(fc);
×
484
                }
×
485
                for (TemplateContext c : pubInfoContexts) {
×
486
                    for (Component fc : c.getComponents()) {
×
487
                        processFeedback(fc);
×
488
                    }
×
489
                }
×
490
            }
×
491

492
            private void processFeedback(Component c) {
493
                if (c instanceof FormComponent) {
×
494
                    ((FormComponent<?>) c).processInput();
×
495
                }
496
                for (FeedbackMessage fm : c.getFeedbackMessages()) {
×
497
                    form.getFeedbackMessages().add(fm);
×
498
                }
×
499
            }
×
500

501
        };
502
        form.setOutputMarkupId(true);
×
503

504
        form.add(new Label("nanopub-namespace", targetNamespaceLabel));
×
505

506
        form.add(new BookmarkablePageLink<Void>("templatelink", ExplorePage.class, new PageParameters().set("id", assertionContext.getTemplate().getId())));
×
507
        form.add(new Label("templatename", assertionContext.getTemplate().getLabel()));
×
508
        String description = assertionContext.getTemplate().getLabel();
×
509
        if (description == null) description = "";
×
510
        form.add(new Label("templatedesc", assertionContext.getTemplate().getDescription()).setEscapeModelStrings(false));
×
511

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

514
            protected void populateItem(ListItem<StatementItem> item) {
515
                item.add(item.getModelObject());
×
516
            }
×
517

518
        });
519

520
        final Map<String, Boolean> handledProvTemplates = new HashMap<>();
×
521
        final String defaultProvTemplateId;
522
        if (assertionContext.getTemplate().getDefaultProvenance() != null) {
×
523
            defaultProvTemplateId = assertionContext.getTemplate().getDefaultProvenance().stringValue();
×
524
            handledProvTemplates.put(defaultProvTemplateId, true);
×
525
        } else {
526
            defaultProvTemplateId = null;
×
527
        }
528
        final List<String> recommendedProvTemplateOptionIds = new ArrayList<>();
×
529
        final List<String> provTemplateOptionIds = new ArrayList<>();
×
530
        if (pageParams.get("prtemplate-options").isNull()) {
×
531
            // TODO Make this dynamic and consider updated templates:
532
            recommendedProvTemplateOptionIds.add("https://w3id.org/np/RA7lSq6MuK_TIC6JMSHvLtee3lpLoZDOqLJCLXevnrPoU");
×
533
            recommendedProvTemplateOptionIds.add("http://purl.org/np/RAcTpoh5Ra0ssqmcpOgWdaZ_YiPE6demO6cpw-2RvSNs8");
×
534
            recommendedProvTemplateOptionIds.add("http://purl.org/np/RA4LGtuOqTIMqVAkjnfBXk1YDcAPNadP5CGiaJiBkdHCQ");
×
535
            recommendedProvTemplateOptionIds.add("http://purl.org/np/RAl_-VTw9Re_uRF8r8y0rjlfnu7FlhTa8xg_8xkcweqiE");
×
536
            recommendedProvTemplateOptionIds.add("https://w3id.org/np/RASORV2mMEVpS4lWh2bwUTEcV-RWjbD9RPbN7J0PIeYAU");
×
537
            recommendedProvTemplateOptionIds.add("http://purl.org/np/RAjkBbM5yQm7hKH1l_Jk3HAUqWi3Bd57TPmAOZCsZmi_M");
×
538
            recommendedProvTemplateOptionIds.add("http://purl.org/np/RAGXx_k9eQMnXaCbsXMsJbGClwZtQEGNg0GVJu6amdAVw");
×
539
            recommendedProvTemplateOptionIds.add("http://purl.org/np/RA1fnITI3Pu1UQ0CHghNpys3JwQrM32LBnjmDLoayp9-4");
×
540
            recommendedProvTemplateOptionIds.add("http://purl.org/np/RAJgbsGeGdTG-zq_gU0TLw4s3raMgoRk-mPlc2DSLXvE0");
×
541
            recommendedProvTemplateOptionIds.add("http://purl.org/np/RA6SXfhUY-xeblZU8HhPddw6tsu-C5NXevG6C_zv4bMxU");
×
542
            for (String s : recommendedProvTemplateOptionIds) {
×
543
                handledProvTemplates.put(s, true);
×
544
            }
×
545

546
            for (ApiResponseEntry t : td.getProvenanceTemplates()) {
×
547
                String tid = t.get("np");
×
548
                if (handledProvTemplates.containsKey(tid)) continue;
×
549
                provTemplateOptionIds.add(tid);
×
550
                handledProvTemplates.put(tid, true);
×
551
            }
×
552
        } else {
553
            for (String s : pageParams.get("prtemplate-options").toString().split(" ")) {
×
554
                if (handledProvTemplates.containsKey(s)) continue;
×
555
                recommendedProvTemplateOptionIds.add(s);
×
556
                handledProvTemplates.put(s, true);
×
557
            }
558
        }
559

560
        ChoiceProvider<String> prTemplateChoiceProvider = new ChoiceProvider<String>() {
×
561

562
            @Override
563
            public String getDisplayValue(String object) {
564
                if (object == null || object.isEmpty()) return "";
×
565
                Template t = td.getTemplate(object);
×
566
                if (t != null) return t.getLabel();
×
567
                return object;
×
568
            }
569

570
            @Override
571
            public String getIdValue(String object) {
572
                return object;
×
573
            }
574

575
            // Getting strange errors with Tomcat if this method is not overridden:
576
            @Override
577
            public void detach() {
578
            }
×
579

580
            @Override
581
            public void query(String term, int page, Response<String> response) {
582
                if (term == null) term = "";
×
583
                term = term.toLowerCase();
×
584
                if (pageParams.get("prtemplate").toString() != null) {
×
585
                    // Using this work-around with "——" because 'optgroup' is not available through Wicket's Select2 classes
586
                    response.add("—— default for this link ——");
×
587
                    response.add(prTemplateId);
×
588
                }
589
                if (defaultProvTemplateId != null) {
×
590
                    response.add("—— default for this template ——");
×
591
                    response.add(defaultProvTemplateId);
×
592
                }
593
                if (!recommendedProvTemplateOptionIds.isEmpty()) {
×
594
                    if (pageParams.get("prtemplate-options").isNull()) {
×
595
                        response.add("—— recommended ——");
×
596
                    }
597
                    for (String s : recommendedProvTemplateOptionIds) {
×
598
                        if (s.toLowerCase().contains(term) || getDisplayValue(s).toLowerCase().contains(term)) {
×
599
                            response.add(s);
×
600
                        }
601
                    }
×
602
                }
603
                if (!provTemplateOptionIds.isEmpty()) {
×
604
                    response.add("—— others ——");
×
605
                    for (String s : provTemplateOptionIds) {
×
606
                        if (s.toLowerCase().contains(term) || getDisplayValue(s).toLowerCase().contains(term)) {
×
607
                            response.add(s);
×
608
                        }
609
                    }
×
610
                }
611
            }
×
612

613
            @Override
614
            public Collection<String> toChoices(Collection<String> ids) {
615
                return ids;
×
616
            }
617

618
        };
619
        final IModel<String> prTemplateModel = Model.of(provenanceContext.getTemplate().getId());
×
620
        Select2Choice<String> prTemplateChoice = new Select2Choice<String>("prtemplate", prTemplateModel, prTemplateChoiceProvider);
×
621
        prTemplateChoice.setRequired(true);
×
622
        prTemplateChoice.getSettings().setCloseOnSelect(true);
×
623
        prTemplateChoice.add(new AjaxFormComponentUpdatingBehavior("change") {
×
624

625
            @Override
626
            protected void onUpdate(AjaxRequestTarget target) {
627
                String o = prTemplateModel.getObject();
×
628
                if (o.startsWith("——")) {
×
629
                    o = provenanceContext.getTemplate().getId();
×
630
                    prTemplateModel.setObject(o);
×
631
                }
632
                provenanceContext = new TemplateContext(ContextType.PROVENANCE, prTemplateModel.getObject(), "pr-statement", targetNamespace);
×
633
                provenanceContext.initStatements();
×
634
                refreshProvenance(target);
×
635
                provenanceContext.finalizeStatements();
×
636
            }
×
637

638
        });
639
        form.add(prTemplateChoice);
×
640
        refreshProvenance(null);
×
641

642
        final Map<String, Boolean> handledPiTemplates = new HashMap<>();
×
643
        final List<String> recommendedPiTemplateOptionIds = new ArrayList<>();
×
644
        final List<String> piTemplateOptionIds = new ArrayList<>();
×
645
        // TODO Make this dynamic and consider updated templates:
646
        recommendedPiTemplateOptionIds.add("http://purl.org/np/RAXflINqt3smqxV5Aq7E9lzje4uLdkKIOefa6Bp8oJ8CY");
×
647
        recommendedPiTemplateOptionIds.add("https://w3id.org/np/RARW4MsFkHuwjycNElvEVtuMjpf4yWDL10-0C5l2MqqRQ");
×
648
        recommendedPiTemplateOptionIds.add("https://w3id.org/np/RA16U9Wo30ObhrK1NzH7EsmVRiRtvEuEA_Dfc-u8WkUCA");
×
649
        recommendedPiTemplateOptionIds.add("http://purl.org/np/RAdyqI6k07V5nAS82C6hvIDtNWk179EIV4DV-sLbOFKg4");
×
650
        recommendedPiTemplateOptionIds.add("https://w3id.org/np/RAjvEpLZUE7rMoa8q6mWSsN6utJDp-5FmgO47YGsbgw3w");
×
651
        recommendedPiTemplateOptionIds.add("http://purl.org/np/RAxuGRKID6yNg63V5Mf0ot2NjncOnodh-mkN3qT_1txGI");
×
652
        for (TemplateContext c : pubInfoContexts) {
×
653
            String s = c.getTemplate().getId();
×
654
            handledPiTemplates.put(s, true);
×
655
        }
×
656
        for (String s : recommendedPiTemplateOptionIds) {
×
657
            handledPiTemplates.put(s, true);
×
658
        }
×
659

660
        for (ApiResponseEntry entry : td.getPubInfoTemplates()) {
×
661
            String tid = entry.get("np");
×
662
            if (handledPiTemplates.containsKey(tid)) continue;
×
663
            piTemplateOptionIds.add(tid);
×
664
            handledPiTemplates.put(tid, true);
×
665
        }
×
666

667
        ChoiceProvider<String> piTemplateChoiceProvider = new ChoiceProvider<String>() {
×
668

669
            @Override
670
            public String getDisplayValue(String object) {
671
                if (object == null || object.isEmpty()) return "";
×
672
                Template t = td.getTemplate(object);
×
673
                if (t != null) return t.getLabel();
×
674
                return object;
×
675
            }
676

677
            @Override
678
            public String getIdValue(String object) {
679
                return object;
×
680
            }
681

682
            // Getting strange errors with Tomcat if this method is not overridden:
683
            @Override
684
            public void detach() {
685
            }
×
686

687
            @Override
688
            public void query(String term, int page, Response<String> response) {
689
                if (term == null) term = "";
×
690
                term = term.toLowerCase();
×
691
                if (!recommendedPiTemplateOptionIds.isEmpty()) {
×
692
                    response.add("—— recommended ——");
×
693
                    for (String s : recommendedPiTemplateOptionIds) {
×
694
                        boolean isAlreadyUsed = false;
×
695
                        for (TemplateContext c : pubInfoContexts) {
×
696
                            // TODO: make this more efficient/nicer
697
                            if (c.getTemplate().getId().equals(s)) {
×
698
                                isAlreadyUsed = true;
×
699
                                break;
×
700
                            }
701
                        }
×
702
                        if (isAlreadyUsed) continue;
×
703
                        if (s.toLowerCase().contains(term) || getDisplayValue(s).toLowerCase().contains(term)) {
×
704
                            response.add(s);
×
705
                        }
706
                    }
×
707
                }
708
                if (!piTemplateOptionIds.isEmpty()) {
×
709
                    response.add("—— others ——");
×
710
                    for (String s : piTemplateOptionIds) {
×
711
                        boolean isAlreadyUsed = false;
×
712
                        for (TemplateContext c : pubInfoContexts) {
×
713
                            // TODO: make this more efficient/nicer
714
                            if (c.getTemplate().getId().equals(s)) {
×
715
                                isAlreadyUsed = true;
×
716
                                break;
×
717
                            }
718
                        }
×
719
                        if (isAlreadyUsed) continue;
×
720
                        if (s.toLowerCase().contains(term) || getDisplayValue(s).toLowerCase().contains(term)) {
×
721
                            response.add(s);
×
722
                        }
723
                    }
×
724
                }
725
            }
×
726

727
            @Override
728
            public Collection<String> toChoices(Collection<String> ids) {
729
                return ids;
×
730
            }
731

732
        };
733
        final IModel<String> newPiTemplateModel = Model.of();
×
734
        Select2Choice<String> piTemplateChoice = new Select2Choice<String>("pitemplate", newPiTemplateModel, piTemplateChoiceProvider);
×
735
        piTemplateChoice.getSettings().setCloseOnSelect(true);
×
736
        piTemplateChoice.getSettings().setPlaceholder("add element...");
×
737
        piTemplateChoice.add(new AjaxFormComponentUpdatingBehavior("change") {
×
738

739
            @Override
740
            protected void onUpdate(AjaxRequestTarget target) {
741
                if (newPiTemplateModel.getObject().startsWith("——")) {
×
742
                    newPiTemplateModel.setObject(null);
×
743
                    refreshPubInfo(target);
×
744
                    return;
×
745
                }
746
                String id = newPiTemplateModel.getObject();
×
747
                TemplateContext c = new TemplateContext(ContextType.PUBINFO, id, "pi-statement", targetNamespace);
×
748
                c.initStatements();
×
749
                pubInfoContexts.add(c);
×
750
                newPiTemplateModel.setObject(null);
×
751
                refreshPubInfo(target);
×
752
                c.finalizeStatements();
×
753
            }
×
754

755
        });
756
        form.add(piTemplateChoice);
×
757
        refreshPubInfo(null);
×
758

759
        form.add(consentCheck);
×
760
        add(form);
×
761

762
        feedbackPanel = new FeedbackPanel("feedback");
×
763
        feedbackPanel.setOutputMarkupId(true);
×
764
        add(feedbackPanel);
×
765
    }
×
766

767
    private void refreshProvenance(AjaxRequestTarget target) {
768
        if (target != null) {
×
769
            form.remove("prtemplatelink");
×
770
            form.remove("pr-statements");
×
771
            target.add(form);
×
772
            target.appendJavaScript("updateElements();");
×
773
        }
774
        form.add(new BookmarkablePageLink<Void>("prtemplatelink", ExplorePage.class, new PageParameters().set("id", provenanceContext.getTemplate().getId())));
×
775
        ListView<StatementItem> list = new ListView<StatementItem>("pr-statements", provenanceContext.getStatementItems()) {
×
776

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

781
        };
782
        list.setOutputMarkupId(true);
×
783
        form.add(list);
×
784
    }
×
785

786
    private void refreshPubInfo(AjaxRequestTarget target) {
787
        ListView<TemplateContext> list = new ListView<TemplateContext>("pis", pubInfoContexts) {
×
788

789
            protected void populateItem(ListItem<TemplateContext> item) {
790
                final TemplateContext pic = item.getModelObject();
×
791
                item.add(new Label("pitemplatename", pic.getTemplate().getLabel()));
×
792
                item.add(new BookmarkablePageLink<Void>("pitemplatelink", ExplorePage.class, new PageParameters().set("id", pic.getTemplate().getId())));
×
793
                Label remove = new Label("piremove", "×");
×
794
                item.add(remove);
×
795
                remove.add(new AjaxEventBehavior("click") {
×
796

797
                    @Override
798
                    protected void onEvent(AjaxRequestTarget target) {
799
                        pubInfoContexts.remove(pic);
×
800
                        target.add(PublishForm.this);
×
801
                        target.appendJavaScript("updateElements();");
×
802
                    }
×
803

804
                });
805
                if (requiredPubInfoContexts.contains(pic)) remove.setVisible(false);
×
806
                item.add(new ListView<StatementItem>("pi-statements", pic.getStatementItems()) {
×
807

808
                    protected void populateItem(ListItem<StatementItem> item) {
809
                        item.add(item.getModelObject());
×
810
                    }
×
811

812
                });
813
            }
×
814

815
        };
816
        list.setOutputMarkupId(true);
×
817
        if (target == null) {
×
818
            form.add(list);
×
819
        } else {
820
            form.remove("pis");
×
821
            form.add(list);
×
822
            target.add(form);
×
823
            target.appendJavaScript("updateElements();");
×
824
        }
825
    }
×
826

827
    private TemplateContext createPubinfoContext(String piTemplateId) {
828
        TemplateContext c;
829
        if (pubInfoContextMap.containsKey(piTemplateId)) {
×
830
            c = pubInfoContextMap.get(piTemplateId);
×
831
        } else {
832
            c = new TemplateContext(ContextType.PUBINFO, piTemplateId, "pi-statement", targetNamespace);
×
833
            pubInfoContextMap.put(piTemplateId, c);
×
834
            pubInfoContexts.add(c);
×
835
        }
836
        return c;
×
837
    }
838

839
    private synchronized Nanopub createNanopub() throws MalformedNanopubException, NanopubAlreadyFinalizedException {
840
        assertionContext.getIntroducedIris().clear();
×
841
        NanopubCreator npCreator = new NanopubCreator(targetNamespace);
×
842
        npCreator.setAssertionUri(vf.createIRI(targetNamespace + "assertion"));
×
843
        assertionContext.propagateStatements(npCreator);
×
844
        provenanceContext.propagateStatements(npCreator);
×
845
        for (TemplateContext c : pubInfoContexts) {
×
846
            c.propagateStatements(npCreator);
×
847
        }
×
848
        for (IRI introducedIri : assertionContext.getIntroducedIris()) {
×
849
            npCreator.addPubinfoStatement(NPX.INTRODUCES, introducedIri);
×
850
        }
×
851
        for (IRI embeddedIri : assertionContext.getEmbeddedIris()) {
×
852
            npCreator.addPubinfoStatement(NPX.EMBEDS, embeddedIri);
×
853
        }
×
854
        npCreator.addNamespace("this", targetNamespace);
×
855
        npCreator.addNamespace("sub", targetNamespace + "/");
×
856
        npCreator.addTimestampNow();
×
857
        IRI templateUri = assertionContext.getTemplate().getNanopub().getUri();
×
858
        npCreator.addPubinfoStatement(NTEMPLATE.WAS_CREATED_FROM_TEMPLATE, templateUri);
×
859
        IRI prTemplateUri = provenanceContext.getTemplate().getNanopub().getUri();
×
860
        npCreator.addPubinfoStatement(NTEMPLATE.WAS_CREATED_FROM_PROVENANCE_TEMPLATE, prTemplateUri);
×
861
        for (TemplateContext c : pubInfoContexts) {
×
862
            IRI piTemplateUri = c.getTemplate().getNanopub().getUri();
×
863
            npCreator.addPubinfoStatement(NTEMPLATE.WAS_CREATED_FROM_PUBINFO_TEMPLATE, piTemplateUri);
×
864
        }
×
865
        String nanopubLabel = getNanopubLabel(npCreator);
×
866
        if (nanopubLabel != null) {
×
867
            npCreator.addPubinfoStatement(RDFS.LABEL, vf.createLiteral(nanopubLabel));
×
868
        }
869
        for (IRI type : assertionContext.getTemplate().getTargetNanopubTypes()) {
×
870
            npCreator.addPubinfoStatement(NPX.HAS_NANOPUB_TYPE, type);
×
871
        }
×
872
        IRI userIri = NanodashSession.get().getUserIri();
×
873
        if (User.getName(userIri) != null) {
×
874
            npCreator.addPubinfoStatement(userIri, FOAF.NAME, vf.createLiteral(User.getName(userIri)));
×
875
            npCreator.addNamespace("foaf", FOAF.NAMESPACE);
×
876
        }
877
        String websiteUrl = NanodashPreferences.get().getWebsiteUrl();
×
878
        if (websiteUrl != null) {
×
879
            npCreator.addPubinfoStatement(NPX.WAS_CREATED_AT, vf.createIRI(websiteUrl));
×
880
        }
881
        return npCreator.finalizeNanopub();
×
882
    }
883

884
    private String getNanopubLabel(NanopubCreator npCreator) {
885
        if (assertionContext.getTemplate().getNanopubLabelPattern() == null) return null;
×
886

887
        Map<IRI, String> labelMap = new HashMap<>();
×
888
        for (Statement st : npCreator.getCurrentPubinfoStatements()) {
×
889
            if (st.getPredicate().equals(RDFS.LABEL) && st.getObject() instanceof Literal objL) {
×
890
                labelMap.put((IRI) st.getSubject(), objL.stringValue());
×
891
            }
892
        }
×
893

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

941
    private NanodashPage getConfirmPage(Nanopub signedNp, PageParameters pageParams) {
942
        try {
943
            return (NanodashPage) confirmPageClass.getConstructor(Nanopub.class, PageParameters.class).newInstance(signedNp, pageParams);
×
944
        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException |
×
945
                 InvocationTargetException | NoSuchMethodException | SecurityException ex) {
946
            logger.error("Could not create instance of confirmation page: {}", ex.getMessage());
×
947
        }
948
        return null;
×
949
    }
950

951
    /**
952
     * Returns a hint whether the form is stateless or not.
953
     *
954
     * @return false if the form is stateful, true if it is stateless.
955
     */
956
    // This is supposed to solve the problem that sometimes (but only sometimes) form content is reset
957
    // if the user browses other pages in parallel:
958
    protected boolean getStatelessHint() {
959
        return false;
×
960
    }
961

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