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

knowledgepixels / nanodash / 17833286003

18 Sep 2025 03:15PM UTC coverage: 13.949% (-0.03%) from 13.974%
17833286003

push

github

tkuhn
feat: Show multi-placeholders as text areas in QueryPage

Still more work needed to fully support multi-placeholders.

444 of 4022 branches covered (11.04%)

Branch coverage included in aggregate %.

1141 of 7341 relevant lines covered (15.54%)

0.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
src/main/java/com/knowledgepixels/nanodash/page/QueryPage.java
1
package com.knowledgepixels.nanodash.page;
2

3
import com.github.jsonldjava.shaded.com.google.common.base.Charsets;
4
import com.knowledgepixels.nanodash.GrlcQuery;
5
import com.knowledgepixels.nanodash.component.QueryParamField;
6
import com.knowledgepixels.nanodash.component.QueryResultTable;
7
import com.knowledgepixels.nanodash.component.TitleBar;
8
import org.apache.wicket.feedback.FeedbackMessage;
9
import org.apache.wicket.markup.html.WebMarkupContainer;
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.link.ExternalLink;
14
import org.apache.wicket.markup.html.list.ListItem;
15
import org.apache.wicket.markup.html.list.ListView;
16
import org.apache.wicket.markup.html.panel.FeedbackPanel;
17
import org.apache.wicket.request.mapper.parameter.PageParameters;
18

19
import java.net.URLEncoder;
20
import java.util.HashMap;
21
import java.util.List;
22

23
/**
24
 * Page for displaying a query and its parameters, allowing users to run the query with specified parameters.
25
 */
26
public class QueryPage extends NanodashPage {
27

28
    /**
29
     * The mount path for this page.
30
     */
31
    public static final String MOUNT_PATH = "/query";
32

33
    private final Form<Void> form;
34
    private final List<QueryParamField> paramFields;
35
    private final FeedbackPanel feedbackPanel;
36

37
    /**
38
     * {@inheritDoc}
39
     */
40
    @Override
41
    public String getMountPath() {
42
        return MOUNT_PATH;
×
43
    }
44

45
    /**
46
     * Constructor for the QueryPage.
47
     *
48
     * @param parameters The page parameters, which should include the query ID and any query parameters.
49
     */
50
    public QueryPage(final PageParameters parameters) {
51
        super(parameters);
×
52
        add(new TitleBar("titlebar", this, null));
×
53
        add(new Label("pagetitle", "Query Info | nanodash"));
×
54

55
        String id = parameters.get("id").toString();
×
56
        final String queryId = parameters.get("runquery").toString();
×
57
        if (id == null) id = queryId;
×
58

59
        final HashMap<String, String> queryParams = new HashMap<>();
×
60
        for (String paramKey : parameters.getNamedKeys()) {
×
61
            if (!paramKey.startsWith("queryparam_")) continue;
×
62
            queryParams.put(paramKey.replaceFirst("queryparam_", ""), parameters.get(paramKey).toString());
×
63
        }
×
64

65
        GrlcQuery q = GrlcQuery.get(id);
×
66

67
        add(new Label("querylabel", q.getLabel()));
×
68
        add(new BookmarkablePageLink<Void>("np", ExplorePage.class, new PageParameters().add("id", q.getNanopub().getUri().stringValue())));
×
69
        // TODO Replace hard-coded domain with dynamic solution:
70
        add(new ExternalLink("openapi-this", "https://query.knowledgepixels.com/openapi/?url=spec/" + id));
×
71
        add(new ExternalLink("openapi-latest", "https://query.knowledgepixels.com/openapi/?url=spec/" + id + "%3Fapi-version=latest"));
×
72
        add(new Label("querydesc", q.getDescription()));
×
73

74
        form = new Form<Void>("form") {
×
75

76
            @Override
77
            protected void onConfigure() {
78
                super.onConfigure();
×
79
                form.getFeedbackMessages().clear();
×
80
            }
×
81

82
            @Override
83
            protected void onSubmit() {
84
                try {
85
                    PageParameters params = new PageParameters();
×
86
                    params.add("runquery", q.getQueryId());
×
87
                    for (QueryParamField f : paramFields) {
×
88
                        if (f.getValue() == null) continue;
×
89
                        params.add("queryparam_" + f.getParamName(), f.getValue());
×
90
                    }
×
91
                    setResponsePage(QueryPage.class, params);
×
92
                } catch (Exception ex) {
×
93
                    String message = ex.getClass().getName();
×
94
                    if (ex.getMessage() != null) message = ex.getMessage();
×
95
                    feedbackPanel.error(message);
×
96
                }
×
97
            }
×
98

99
            @Override
100
            protected void onValidate() {
101
                super.onValidate();
×
102
                for (QueryParamField f : paramFields) {
×
103
                    f.getFormComponent().processInput();
×
104
                    for (FeedbackMessage fm : f.getFormComponent().getFeedbackMessages()) {
×
105
                        form.getFeedbackMessages().add(fm);
×
106
                    }
×
107
                }
×
108
            }
×
109

110
        };
111
        form.setOutputMarkupId(true);
×
112

113
        WebMarkupContainer paramContainer = new WebMarkupContainer("params");
×
114

115
        paramFields = q.createParamFields("paramfield");
×
116
        paramContainer.add(new ListView<QueryParamField>("paramfields", paramFields) {
×
117

118
            protected void populateItem(ListItem<QueryParamField> item) {
119
                QueryParamField f = item.getModelObject();
×
120
                f.getModel().setObject(parameters.get("queryparam_" + f.getParamName()).toString());
×
121
                item.add(item.getModelObject());
×
122
            }
×
123

124
        });
125
        paramContainer.setVisible(!paramFields.isEmpty());
×
126
        form.add(paramContainer);
×
127

128
        // TODO Replace hard-coded Nanopub Query URL with dynamic solution:
129
        String editLink = q.getEndpoint().stringValue().replaceFirst("^.*/repo/", "https://query.petapico.org/tools/") + "/yasgui.html#query=" + URLEncoder.encode(q.getSparql(), Charsets.UTF_8);
×
130
        // TODO We also need to replace the nanopub-query placeholder service URLs in the query above.
131
        // Deactivated for now:
132
        form.add(new ExternalLink("yasgui", editLink).setVisible(false));
×
133

134
        add(form);
×
135

136
        feedbackPanel = new FeedbackPanel("feedback");
×
137
        feedbackPanel.setOutputMarkupId(true);
×
138
        add(feedbackPanel);
×
139

140
        if (queryId == null) {
×
141
            add(new Label("resulttable").setVisible(false));
×
142
        } else {
143
            add(QueryResultTable.createComponent("resulttable", queryId, queryParams, true));
×
144
        }
145
    }
×
146

147
    /**
148
     * <p>hasAutoRefreshEnabled.</p>
149
     *
150
     * @return a boolean
151
     */
152
    protected boolean hasAutoRefreshEnabled() {
153
        return true;
×
154
    }
155

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