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

knowledgepixels / nanodash / 22618039211

03 Mar 2026 10:05AM UTC coverage: 16.058% (+0.2%) from 15.884%
22618039211

Pull #365

github

web-flow
Merge 1e7e700f0 into a8c4b4a77
Pull Request #365: Refactor of `ResourceWithProfile` and related classes

699 of 5287 branches covered (13.22%)

Branch coverage included in aggregate %.

1721 of 9783 relevant lines covered (17.59%)

2.41 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.MaintainedResource;
5
import com.knowledgepixels.nanodash.page.NanodashPage;
6
import com.knowledgepixels.nanodash.page.PublishPage;
7
import com.knowledgepixels.nanodash.repository.MaintainedResourceRepository;
8
import com.knowledgepixels.nanodash.template.Template;
9
import org.apache.wicket.Component;
10
import org.apache.wicket.ajax.markup.html.navigation.paging.AjaxPagingNavigator;
11
import org.apache.wicket.extensions.markup.html.repeater.data.table.NavigatorLabel;
12
import org.apache.wicket.markup.html.WebMarkupContainer;
13
import org.apache.wicket.markup.html.basic.Label;
14
import org.apache.wicket.markup.html.link.AbstractLink;
15
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
16
import org.apache.wicket.markup.repeater.Item;
17
import org.apache.wicket.markup.repeater.RepeatingView;
18
import org.apache.wicket.markup.repeater.data.DataView;
19
import org.apache.wicket.model.Model;
20
import org.apache.wicket.request.mapper.parameter.PageParameters;
21
import org.eclipse.rdf4j.model.IRI;
22
import org.nanopub.extra.services.ApiResponse;
23
import org.nanopub.extra.services.ApiResponseEntry;
24
import org.nanopub.extra.services.QueryRef;
25

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

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

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

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

47
        String label = grlcQuery.getLabel();
×
48
        if (viewDisplay.getView().getTitle() != null) {
×
49
            label = viewDisplay.getView().getTitle();
×
50
        }
51
        add(new Label("label", label));
×
52
        if (viewDisplay.getNanopubId() != null) {
×
53
            add(new SourceNanopub("np", viewDisplay.getNanopubId(), "smallbutton"));
×
54
        } else {
55
            add(new Label("np").setVisible(false));
×
56
        }
57

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

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

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

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

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

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

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