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

knowledgepixels / nanodash / 22660601761

04 Mar 2026 08:08AM UTC coverage: 15.94% (-0.09%) from 16.03%
22660601761

Pull #369

github

web-flow
Merge a19d3ced6 into 85e0af2dc
Pull Request #369: Replace "^" for view displays with dropdown menu

699 of 5319 branches covered (13.14%)

Branch coverage included in aggregate %.

1721 of 9863 relevant lines covered (17.45%)

2.39 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.google.common.collect.ArrayListMultimap;
5
import com.google.common.collect.Multimap;
6
import com.knowledgepixels.nanodash.GrlcQuery;
7
import com.knowledgepixels.nanodash.Utils;
8
import com.knowledgepixels.nanodash.ViewDisplay;
9
import com.knowledgepixels.nanodash.component.QueryParamField;
10
import com.knowledgepixels.nanodash.component.QueryResultTableBuilder;
11
import com.knowledgepixels.nanodash.component.TitleBar;
12
import org.apache.wicket.RestartResponseException;
13
import org.apache.wicket.feedback.FeedbackMessage;
14
import org.apache.wicket.markup.html.WebMarkupContainer;
15
import org.apache.wicket.markup.html.basic.Label;
16
import org.apache.wicket.markup.html.form.Form;
17
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
18
import org.apache.wicket.markup.html.link.ExternalLink;
19
import org.apache.wicket.markup.html.list.ListItem;
20
import org.apache.wicket.markup.html.list.ListView;
21
import org.apache.wicket.markup.html.panel.FeedbackPanel;
22
import org.apache.wicket.request.mapper.parameter.INamedParameters.NamedPair;
23
import org.apache.wicket.request.mapper.parameter.PageParameters;
24
import org.apache.wicket.util.string.StringValue;
25
import org.nanopub.extra.services.QueryRef;
26

27
import java.net.URLEncoder;
28
import java.util.List;
29

30
/**
31
 * Page for displaying a query and its parameters, allowing users to run the query with specified parameters.
32
 */
33
public class QueryPage extends NanodashPage {
34

35
    /**
36
     * The mount path for this page.
37
     */
38
    public static final String MOUNT_PATH = "/query";
39

40
    private final Form<Void> form;
41
    private final List<QueryParamField> paramFields;
42
    private final FeedbackPanel feedbackPanel;
43

44
    /**
45
     * {@inheritDoc}
46
     */
47
    @Override
48
    public String getMountPath() {
49
        return MOUNT_PATH;
×
50
    }
51

52
    /**
53
     * Constructor for the QueryPage.
54
     *
55
     * @param parameters The page parameters, which should include the query ID and any query parameters.
56
     */
57
    public QueryPage(final PageParameters parameters) {
58
        super(parameters);
×
59
        add(new TitleBar("titlebar", this, null));
×
60
        add(new Label("pagetitle", "Query Info | nanodash"));
×
61

62
        String id = parameters.get("id").toString();
×
63
        final String queryId = parameters.get("runquery").toString();
×
64
        if (id == null) id = queryId;
×
65

66
        final Multimap<String, String> queryParams = ArrayListMultimap.create();
×
67
        for (NamedPair param : parameters.getAllNamed()) {
×
68
            if (!param.getKey().startsWith("queryparam_")) continue;
×
69
            queryParams.put(param.getKey().replaceFirst("queryparam_", ""), param.getValue());
×
70
        }
×
71

72
        GrlcQuery q = GrlcQuery.get(id);
×
73
        if (!q.getQueryId().equals(id)) {
×
74
            throw new RestartResponseException(getClass(), parameters.set("id", q.getQueryId()));
×
75
        }
76

77
        add(new Label("querylabel", q.getLabel()));
×
78
        add(new BookmarkablePageLink<Void>("np", ExplorePage.class, new PageParameters().set("id", q.getNanopub().getUri().stringValue())));
×
79
        // TODO Replace hard-coded domain with dynamic solution:
80
        add(new ExternalLink("openapi-this", "https://query.knowledgepixels.com/openapi/?url=spec/" + id));
×
81
        add(new ExternalLink("openapi-latest", "https://query.knowledgepixels.com/openapi/?url=spec/" + id + "%3Fapi-version=latest"));
×
82
        add(new Label("querydesc", q.getDescription()));
×
83

84
        form = new Form<Void>("form") {
×
85

86
            @Override
87
            protected void onConfigure() {
88
                super.onConfigure();
×
89
                form.getFeedbackMessages().clear();
×
90
            }
×
91

92
            @Override
93
            protected void onSubmit() {
94
                try {
95
                    PageParameters params = new PageParameters();
×
96
                    params.set("runquery", q.getQueryId());
×
97
                    for (QueryParamField f : paramFields) {
×
98
                        for (String v : f.getValues()) {
×
99
                            params.add("queryparam_" + f.getParamName(), v);
×
100
                        }
101
                    }
×
102
                    setResponsePage(QueryPage.class, params);
×
103
                } catch (Exception ex) {
×
104
                    String message = ex.getClass().getName();
×
105
                    if (ex.getMessage() != null) message = ex.getMessage();
×
106
                    feedbackPanel.error(message);
×
107
                }
×
108
            }
×
109

110
            @Override
111
            protected void onValidate() {
112
                super.onValidate();
×
113
                for (QueryParamField f : paramFields) {
×
114
                    f.getFormComponent().processInput();
×
115
                    for (FeedbackMessage fm : f.getFormComponent().getFeedbackMessages()) {
×
116
                        form.getFeedbackMessages().add(fm);
×
117
                    }
×
118
                }
×
119
            }
×
120

121
        };
122
        form.setOutputMarkupId(true);
×
123

124
        WebMarkupContainer paramContainer = new WebMarkupContainer("params");
×
125

126
        paramFields = q.createParamFields("paramfield");
×
127
        paramContainer.add(new ListView<QueryParamField>("paramfields", paramFields) {
×
128

129
            protected void populateItem(ListItem<QueryParamField> item) {
130
                QueryParamField f = item.getModelObject();
×
131
                f.clearValue();
×
132
                for (StringValue parameter : parameters.getValues("queryparam_" + f.getParamName())) {
×
133
                    f.putValue(parameter.toString().replaceFirst("\\s*$", ""));
×
134
                }
×
135
                item.add(item.getModelObject());
×
136
            }
×
137

138
        });
139
        paramContainer.setVisible(!paramFields.isEmpty());
×
140
        form.add(paramContainer);
×
141

142
        // Hack to prevent auto-execution:
143
        String sparql = "'auto_execution_blocker: Fill in placeholders below if applicable, then remove this line to run the query'\n\n" + q.getSparql();
×
144
        String editLink = q.getEndpoint().stringValue().replaceFirst("^.*/repo/", Utils.getMainQueryUrl() + "tools/") + "/yasgui.html#query=" + URLEncoder.encode(sparql, Charsets.UTF_8);
×
145
        // TODO We also need to replace the nanopub-query placeholder service URLs in the query above.
146
        form.add(new ExternalLink("yasgui", editLink));
×
147

148
        add(form);
×
149

150
        feedbackPanel = new FeedbackPanel("feedback");
×
151
        feedbackPanel.setOutputMarkupId(true);
×
152
        add(feedbackPanel);
×
153

154
        if (queryId == null) {
×
155
            add(new Label("resulttable").setVisible(false));
×
156
        } else {
157
            add(QueryResultTableBuilder.create("resulttable", new QueryRef(queryId, queryParams), new ViewDisplay(20)).plain(true).build());
×
158
        }
159
    }
×
160

161
    /**
162
     * <p>hasAutoRefreshEnabled.</p>
163
     *
164
     * @return a boolean
165
     */
166
    protected boolean hasAutoRefreshEnabled() {
167
        return true;
×
168
    }
169

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