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

knowledgepixels / nanodash / 28792900518

06 Jul 2026 12:52PM UTC coverage: 28.504% (-0.006%) from 28.51%
28792900518

Pull #536

github

web-flow
Merge fd800ea3b into afb8fc1ab
Pull Request #536: feat: replace template-form '^' source links with dropdown menus

1811 of 7177 branches covered (25.23%)

Branch coverage included in aggregate %.

3710 of 12192 relevant lines covered (30.43%)

4.52 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.template.ContextType;
6
import com.knowledgepixels.nanodash.template.Template;
7
import com.knowledgepixels.nanodash.template.TemplateContext;
8
import com.knowledgepixels.nanodash.template.TemplateData;
9
import org.apache.wicket.markup.html.basic.Label;
10
import org.apache.wicket.markup.html.form.Form;
11
import org.apache.wicket.markup.html.list.ListItem;
12
import org.apache.wicket.markup.html.list.ListView;
13
import org.apache.wicket.markup.html.panel.Panel;
14
import org.eclipse.rdf4j.model.IRI;
15
import org.nanopub.Nanopub;
16

17
import java.util.ArrayList;
18
import java.util.List;
19

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

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

35
        TemplateData td = TemplateData.get();
×
36

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

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

47
        // Assertion context
48
        TemplateContext assertionContext = new TemplateContext(ContextType.ASSERTION, templateId, "statement", targetNamespace);
×
49
        assertionContext.initStatements();
×
50
        assertionContext.finalizeStatements();
×
51

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

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

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

93
        // Assertion section
94
        form.add(PublishForm.newSourceMenu("templatelink", templateId));
×
95
        form.add(new Label("templatename", template.getLabel()));
×
96
        form.add(new Label("templatedesc", template.getDescription()).setEscapeModelStrings(false));
×
97

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

104
        // Provenance section
105
        form.add(new Label("prtemplatename", provenanceContext.getTemplate().getLabel()));
×
106
        form.add(PublishForm.newSourceMenu("prtemplatelink", provenanceContext.getTemplate().getId()));
×
107

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

114
        // Pubinfo section
115
        form.add(new ListView<TemplateContext>("pis", pubInfoContexts) {
×
116
            protected void populateItem(ListItem<TemplateContext> item) {
117
                TemplateContext pic = item.getModelObject();
×
118
                item.add(new Label("pitemplatename", pic.getTemplate().getLabel()));
×
119
                item.add(PublishForm.newSourceMenu("pitemplatelink", pic.getTemplate().getId()));
×
120
                item.add(new ListView<StatementItem>("pi-statements", pic.getStatementItems()) {
×
121
                    protected void populateItem(ListItem<StatementItem> item) {
122
                        item.add(item.getModelObject());
×
123
                    }
×
124
                });
125
            }
×
126
        });
127

128
        add(form);
×
129
    }
×
130

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