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

knowledgepixels / nanodash / 24244170325

10 Apr 2026 01:00PM UTC coverage: 16.178% (+0.03%) from 16.147%
24244170325

push

github

web-flow
Merge pull request #433 from knowledgepixels/fix/default-license-not-picked-up

fix: apply user's default license per-request instead of caching globally

789 of 6028 branches covered (13.09%)

Branch coverage included in aggregate %.

1977 of 11069 relevant lines covered (17.86%)

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

3
import com.knowledgepixels.nanodash.NanodashSession;
4
import com.knowledgepixels.nanodash.domain.User;
5
import com.knowledgepixels.nanodash.page.ExplorePage;
6
import com.knowledgepixels.nanodash.template.ContextType;
7
import com.knowledgepixels.nanodash.template.Template;
8
import com.knowledgepixels.nanodash.template.TemplateContext;
9
import com.knowledgepixels.nanodash.template.TemplateData;
10
import org.apache.wicket.markup.html.basic.Label;
11
import org.apache.wicket.markup.html.form.Form;
12
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
13
import org.apache.wicket.markup.html.list.ListItem;
14
import org.apache.wicket.markup.html.list.ListView;
15
import org.apache.wicket.markup.html.panel.Panel;
16
import org.apache.wicket.request.mapper.parameter.PageParameters;
17
import org.eclipse.rdf4j.model.IRI;
18
import org.nanopub.Nanopub;
19

20
import java.util.ArrayList;
21
import java.util.List;
22

23
/**
24
 * A preview panel that shows what the template form will look like when used,
25
 * without the consent checkbox and publish/preview buttons.
26
 */
27
public class TemplateFormPreview extends Panel {
28

29
    /**
30
     * Creates a form preview for a template nanopub that may not yet be published.
31
     *
32
     * @param id              the Wicket component ID
33
     * @param templateNanopub the nanopub that defines the assertion template to preview
34
     */
35
    public TemplateFormPreview(String id, Nanopub templateNanopub) {
36
        super(id);
×
37

38
        TemplateData td = TemplateData.get();
×
39

40
        // Register the template from the nanopub so it can be looked up by TemplateContext
41
        Template template = td.registerTemplate(templateNanopub);
×
42
        String templateId = templateNanopub.getUri().stringValue();
×
43

44
        String targetNamespace = template.getTargetNamespace();
×
45
        if (targetNamespace == null) {
×
46
            targetNamespace = Template.DEFAULT_TARGET_NAMESPACE;
×
47
        }
48
        targetNamespace = targetNamespace + "~~~ARTIFACTCODE~~~/";
×
49

50
        // Assertion context
51
        TemplateContext assertionContext = new TemplateContext(ContextType.ASSERTION, templateId, "statement", targetNamespace);
×
52
        assertionContext.initStatements();
×
53
        assertionContext.finalizeStatements();
×
54

55
        // Provenance context
56
        String prTemplateId;
57
        if (template.getDefaultProvenance() != null) {
×
58
            prTemplateId = template.getDefaultProvenance().stringValue();
×
59
        } else {
60
            prTemplateId = PublishForm.DEFAULT_PROV_TEMPLATE;
×
61
        }
62
        TemplateContext provenanceContext = new TemplateContext(ContextType.PROVENANCE, prTemplateId, "pr-statement", targetNamespace);
×
63
        provenanceContext.initStatements();
×
64
        provenanceContext.finalizeStatements();
×
65

66
        // Pubinfo contexts
67
        List<TemplateContext> pubInfoContexts = new ArrayList<>();
×
68
        pubInfoContexts.add(new TemplateContext(ContextType.PUBINFO, PublishForm.CREATOR_PUB_INFO_TEMPLATE, "pi-statement", targetNamespace));
×
69
        TemplateContext licenseContext = new TemplateContext(ContextType.PUBINFO, PublishForm.LICENSE_PUB_INFO_TEMPLATE, "pi-statement", targetNamespace);
×
70
        IRI defaultLicense = User.getDefaultLicense(NanodashSession.get().getUserIri());
×
71
        if (defaultLicense != null) {
×
72
            licenseContext.setParam("license", defaultLicense.stringValue());
×
73
        }
74
        pubInfoContexts.add(licenseContext);
×
75
        for (IRI r : template.getRequiredPubInfoElements()) {
×
76
            String rId = r.stringValue();
×
77
            boolean alreadyAdded = false;
×
78
            for (TemplateContext c : pubInfoContexts) {
×
79
                if (c.getTemplate().getId().equals(rId)) {
×
80
                    alreadyAdded = true;
×
81
                    break;
×
82
                }
83
            }
×
84
            if (!alreadyAdded) {
×
85
                pubInfoContexts.add(new TemplateContext(ContextType.PUBINFO, rId, "pi-statement", targetNamespace));
×
86
            }
87
        }
×
88
        for (TemplateContext c : pubInfoContexts) {
×
89
            c.initStatements();
×
90
            c.finalizeStatements();
×
91
        }
×
92

93
        // Build the form (needed for Wicket form components to render, but no submit action)
94
        Form<?> form = new Form<Void>("form");
×
95

96
        // Assertion section
97
        form.add(new BookmarkablePageLink<Void>("templatelink", ExplorePage.class, new PageParameters().set("id", templateId)));
×
98
        form.add(new Label("templatename", template.getLabel()));
×
99
        form.add(new Label("templatedesc", template.getDescription()).setEscapeModelStrings(false));
×
100

101
        form.add(new ListView<StatementItem>("statements", assertionContext.getStatementItems()) {
×
102
            protected void populateItem(ListItem<StatementItem> item) {
103
                item.add(item.getModelObject());
×
104
            }
×
105
        });
106

107
        // Provenance section
108
        form.add(new Label("prtemplatename", provenanceContext.getTemplate().getLabel()));
×
109
        form.add(new BookmarkablePageLink<Void>("prtemplatelink", ExplorePage.class, new PageParameters().set("id", provenanceContext.getTemplate().getId())));
×
110

111
        form.add(new ListView<StatementItem>("pr-statements", provenanceContext.getStatementItems()) {
×
112
            protected void populateItem(ListItem<StatementItem> item) {
113
                item.add(item.getModelObject());
×
114
            }
×
115
        });
116

117
        // Pubinfo section
118
        form.add(new ListView<TemplateContext>("pis", pubInfoContexts) {
×
119
            protected void populateItem(ListItem<TemplateContext> item) {
120
                TemplateContext pic = item.getModelObject();
×
121
                item.add(new Label("pitemplatename", pic.getTemplate().getLabel()));
×
122
                item.add(new BookmarkablePageLink<Void>("pitemplatelink", ExplorePage.class, new PageParameters().set("id", pic.getTemplate().getId())));
×
123
                item.add(new ListView<StatementItem>("pi-statements", pic.getStatementItems()) {
×
124
                    protected void populateItem(ListItem<StatementItem> item) {
125
                        item.add(item.getModelObject());
×
126
                    }
×
127
                });
128
            }
×
129
        });
130

131
        add(form);
×
132
    }
×
133

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