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

knowledgepixels / nanodash / 21569970831

01 Feb 2026 08:46PM UTC coverage: 14.11% (-0.2%) from 14.273%
21569970831

push

github

tkuhn
style: Remove "beta" from logo and "by Knowledge Pixels" link

549 of 5182 branches covered (10.59%)

Branch coverage included in aggregate %.

1506 of 9382 relevant lines covered (16.05%)

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

3
import com.knowledgepixels.nanodash.*;
4
import com.knowledgepixels.nanodash.page.ExplorePage;
5
import com.knowledgepixels.nanodash.page.NanodashPage;
6
import com.knowledgepixels.nanodash.page.PublishPage;
7
import com.knowledgepixels.nanodash.template.Template;
8
import org.apache.wicket.Component;
9
import org.apache.wicket.behavior.AttributeAppender;
10
import org.apache.wicket.ajax.AjaxRequestTarget;
11
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
12
import org.apache.wicket.extensions.ajax.markup.html.repeater.data.table.AjaxNavigationToolbar;
13
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
14
import org.apache.wicket.extensions.markup.html.repeater.data.table.*;
15
import org.apache.wicket.markup.html.basic.Label;
16
import org.apache.wicket.markup.html.form.TextField;
17
import org.apache.wicket.markup.html.link.AbstractLink;
18
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
19
import org.apache.wicket.markup.repeater.Item;
20
import org.apache.wicket.model.IModel;
21
import org.apache.wicket.model.Model;
22
import org.apache.wicket.request.mapper.parameter.PageParameters;
23
import org.eclipse.rdf4j.model.IRI;
24
import org.nanopub.extra.services.ApiResponse;
25
import org.nanopub.extra.services.ApiResponseEntry;
26
import org.nanopub.extra.services.QueryRef;
27
import org.slf4j.Logger;
28
import org.slf4j.LoggerFactory;
29

30
import java.util.ArrayList;
31
import java.util.List;
32

33
/**
34
 * Component for displaying query results in a table format.
35
 */
36
public class QueryResultTable extends QueryResult {
37

38
    private static final Logger logger = LoggerFactory.getLogger(QueryResultTable.class);
×
39

40
    private Model<String> errorMessages = Model.of("");
×
41
    private DataTable<ApiResponseEntry, String> table;
42
    private Label errorLabel;
43
    private FilteredQueryResultDataProvider filteredDataProvider;
44
    private Model<String> filterModel = Model.of("");
×
45

46
    QueryResultTable(String id, QueryRef queryRef, ApiResponse response, ViewDisplay viewDisplay, boolean plain) {
47
        super(id, queryRef, response, viewDisplay);
×
48

49
        if (plain) {
×
50
            add(new Label("label").setVisible(false));
×
51
            add(new Label("np").setVisible(false));
×
52
        } else {
53
            String label = grlcQuery.getLabel();
×
54
            if (viewDisplay.getTitle() != null) {
×
55
                label = viewDisplay.getTitle();
×
56
            }
57
            add(new Label("label", label));
×
58
            if (viewDisplay.getNanopubId() != null) {
×
59
                add(new BookmarkablePageLink<Void>("np", ExplorePage.class, new PageParameters().set("id", viewDisplay.getNanopubId())));
×
60
            } else {
61
                add(new Label("np").setVisible(false));
×
62
            }
63
        }
64

65
        errorLabel = new Label("error-messages", errorMessages);
×
66
        errorLabel.setVisible(false);
×
67
        add(errorLabel);
×
68

69
        TextField<String> filterField = new TextField<>("filter", filterModel);
×
70
        filterField.setOutputMarkupId(true);
×
71
        filterField.add(new AjaxFormComponentUpdatingBehavior("change") {
×
72
            @Override
73
            protected void onUpdate(AjaxRequestTarget target) {
74
                if (filteredDataProvider != null && table != null) {
×
75
                    filteredDataProvider.setFilterText(filterModel.getObject());
×
76
                    target.add(table);
×
77
                }
78
            }
×
79
        });
80
        add(filterField);
×
81

82
        populateComponent();
×
83
    }
×
84

85
    private void addErrorMessage(String errorMessage) {
86
        String s = errorMessages.getObject();
×
87
        if (s.isEmpty()) {
×
88
            s = "Error: " + errorMessage;
×
89
        } else {
90
            s += ", " + errorMessage;
×
91
        }
92
        errorMessages.setObject(s);
×
93
        errorLabel.setVisible(true);
×
94
        if (table != null) table.setVisible(false);
×
95
    }
×
96

97
    @Override
98
    protected void populateComponent() {
99
        List<IColumn<ApiResponseEntry, String>> columns = new ArrayList<>();
×
100
        QueryResultDataProvider dataProvider;
101
        try {
102
            for (String h : response.getHeader()) {
×
103
                if (h.endsWith("_label")) {
×
104
                    continue;
×
105
                }
106
                columns.add(new Column(h.replaceAll("_", " "), h));
×
107
            }
108
            if (viewDisplay.getView() != null && !viewDisplay.getView().getViewEntryActionList().isEmpty()) {
×
109
                columns.add(new Column("", Column.ACTIONS));
×
110
            }
111
            dataProvider = new QueryResultDataProvider(response.getData());
×
112
            filteredDataProvider = new FilteredQueryResultDataProvider(dataProvider, response);
×
113
            table = new DataTable<>("table", columns, filteredDataProvider, viewDisplay.getPageSize() < 1 ? Integer.MAX_VALUE : viewDisplay.getPageSize());
×
114
            table.setOutputMarkupId(true);
×
115
            table.addBottomToolbar(new AjaxNavigationToolbar(table));
×
116
            table.addBottomToolbar(new NoRecordsToolbar(table));
×
117
            table.addTopToolbar(new HeadersToolbar<String>(table, dataProvider));
×
118
            add(table);
×
119
        } catch (Exception ex) {
×
120
            logger.error("Error creating table for query {}", grlcQuery.getQueryId(), ex);
×
121
            add(new Label("table", "").setVisible(false));
×
122
            addErrorMessage(ex.getMessage());
×
123
        }
×
124
    }
×
125

126
    private class Column extends AbstractColumn<ApiResponseEntry, String> {
127

128
        private String key;
129
        public static final String ACTIONS = "*actions*";
130

131
        public Column(String title, String key) {
×
132
            super(new Model<String>(title), key);
×
133
            this.key = key;
×
134
        }
×
135

136
        @Override
137
        public void populateItem(Item<ICellPopulator<ApiResponseEntry>> cellItem, String componentId, IModel<ApiResponseEntry> rowModel) {
138
            try {
139
                ResourceView view = viewDisplay.getView();
×
140
                if (key.equals(ACTIONS) && view != null) {
×
141
                    List<AbstractLink> links = new ArrayList<>();
×
142
                    for (IRI actionIri : view.getViewEntryActionList()) {
×
143
                        // TODO Copied code and adjusted from QueryResultTableBuilder:
144
                        Template t = view.getTemplateForAction(actionIri);
×
145
                        if (t == null) continue;
×
146
                        String targetField = view.getTemplateTargetFieldForAction(actionIri);
×
147
                        if (targetField == null) targetField = "resource";
×
148
                        String label = view.getLabelForAction(actionIri);
×
149
                        if (label == null) label = "action...";
×
150
                        PageParameters params = new PageParameters().set("template", t.getId())
×
151
                                .set("param_" + targetField, contextId)
×
152
                                .set("context", contextId)
×
153
                                .set("template-version", "latest");
×
154
                        if (partId != null && contextId != null && !partId.equals(contextId)) {
×
155
                            params.set("part", partId);
×
156
                        }
157
                        String partField = view.getTemplatePartFieldForAction(actionIri);
×
158
                        if (partField != null) {
×
159
                            // TODO Find a better way to pass the MaintainedResource object to this method:
160
                            MaintainedResource r = MaintainedResource.get(contextId);
×
161
                            if (r != null && r.getNamespace() != null) {
×
162
                                params.set("param_" + partField, r.getNamespace() + "<SET-SUFFIX>");
×
163
                            }
164
                        }
165
                        String queryMapping = view.getTemplateQueryMapping(actionIri);
×
166
                        if (queryMapping != null && queryMapping.contains(":")) {
×
167
                            // This part is different from the code in QueryResultTableBuilder:
168
                            String queryParam = queryMapping.split(":")[0];
×
169
                            String templateParam = queryMapping.split(":")[1];
×
170
                            params.set("param_" + templateParam, rowModel.getObject().get(queryParam));
×
171
                        }
172
                        params.set("refresh-upon-publish", queryRef.getAsUrlString());
×
173
                        AbstractLink button = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, params);
×
174
                        button.setBody(Model.of(label));
×
175
                        links.add(button);
×
176
                    }
×
177
                    cellItem.add(new ButtonList(componentId, profiledResource, links, null, null));
×
178
                } else {
×
179
                    String value = rowModel.getObject().get(key);
×
180
                    if (value.matches("https?://.+ .+")) {
×
181
                        List<Component> links = new ArrayList<>();
×
182
                        for (String v : value.split(" ")) {
×
183
                            links.add(new NanodashLink("component", v));
×
184
                        }
185
                        cellItem.add(new ComponentSequence(componentId, ", ", links));
×
186
                    } else if (value.matches("https?://.+")) {
×
187
                        String label = rowModel.getObject().get(key + "_label");
×
188
                        cellItem.add(new NanodashLink(componentId, value, null, null, label, contextId));
×
189
                    } else {
×
190
                        if (key.startsWith("pubkey")) {
×
191
                            cellItem.add(new Label(componentId, value).add(new AttributeAppender("style", "overflow-wrap: anywhere;")));
×
192
                        } else {
193
                            Label cellLabel;
194
                            if (Utils.looksLikeHtml(value)) {
×
195
                                cellLabel = (Label) new Label(componentId, Utils.sanitizeHtml(value))
×
196
                                        .setEscapeModelStrings(false)
×
197
                                        .add(new AttributeAppender("class", "cell-data-html"));
×
198
                            } else {
199
                                cellLabel = new Label(componentId, value);
×
200
                            }
201
                            cellItem.add(cellLabel);
×
202
                        }
203
                    }
204
                }
205
            } catch (Exception ex) {
×
206
                logger.error("Failed to populate table column: ", ex);
×
207
                cellItem.add(new Label(componentId).setVisible(false));
×
208
                addErrorMessage(ex.getMessage());
×
209
            }
×
210
        }
×
211

212
    }
213

214
//    private class ApiResponseComparator implements Comparator<ApiResponseEntry>, Serializable {
215
//
216
//        private SortParam<String> sortParam;
217
//
218
//        public ApiResponseComparator(SortParam<String> sortParam) {
219
//            this.sortParam = sortParam;
220
//        }
221
//
222
//        @Override
223
//        public int compare(ApiResponseEntry o1, ApiResponseEntry o2) {
224
//            String p = sortParam.getProperty();
225
//            int result;
226
//            if (o1.get(p) == null && o2.get(p) == null) {
227
//                result = 0;
228
//            } else if (o1.get(p) == null) {
229
//                result = 1;
230
//            } else if (o2.get(p) == null) {
231
//                result = -1;
232
//            } else {
233
//                result = o1.get(p).compareTo(o2.get(p));
234
//            }
235
//            if (!sortParam.isAscending()) result = -result;
236
//            return result;
237
//        }
238
//
239
//    }
240

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