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

knowledgepixels / nanodash / 20264440287

16 Dec 2025 10:18AM UTC coverage: 15.358% (-0.1%) from 15.457%
20264440287

push

github

tkuhn
feat: Make use of template-version=latest in more places

593 of 4976 branches covered (11.92%)

Branch coverage included in aggregate %.

1571 of 9114 relevant lines covered (17.24%)

2.22 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.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.ajax.markup.html.navigation.paging.AjaxPagingNavigator;
10
import org.apache.wicket.extensions.markup.html.repeater.data.table.NavigatorLabel;
11
import org.apache.wicket.markup.html.WebMarkupContainer;
12
import org.apache.wicket.markup.html.basic.Label;
13
import org.apache.wicket.markup.html.link.AbstractLink;
14
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
15
import org.apache.wicket.markup.repeater.Item;
16
import org.apache.wicket.markup.repeater.RepeatingView;
17
import org.apache.wicket.markup.repeater.data.DataView;
18
import org.apache.wicket.model.Model;
19
import org.apache.wicket.request.mapper.parameter.PageParameters;
20
import org.eclipse.rdf4j.model.IRI;
21
import org.nanopub.extra.services.ApiResponse;
22
import org.nanopub.extra.services.ApiResponseEntry;
23
import org.nanopub.extra.services.QueryRef;
24

25
import java.util.ArrayList;
26
import java.util.List;
27

28
/**
29
 * Component for displaying query results in a list format.
30
 */
31
public class QueryResultList extends QueryResult {
32

33
    private static final String SEPARATOR = " ยท ";
34

35
    /**
36
     * Constructor for QueryResultList.
37
     *
38
     * @param markupId    the markup ID
39
     * @param queryRef    the query reference
40
     * @param response    the API response
41
     * @param viewDisplay the view display
42
     */
43
    QueryResultList(String markupId, QueryRef queryRef, ApiResponse response, ViewDisplay viewDisplay) {
44
        super(markupId, queryRef, response, viewDisplay);
×
45

46
        String label = grlcQuery.getLabel();
×
47
        if (viewDisplay.getView().getTitle() != null) {
×
48
            label = viewDisplay.getView().getTitle();
×
49
        }
50
        add(new Label("label", label));
×
51
        if (viewDisplay.getNanopubId() != null) {
×
52
            add(new BookmarkablePageLink<Void>("np", ExplorePage.class, new PageParameters().set("id", viewDisplay.getNanopubId())));
×
53
        } else {
54
            add(new Label("np").setVisible(false));
×
55
        }
56

57
        setOutputMarkupId(true);
×
58
        populateComponent();
×
59
    }
×
60

61
    @Override
62
    protected void populateComponent() {
63
        QueryResultDataProvider dataProvider = new QueryResultDataProvider(response.getData());
×
64
        DataView<ApiResponseEntry> dataView = new DataView<>("items", dataProvider) {
×
65

66
            @Override
67
            protected void populateItem(Item<ApiResponseEntry> item) {
68
                ApiResponseEntry entry = item.getModelObject();
×
69
                RepeatingView listItem = new RepeatingView("listItem");
×
70

71
                List<Component> components = new ArrayList<>();
×
72
                for (String key : response.getHeader()) {
×
73
                    if (!key.endsWith("_label")) {
×
74
                        String entryValue = entry.get(key);
×
75
                        if (entryValue != null && !entryValue.isBlank()) {
×
76
                            if (entryValue.matches("https?://.+")) {
×
77
                                String entryLabel = entry.get(key + "_label");
×
78
                                components.add(new NanodashLink("component", entryValue, null, null, entryLabel, contextId));
×
79
                            } else {
×
80
                                if (Utils.looksLikeHtml(entryValue)) {
×
81
                                    entryValue = Utils.sanitizeHtml(entryValue);
×
82
                                }
83
                                components.add(new Label("component", entryValue).setEscapeModelStrings(false));
×
84
                            }
85
                        }
86
                    }
87
                }
88
                ResourceView view = viewDisplay.getView();
×
89
                if (view != null && !view.getViewEntryActionList().isEmpty()) {
×
90
                    List<AbstractLink> links = new ArrayList<>();
×
91
                    for (IRI actionIri : view.getViewEntryActionList()) {
×
92
                        // TODO Copied code and adjusted from QueryResultTableBuilder:
93
                        Template t = view.getTemplateForAction(actionIri);
×
94
                        if (t == null) continue;
×
95
                        String targetField = view.getTemplateTargetFieldForAction(actionIri);
×
96
                        if (targetField == null) targetField = "resource";
×
97
                        String labelForAction = view.getLabelForAction(actionIri);
×
98
                        if (labelForAction == null) labelForAction = "action...";
×
99
                        PageParameters params = new PageParameters().set("template", t.getId())
×
100
                                .set("param_" + targetField, contextId)
×
101
                                .set("context", contextId)
×
102
                                .set("template-version", "latest");
×
103
                        String partField = view.getTemplatePartFieldForAction(actionIri);
×
104
                        if (partField != null) {
×
105
                            // TODO Find a better way to pass the MaintainedResource object to this method:
106
                            MaintainedResource r = MaintainedResource.get(contextId);
×
107
                            if (r != null && r.getNamespace() != null) {
×
108
                                params.set("param_" + partField, r.getNamespace() + "<SET-SUFFIX>");
×
109
                            }
110
                        }
111
                        String queryMapping = view.getTemplateQueryMapping(actionIri);
×
112
                        if (queryMapping != null && queryMapping.contains(":")) {
×
113
                            // This part is different from the code in QueryResultTableBuilder:
114
                            String queryParam = queryMapping.split(":")[0];
×
115
                            String templateParam = queryMapping.split(":")[1];
×
116
                            params.set("param_" + templateParam, entry.get(queryParam));
×
117
                        }
118
                        params.set("refresh-upon-publish", queryRef.getAsUrlString());
×
119
                        AbstractLink button = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, params);
×
120
                        button.setBody(Model.of(labelForAction));
×
121
                        links.add(button);
×
122
                    }
×
123
                    components.add(new ButtonList("component", profiledResource, links, null, null));
×
124
                }
125
                ComponentSequence componentSequence = new ComponentSequence(listItem.newChildId(), SEPARATOR, components);
×
126
                listItem.add(componentSequence);
×
127
                item.add(listItem);
×
128
            }
×
129
        };
130
        dataView.setItemsPerPage(10);
×
131
        dataView.setOutputMarkupId(true);
×
132

133
        WebMarkupContainer navigation = new WebMarkupContainer("navigation");
×
134
        navigation.add(new NavigatorLabel("navigatorLabel", dataView));
×
135
        AjaxPagingNavigator pagingNavigator = new AjaxPagingNavigator("navigator", dataView);
×
136
        navigation.setVisible(dataView.getPageCount() > 1);
×
137
        navigation.add(pagingNavigator);
×
138

139
        add(navigation);
×
140
        add(dataView);
×
141
    }
×
142

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