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

knowledgepixels / nanodash / 26638862479

29 May 2026 01:03PM UTC coverage: 20.826% (-0.01%) from 20.836%
26638862479

Pull #477

github

web-flow
Merge 3337ee0f8 into 7ef27216c
Pull Request #477: feat: render /explore "Described in" as a view display + list empty-state note

1003 of 6132 branches covered (16.36%)

Branch coverage included in aggregate %.

2584 of 11092 relevant lines covered (23.3%)

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

3
import com.knowledgepixels.nanodash.*;
4
import com.knowledgepixels.nanodash.domain.IndividualAgent;
5
import com.knowledgepixels.nanodash.domain.MaintainedResource;
6
import com.knowledgepixels.nanodash.domain.User;
7
import com.knowledgepixels.nanodash.page.NanodashPage;
8
import com.knowledgepixels.nanodash.page.PublishPage;
9
import com.knowledgepixels.nanodash.page.QueryPage;
10
import com.knowledgepixels.nanodash.page.UserPage;
11
import com.knowledgepixels.nanodash.repository.MaintainedResourceRepository;
12
import com.knowledgepixels.nanodash.template.Template;
13
import org.apache.wicket.Component;
14
import org.apache.wicket.ajax.AjaxRequestTarget;
15
import org.apache.wicket.ajax.markup.html.navigation.paging.AjaxPagingNavigator;
16
import org.apache.wicket.markup.html.form.TextField;
17
import org.apache.wicket.extensions.markup.html.repeater.data.table.NavigatorLabel;
18
import org.apache.wicket.markup.html.WebMarkupContainer;
19
import org.apache.wicket.markup.html.basic.Label;
20
import org.apache.wicket.markup.html.link.AbstractLink;
21
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
22
import org.apache.wicket.markup.repeater.Item;
23
import org.apache.wicket.markup.repeater.RepeatingView;
24
import org.apache.wicket.markup.repeater.data.DataView;
25
import org.apache.wicket.model.Model;
26
import org.apache.wicket.request.cycle.RequestCycle;
27
import org.apache.wicket.request.mapper.parameter.PageParameters;
28
import org.apache.wicket.request.resource.ContextRelativeResourceReference;
29
import org.apache.wicket.util.string.Strings;
30
import org.eclipse.rdf4j.model.IRI;
31
import org.nanopub.extra.services.ApiResponse;
32
import org.nanopub.extra.services.ApiResponseEntry;
33
import org.nanopub.extra.services.QueryRef;
34

35
import java.util.ArrayList;
36
import java.util.List;
37

38
/**
39
 * Component for displaying query results in a list format.
40
 */
41
public class QueryResultList extends QueryResult {
42

43
    private static final String SEPARATOR = " ยท ";
44

45
    private FilteredQueryResultDataProvider filteredDataProvider;
46
    private Model<String> filterModel = Model.of("");
×
47
    private WebMarkupContainer itemsContainer;
48

49
    /**
50
     * Constructor for QueryResultList.
51
     *
52
     * @param markupId    the markup ID
53
     * @param queryRef    the query reference
54
     * @param response    the API response
55
     * @param viewDisplay the view display
56
     */
57
    QueryResultList(String markupId, QueryRef queryRef, ApiResponse response, ViewDisplay viewDisplay) {
58
        super(markupId, queryRef, response, viewDisplay);
×
59

60
        String label = grlcQuery.getLabel();
×
61
        if (viewDisplay.getTitle() != null) {
×
62
            label = viewDisplay.getTitle();
×
63
        }
64
        add(new Label("label", label));
×
65
        setOutputMarkupId(true);
×
66

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

80
        populateComponent();
×
81
    }
×
82

83
    @Override
84
    protected void populateComponent() {
85
        QueryResultDataProvider dataProvider = new QueryResultDataProvider(response.getData());
×
86
        filteredDataProvider = new FilteredQueryResultDataProvider(dataProvider, response);
×
87
        DataView<ApiResponseEntry> dataView = new DataView<>("items", filteredDataProvider) {
×
88

89
            @Override
90
            protected void populateItem(Item<ApiResponseEntry> item) {
91
                ApiResponseEntry entry = item.getModelObject();
×
92
                RepeatingView listItem = new RepeatingView("listItem");
×
93

94
                List<Component> components = new ArrayList<>();
×
95
                for (String key : response.getHeader()) {
×
96
                    if (key.endsWith("_label") || key.endsWith("_label_multi")) {
×
97
                        continue;
×
98
                    }
99
                    String entryValue = entry.get(key);
×
100
                    if (entryValue != null && !entryValue.isBlank()) {
×
101
                        if (key.endsWith("user_iri")) {
×
102
                            IRI userIri = Utils.vf.createIRI(entryValue);
×
103
                            IRI profilePicIri = User.getProfilePicture(userIri);
×
104
                            String imgSrc;
105
                            if (profilePicIri != null) {
×
106
                                imgSrc = Strings.escapeMarkup(profilePicIri.stringValue()).toString();
×
107
                            } else if (IndividualAgent.isSoftware(userIri)) {
×
108
                                imgSrc = RequestCycle.get().urlFor(new ContextRelativeResourceReference("images/bot-icon.svg", false), null).toString();
×
109
                            } else {
110
                                imgSrc = RequestCycle.get().urlFor(new ContextRelativeResourceReference("images/user-icon.svg", false), null).toString();
×
111
                            }
112
                            String userLabel = entry.get(key + "_label");
×
113
                            String displayLabel = userLabel != null && !userLabel.isBlank() ? userLabel : User.getShortDisplayName(userIri);
×
114
                            String userUrl = UserPage.MOUNT_PATH + "?id=" + Utils.urlEncode(entryValue);
×
115
                            String linkHtml = "<a href=\"" + Strings.escapeMarkup(userUrl) + "\">" + Strings.escapeMarkup(displayLabel) + "</a>";
×
116
                            components.add(new ComponentSequence("component", " ", List.of(
×
117
                                    new Label("component", "<img class=\"user-icon\" src=\"" + imgSrc + "\" />").setEscapeModelStrings(false),
×
118
                                    new Label("component", linkHtml).setEscapeModelStrings(false))));
×
119
                        } else if (key.endsWith("template_iri")) {
×
120
                            String templateLabel = entry.get(key + "_label");
×
121
                            String displayLabel = templateLabel != null && !templateLabel.isBlank() ? templateLabel : entryValue;
×
122
                            String templateUrl = PublishPage.MOUNT_PATH + "?template=" + Utils.urlEncode(entryValue) + "&template-version=latest";
×
123
                            String linkHtml = "<a href=\"" + Strings.escapeMarkup(templateUrl) + "\">" + Strings.escapeMarkup(displayLabel) + "</a>";
×
124
                            components.add(new ComponentSequence("component", " ", List.of(
×
125
                                    new Label("component", "<span class=\"form-icon\"></span>").setEscapeModelStrings(false),
×
126
                                    new Label("component", linkHtml).setEscapeModelStrings(false))));
×
127
                        } else if (key.endsWith("query_iri")) {
×
128
                            String queryLabel = entry.get(key + "_label");
×
129
                            String displayLabel = queryLabel != null && !queryLabel.isBlank() ? queryLabel : entryValue;
×
130
                            String queryUrl = QueryPage.MOUNT_PATH + "?id=" + Utils.urlEncode(entryValue);
×
131
                            String linkHtml = "<a href=\"" + Strings.escapeMarkup(queryUrl) + "\">" + Strings.escapeMarkup(displayLabel) + "</a>";
×
132
                            components.add(new Label("component", linkHtml).setEscapeModelStrings(false));
×
133
                        } else if (key.endsWith("_multi_iri")) {
×
134
                            String[] uris = entryValue.split("\\s+");
×
135
                            String labelKey = key.substring(0, key.length() - "_multi_iri".length()) + "_label_multi";
×
136
                            String labelValue = entry.get(labelKey);
×
137
                            String[] labels = labelValue != null ? labelValue.split("\n", -1) : null;
×
138
                            List<Component> links = new ArrayList<>();
×
139
                            for (int i = 0; i < uris.length; i++) {
×
140
                                String uri = uris[i];
×
141
                                if (uri.isBlank()) continue;
×
142
                                String label = (labels != null && i < labels.length && !labels[i].isBlank()) ? Utils.unescapeMultiValue(labels[i]) : null;
×
143
                                // SPARQL coalesce often falls back to the URI string itself; treat that as no label
144
                                // so NanodashLink can derive a short name from the URI.
145
                                if (label != null && label.equals(uri)) label = null;
×
146
                                links.add(new NanodashLink("component", uri, null, null, label, contextId));
×
147
                            }
148
                            components.add(new ComponentSequence("component", ", ", links));
×
149
                        } else if (key.endsWith("_multi_val")) {
×
150
                            String labelKey = key.substring(0, key.length() - "_multi_val".length()) + "_label_multi";
×
151
                            String labelValue = entry.get(labelKey);
×
152
                            String[] parts = entryValue.split("\n", -1);
×
153
                            String[] labels = labelValue != null ? labelValue.split("\n", -1) : null;
×
154
                            List<Component> multiComponents = new ArrayList<>();
×
155
                            for (int i = 0; i < parts.length; i++) {
×
156
                                String part = parts[i];
×
157
                                String label = (labels != null && i < labels.length && !labels[i].isBlank()) ? Utils.unescapeMultiValue(labels[i]) : null;
×
158
                                if (part.matches("https?://.+")) {
×
159
                                    if (label != null && label.equals(part)) label = null;
×
160
                                    multiComponents.add(new NanodashLink("component", part, null, null, label, contextId));
×
161
                                } else {
162
                                    String display = label != null ? label : Utils.unescapeMultiValue(part);
×
163
                                    boolean isHtml = Utils.looksLikeHtml(display);
×
164
                                    if (isHtml) {
×
165
                                        display = Utils.sanitizeHtml(display);
×
166
                                    }
167
                                    multiComponents.add(new Label("component", display).setEscapeModelStrings(!isHtml));
×
168
                                }
169
                            }
170
                            components.add(new ComponentSequence("component", ", ", multiComponents));
×
171
                        } else if (key.endsWith("_multi")) {
×
172
                            String[] parts = entryValue.split("\n", -1);
×
173
                            String labelKey = key.substring(0, key.length() - "_multi".length()) + "_label_multi";
×
174
                            String labelValue = entry.get(labelKey);
×
175
                            String[] labels = labelValue != null ? labelValue.split("\n", -1) : null;
×
176
                            List<Component> multiComponents = new ArrayList<>();
×
177
                            for (int i = 0; i < parts.length; i++) {
×
178
                                String display;
179
                                if (labels != null && i < labels.length && !labels[i].isBlank()) {
×
180
                                    display = Utils.unescapeMultiValue(labels[i]);
×
181
                                } else {
182
                                    display = Utils.unescapeMultiValue(parts[i]);
×
183
                                }
184
                                multiComponents.add(new Label("component", display));
×
185
                            }
186
                            components.add(new ComponentSequence("component", ", ", multiComponents));
×
187
                        } else if (entryValue.matches("https?://.+")) {
×
188
                            String entryLabel = entry.get(key + "_label");
×
189
                            components.add(new NanodashLink("component", entryValue, null, null, entryLabel, contextId));
×
190
                        } else {
×
191
                            if (Utils.looksLikeHtml(entryValue)) {
×
192
                                entryValue = Utils.sanitizeHtml(entryValue);
×
193
                            }
194
                            components.add(new Label("component", entryValue).setEscapeModelStrings(false));
×
195
                        }
196
                    }
197
                }
198
                View view = viewDisplay.getView();
×
199
                if (view != null && !view.getViewEntryActionList().isEmpty()) {
×
200
                    List<AbstractLink> links = new ArrayList<>();
×
201
                    for (IRI actionIri : view.getViewEntryActionList()) {
×
202
                        // TODO Copied code and adjusted from QueryResultTableBuilder:
203
                        Template t = view.getTemplateForAction(actionIri);
×
204
                        if (t == null) continue;
×
205
                        String targetField = view.getTemplateTargetFieldForAction(actionIri);
×
206
                        if (targetField == null) targetField = "resource";
×
207
                        String labelForAction = view.getLabelForAction(actionIri);
×
208
                        if (labelForAction == null) labelForAction = "action...";
×
209
                        if (!labelForAction.endsWith("...")) labelForAction += "...";
×
210
                        PageParameters params = new PageParameters().set("template", t.getId())
×
211
                                .set("param_" + targetField, contextId)
×
212
                                .set("context", contextId)
×
213
                                .set("template-version", "latest");
×
214
                        String partField = view.getTemplatePartFieldForAction(actionIri);
×
215
                        if (partField != null) {
×
216
                            // TODO Find a better way to pass the MaintainedResource object to this method:
217
                            MaintainedResource r = MaintainedResourceRepository.get().findById(contextId);
×
218
                            if (r != null && r.getNamespace() != null) {
×
219
                                params.set("param_" + partField, r.getNamespace() + "<SET-SUFFIX>");
×
220
                            }
221
                        }
222
                        String queryMapping = view.getTemplateQueryMapping(actionIri);
×
223
                        if (queryMapping != null && queryMapping.contains(":")) {
×
224
                            // This part is different from the code in QueryResultTableBuilder:
225
                            String queryParam = queryMapping.split(":")[0];
×
226
                            String templateParam = queryMapping.split(":")[1];
×
227
                            params.set("param_" + templateParam, entry.get(queryParam));
×
228
                        }
229
                        params.set("refresh-upon-publish", queryRef.getAsUrlString());
×
230
                        AbstractLink button = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, params);
×
231
                        button.setBody(Model.of(labelForAction));
×
232
                        links.add(button);
×
233
                    }
×
234
                    components.add(new ButtonList("component", resourceWithProfile, links, null, null));
×
235
                }
236
                ComponentSequence componentSequence = new ComponentSequence(listItem.newChildId(), SEPARATOR, components);
×
237
                listItem.add(componentSequence);
×
238
                item.add(listItem);
×
239
            }
×
240
        };
241
        dataView.setItemsPerPage(viewDisplay.getPageSize());
×
242

243
        WebMarkupContainer navigation = new WebMarkupContainer("navigation");
×
244
        navigation.add(new NavigatorLabel("navigatorLabel", dataView));
×
245
        AjaxPagingNavigator pagingNavigator = new AjaxPagingNavigator("navigator", dataView);
×
246
        navigation.setVisible(dataView.getPageCount() > 1);
×
247
        navigation.add(pagingNavigator);
×
248

249
        Label noRecordsLabel = new Label("no-records", "Nothing found.") {
×
250
            @Override
251
            protected void onConfigure() {
252
                super.onConfigure();
×
253
                setVisible(filteredDataProvider.size() == 0);
×
254
            }
×
255
        };
256

257
        itemsContainer = new WebMarkupContainer("items-container");
×
258
        itemsContainer.setOutputMarkupId(true);
×
259
        itemsContainer.add(dataView);
×
260
        itemsContainer.add(noRecordsLabel);
×
261
        itemsContainer.add(navigation);
×
262
        add(itemsContainer);
×
263
    }
×
264

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