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

knowledgepixels / nanodash / 22767166801

06 Mar 2026 02:14PM UTC coverage: 15.73% (-0.1%) from 15.877%
22767166801

Pull #381

github

web-flow
Merge eade858ec into 45247de7b
Pull Request #381: feat(QueryPage): support CONSTRUCT queries

705 of 5435 branches covered (12.97%)

Branch coverage included in aggregate %.

1743 of 10128 relevant lines covered (17.21%)

2.35 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.ApiCache;
7
import com.knowledgepixels.nanodash.GrlcQuery;
8
import com.knowledgepixels.nanodash.Utils;
9
import com.knowledgepixels.nanodash.ViewDisplay;
10
import com.knowledgepixels.nanodash.component.QueryParamField;
11
import com.knowledgepixels.nanodash.component.QueryResultRdf;
12
import com.knowledgepixels.nanodash.component.QueryResultTableBuilder;
13
import com.knowledgepixels.nanodash.component.RdfResultComponent;
14
import com.knowledgepixels.nanodash.component.TitleBar;
15
import org.apache.wicket.Component;
16
import org.eclipse.rdf4j.model.Model;
17
import org.apache.wicket.RestartResponseException;
18
import org.apache.wicket.feedback.FeedbackMessage;
19
import org.apache.wicket.markup.html.WebMarkupContainer;
20
import org.apache.wicket.markup.html.basic.Label;
21
import org.apache.wicket.markup.html.form.Form;
22
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
23
import org.apache.wicket.markup.html.form.Button;
24
import org.apache.wicket.markup.html.link.ExternalLink;
25
import org.apache.wicket.markup.html.list.ListItem;
26
import org.apache.wicket.markup.html.list.ListView;
27
import org.apache.wicket.request.IRequestParameters;
28
import org.apache.wicket.request.flow.RedirectToUrlException;
29
import org.apache.wicket.markup.html.panel.FeedbackPanel;
30
import org.apache.wicket.request.mapper.parameter.INamedParameters.NamedPair;
31
import org.apache.wicket.request.mapper.parameter.PageParameters;
32
import org.apache.wicket.util.string.StringValue;
33
import org.nanopub.extra.services.QueryRef;
34

35
import java.net.URLEncoder;
36
import java.util.List;
37

38
/**
39
 * Page for displaying a query and its parameters, allowing users to run the query with specified parameters.
40
 */
41
public class QueryPage extends NanodashPage {
42

43
    /**
44
     * The mount path for this page.
45
     */
46
    public static final String MOUNT_PATH = "/query";
47

48
    private final Form<Void> form;
49
    private final List<QueryParamField> paramFields;
50
    private final FeedbackPanel feedbackPanel;
51

52
    /**
53
     * {@inheritDoc}
54
     */
55
    @Override
56
    public String getMountPath() {
57
        return MOUNT_PATH;
×
58
    }
59

60
    /**
61
     * Constructor for the QueryPage.
62
     *
63
     * @param parameters The page parameters, which should include the query ID and any query parameters.
64
     */
65
    public QueryPage(final PageParameters parameters) {
66
        super(parameters);
×
67
        add(new TitleBar("titlebar", this, null));
×
68
        add(new Label("pagetitle", "Query Info | nanodash"));
×
69

70
        String id = parameters.get("id").toString();
×
71
        final String queryId = parameters.get("runquery").toString();
×
72
        if (id == null) id = queryId;
×
73

74
        final Multimap<String, String> queryParams = ArrayListMultimap.create();
×
75
        for (NamedPair param : parameters.getAllNamed()) {
×
76
            if (!param.getKey().startsWith("queryparam_")) continue;
×
77
            queryParams.put(param.getKey().replaceFirst("queryparam_", ""), param.getValue());
×
78
        }
×
79

80
        GrlcQuery q = GrlcQuery.get(id);
×
81
        if (!q.getQueryId().equals(id)) {
×
82
            throw new RestartResponseException(getClass(), parameters.set("id", q.getQueryId()));
×
83
        }
84

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

92
        form = new Form<Void>("form") {
×
93

94
            @Override
95
            protected void onConfigure() {
96
                super.onConfigure();
×
97
                form.getFeedbackMessages().clear();
×
98
            }
×
99

100
            @Override
101
            protected void onSubmit() {
102
                try {
103
                    PageParameters params = new PageParameters();
×
104
                    params.set("runquery", q.getQueryId());
×
105
                    for (QueryParamField f : paramFields) {
×
106
                        for (String v : f.getValues()) {
×
107
                            params.add("queryparam_" + f.getParamName(), v);
×
108
                        }
109
                    }
×
110
                    setResponsePage(QueryPage.class, params);
×
111
                } catch (Exception ex) {
×
112
                    String message = ex.getClass().getName();
×
113
                    if (ex.getMessage() != null) message = ex.getMessage();
×
114
                    feedbackPanel.error(message);
×
115
                }
×
116
            }
×
117

118
            @Override
119
            protected void onValidate() {
120
                super.onValidate();
×
121
                for (QueryParamField f : paramFields) {
×
122
                    f.getFormComponent().processInput();
×
123
                    for (FeedbackMessage fm : f.getFormComponent().getFeedbackMessages()) {
×
124
                        form.getFeedbackMessages().add(fm);
×
125
                    }
×
126
                }
×
127
            }
×
128

129
        };
130
        form.setOutputMarkupId(true);
×
131

132
        WebMarkupContainer paramContainer = new WebMarkupContainer("params");
×
133

134
        paramFields = q.createParamFields("paramfield");
×
135
        for (QueryParamField f : paramFields) {
×
136
            for (StringValue parameter : parameters.getValues("queryparam_" + f.getParamName())) {
×
137
                f.putValue(parameter.toString().replaceFirst("\\s*$", ""));
×
138
            }
×
139
        }
×
140
        paramContainer.add(new ListView<QueryParamField>("paramfields", paramFields) {
×
141

142
            protected void populateItem(ListItem<QueryParamField> item) {
143
                item.add(item.getModelObject());
×
144
            }
×
145

146
        });
147
        paramContainer.setVisible(!paramFields.isEmpty());
×
148
        form.add(paramContainer);
×
149

150
        form.add(new Button("yasgui") {
×
151

152
            @Override
153
            public void onSubmit() {
154
                IRequestParameters params = getRequest().getPostParameters();
×
155
                for (QueryParamField f : paramFields) {
×
156
                    StringValue input = params.getParameterValue(f.getFormComponent().getInputName());
×
157
                    f.clearValue();
×
158
                    if (!input.isNull() && !input.isEmpty()) {
×
159
                        f.putValue(input.toString());
×
160
                    }
161
                }
×
162
                String sparql = q.expandQuery(paramFields);
×
163
                boolean allSet = GrlcQuery.allMandatoryFieldsSet(paramFields);
×
164
                if (!allSet) {
×
165
                    sparql = "'auto_execution_blocker: Fill in placeholders below, then remove this line to run the query'\n\n" + sparql;
×
166
                }
167
                String editLink = q.getEndpoint().stringValue().replaceFirst("^.*/repo/", Utils.getMainQueryUrl() + "tools/")
×
168
                    + "/yasgui.html#query=" + URLEncoder.encode(sparql, Charsets.UTF_8);
×
169
                throw new RedirectToUrlException(editLink);
×
170
            }
171

172
        }.setDefaultFormProcessing(false));
×
173

174
        add(form);
×
175

176
        feedbackPanel = new FeedbackPanel("feedback");
×
177
        feedbackPanel.setOutputMarkupId(true);
×
178
        add(feedbackPanel);
×
179

180
        if (queryId == null) {
×
181
            add(new Label("resulttable").setVisible(false));
×
182
        } else if (q.isConstructQuery()) {
×
183
            QueryRef constructQueryRef = new QueryRef(queryId, queryParams);
×
184
            Model rdfModel = ApiCache.retrieveRdfModelAsync(constructQueryRef);
×
185
            if (rdfModel != null) {
×
186
                add(new QueryResultRdf("resulttable", rdfModel));
×
187
            } else {
188
                add(new RdfResultComponent("resulttable", constructQueryRef) {
×
189
                    @Override
190
                    public Component getRdfResultComponent(String markupId, Model model) {
191
                        return new QueryResultRdf(markupId, model);
×
192
                    }
193
                });
194
            }
195
        } else {
×
196
            add(QueryResultTableBuilder.create("resulttable", new QueryRef(queryId, queryParams), new ViewDisplay(20)).plain(true).build());
×
197
        }
198
    }
×
199

200
    /**
201
     * <p>hasAutoRefreshEnabled.</p>
202
     *
203
     * @return a boolean
204
     */
205
    protected boolean hasAutoRefreshEnabled() {
206
        return true;
×
207
    }
208

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