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

knowledgepixels / nanodash / 24334200781

13 Apr 2026 08:45AM UTC coverage: 16.094% (-0.05%) from 16.148%
24334200781

Pull #437

github

web-flow
Merge 91539235a into d46e750d5
Pull Request #437: feat: add filter field to all view types and convert publish page panels to proper views

789 of 6058 branches covered (13.02%)

Branch coverage included in aggregate %.

1977 of 11128 relevant lines covered (17.77%)

2.43 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.UserPage;
10
import com.knowledgepixels.nanodash.repository.MaintainedResourceRepository;
11
import com.knowledgepixels.nanodash.template.Template;
12
import org.apache.wicket.Component;
13
import org.apache.wicket.ajax.AjaxRequestTarget;
14
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
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 AjaxFormComponentUpdatingBehavior("change") {
×
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("_multi_iri")) {
×
128
                            String[] uris = entryValue.split("\\s+");
×
129
                            String labelKey = key.substring(0, key.length() - "_multi_iri".length()) + "_label_multi";
×
130
                            String labelValue = entry.get(labelKey);
×
131
                            String[] labels = labelValue != null ? labelValue.split("\n", -1) : null;
×
132
                            List<Component> links = new ArrayList<>();
×
133
                            for (int i = 0; i < uris.length; i++) {
×
134
                                String label = (labels != null && i < labels.length && !labels[i].isBlank()) ? Utils.unescapeMultiValue(labels[i]) : null;
×
135
                                links.add(new NanodashLink("component", uris[i], null, null, label, contextId));
×
136
                            }
137
                            components.add(new ComponentSequence("component", ", ", links));
×
138
                        } else if (key.endsWith("_multi_val")) {
×
139
                            String labelKey = key.substring(0, key.length() - "_multi_val".length()) + "_label_multi";
×
140
                            String labelValue = entry.get(labelKey);
×
141
                            String[] parts = entryValue.split("\n", -1);
×
142
                            String[] labels = labelValue != null ? labelValue.split("\n", -1) : null;
×
143
                            List<Component> multiComponents = new ArrayList<>();
×
144
                            for (int i = 0; i < parts.length; i++) {
×
145
                                String part = parts[i];
×
146
                                String label = (labels != null && i < labels.length && !labels[i].isBlank()) ? Utils.unescapeMultiValue(labels[i]) : null;
×
147
                                if (part.matches("https?://.+")) {
×
148
                                    multiComponents.add(new NanodashLink("component", part, null, null, label, contextId));
×
149
                                } else {
150
                                    String display = label != null ? label : Utils.unescapeMultiValue(part);
×
151
                                    boolean isHtml = Utils.looksLikeHtml(display);
×
152
                                    if (isHtml) {
×
153
                                        display = Utils.sanitizeHtml(display);
×
154
                                    }
155
                                    multiComponents.add(new Label("component", display).setEscapeModelStrings(!isHtml));
×
156
                                }
157
                            }
158
                            components.add(new ComponentSequence("component", ", ", multiComponents));
×
159
                        } else if (key.endsWith("_multi")) {
×
160
                            String[] parts = entryValue.split("\n", -1);
×
161
                            String labelKey = key.substring(0, key.length() - "_multi".length()) + "_label_multi";
×
162
                            String labelValue = entry.get(labelKey);
×
163
                            String[] labels = labelValue != null ? labelValue.split("\n", -1) : null;
×
164
                            List<Component> multiComponents = new ArrayList<>();
×
165
                            for (int i = 0; i < parts.length; i++) {
×
166
                                String display;
167
                                if (labels != null && i < labels.length && !labels[i].isBlank()) {
×
168
                                    display = Utils.unescapeMultiValue(labels[i]);
×
169
                                } else {
170
                                    display = Utils.unescapeMultiValue(parts[i]);
×
171
                                }
172
                                multiComponents.add(new Label("component", display));
×
173
                            }
174
                            components.add(new ComponentSequence("component", ", ", multiComponents));
×
175
                        } else if (entryValue.matches("https?://.+")) {
×
176
                            String entryLabel = entry.get(key + "_label");
×
177
                            components.add(new NanodashLink("component", entryValue, null, null, entryLabel, contextId));
×
178
                        } else {
×
179
                            if (Utils.looksLikeHtml(entryValue)) {
×
180
                                entryValue = Utils.sanitizeHtml(entryValue);
×
181
                            }
182
                            components.add(new Label("component", entryValue).setEscapeModelStrings(false));
×
183
                        }
184
                    }
185
                }
186
                View view = viewDisplay.getView();
×
187
                if (view != null && !view.getViewEntryActionList().isEmpty()) {
×
188
                    List<AbstractLink> links = new ArrayList<>();
×
189
                    for (IRI actionIri : view.getViewEntryActionList()) {
×
190
                        // TODO Copied code and adjusted from QueryResultTableBuilder:
191
                        Template t = view.getTemplateForAction(actionIri);
×
192
                        if (t == null) continue;
×
193
                        String targetField = view.getTemplateTargetFieldForAction(actionIri);
×
194
                        if (targetField == null) targetField = "resource";
×
195
                        String labelForAction = view.getLabelForAction(actionIri);
×
196
                        if (labelForAction == null) labelForAction = "action...";
×
197
                        if (!labelForAction.endsWith("...")) labelForAction += "...";
×
198
                        PageParameters params = new PageParameters().set("template", t.getId())
×
199
                                .set("param_" + targetField, contextId)
×
200
                                .set("context", contextId)
×
201
                                .set("template-version", "latest");
×
202
                        String partField = view.getTemplatePartFieldForAction(actionIri);
×
203
                        if (partField != null) {
×
204
                            // TODO Find a better way to pass the MaintainedResource object to this method:
205
                            MaintainedResource r = MaintainedResourceRepository.get().findById(contextId);
×
206
                            if (r != null && r.getNamespace() != null) {
×
207
                                params.set("param_" + partField, r.getNamespace() + "<SET-SUFFIX>");
×
208
                            }
209
                        }
210
                        String queryMapping = view.getTemplateQueryMapping(actionIri);
×
211
                        if (queryMapping != null && queryMapping.contains(":")) {
×
212
                            // This part is different from the code in QueryResultTableBuilder:
213
                            String queryParam = queryMapping.split(":")[0];
×
214
                            String templateParam = queryMapping.split(":")[1];
×
215
                            params.set("param_" + templateParam, entry.get(queryParam));
×
216
                        }
217
                        params.set("refresh-upon-publish", queryRef.getAsUrlString());
×
218
                        AbstractLink button = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, params);
×
219
                        button.setBody(Model.of(labelForAction));
×
220
                        links.add(button);
×
221
                    }
×
222
                    components.add(new ButtonList("component", resourceWithProfile, links, null, null));
×
223
                }
224
                ComponentSequence componentSequence = new ComponentSequence(listItem.newChildId(), SEPARATOR, components);
×
225
                listItem.add(componentSequence);
×
226
                item.add(listItem);
×
227
            }
×
228
        };
229
        dataView.setItemsPerPage(10);
×
230

231
        WebMarkupContainer navigation = new WebMarkupContainer("navigation");
×
232
        navigation.add(new NavigatorLabel("navigatorLabel", dataView));
×
233
        AjaxPagingNavigator pagingNavigator = new AjaxPagingNavigator("navigator", dataView);
×
234
        navigation.setVisible(dataView.getPageCount() > 1);
×
235
        navigation.add(pagingNavigator);
×
236

237
        itemsContainer = new WebMarkupContainer("items-container");
×
238
        itemsContainer.setOutputMarkupId(true);
×
239
        itemsContainer.add(dataView);
×
240
        itemsContainer.add(navigation);
×
241
        add(itemsContainer);
×
242
    }
×
243

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