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

knowledgepixels / nanodash / 19820983664

01 Dec 2025 11:24AM UTC coverage: 15.298% (+1.9%) from 13.36%
19820983664

push

github

web-flow
Merge pull request #313 from knowledgepixels/296-refactor-usage-of-pair-as-classes

Replace Pair with new class

591 of 4966 branches covered (11.9%)

Branch coverage included in aggregate %.

1559 of 9088 relevant lines covered (17.15%)

0.76 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.behavior.AttributeAppender;
10
import org.apache.wicket.markup.html.basic.Label;
11
import org.apache.wicket.markup.html.link.AbstractLink;
12
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
13
import org.apache.wicket.markup.html.panel.Panel;
14
import org.apache.wicket.markup.repeater.RepeatingView;
15
import org.apache.wicket.model.Model;
16
import org.apache.wicket.request.mapper.parameter.PageParameters;
17
import org.eclipse.rdf4j.model.IRI;
18
import org.nanopub.extra.services.ApiResponse;
19
import org.nanopub.extra.services.ApiResponseEntry;
20
import org.nanopub.extra.services.QueryRef;
21

22
import java.util.ArrayList;
23
import java.util.List;
24

25
public class QueryResultList extends Panel {
26

27
    private static final String SEPARATOR = ", ";
28
    private final List<AbstractLink> buttons = new ArrayList<>();
×
29
    private String contextId;
30
    private boolean finalized = false;
×
31
    private Space space;
32
    private final QueryRef queryRef;
33
    private final ViewDisplay viewDisplay;
34
    private final ApiResponse response;
35

36
    QueryResultList(String markupId, QueryRef queryRef, ApiResponse response, ViewDisplay viewDisplay) {
37
        super(markupId);
×
38
        this.queryRef = queryRef;
×
39
        this.viewDisplay = viewDisplay;
×
40
        this.response = response;
×
41

42
        add(new AttributeAppender("class", " col-" + viewDisplay.getDisplayWidth()));
×
43

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

56
    }
×
57

58
    public void addButton(String label, Class<? extends NanodashPage> pageClass, PageParameters parameters) {
59
        if (parameters == null) {
×
60
            parameters = new PageParameters();
×
61
        }
62
        if (contextId != null) {
×
63
            parameters.set("context", contextId);
×
64
        }
65
        AbstractLink button = new BookmarkablePageLink<NanodashPage>("button", pageClass, parameters);
×
66
        button.setBody(Model.of(label));
×
67
        buttons.add(button);
×
68
    }
×
69

70
    @Override
71
    protected void onBeforeRender() {
72
        if (!finalized) {
×
73
            if (!buttons.isEmpty()) {
×
74
                add(new ButtonList("buttons", space, buttons, null, null));
×
75
            } else {
76
                add(new Label("buttons").setVisible(false));
×
77
            }
78
            finalized = true;
×
79
        }
80
        super.onBeforeRender();
×
81
    }
×
82

83
    /**
84
     * Sets the space.
85
     *
86
     * @param space the space
87
     */
88
    public void setSpace(Space space) {
89
        this.space = space;
×
90
    }
×
91

92
    /**
93
     * Sets the context ID.
94
     *
95
     * @param contextId the context ID
96
     */
97
    public void setContextId(String contextId) {
98
        this.contextId = contextId;
×
99
    }
×
100

101
    /**
102
     * Populates the list with data from the API response.
103
     */
104
    protected void populateList() {
105
        RepeatingView listItems = new RepeatingView("listItems");
×
106
        for (ApiResponseEntry entry : response.getData()) {
×
107
            List<Component> components = new ArrayList<>();
×
108
            for (String key : response.getHeader()) {
×
109
                if (!key.endsWith("_label")) {
×
110
                    String entryValue = entry.get(key);
×
111
                    if (entryValue != null && !entryValue.isBlank()) {
×
112
                        if (entryValue.matches("https?://.+")) {
×
113
                            String entryLabel = entry.get(key + "_label");
×
114
                            components.add(new NanodashLink("component", entryValue, null, null, entryLabel, contextId));
×
115
                        } else {
×
116
                            if (Utils.looksLikeHtml(entryValue)) {
×
117
                                entryValue = Utils.sanitizeHtml(entryValue);
×
118
                            }
119
                            components.add(new Label("component", entryValue));
×
120
                        }
121
                    }
122
                }
123
            }
124
            ResourceView view = viewDisplay.getView();
×
125
            if (view != null && !view.getViewEntryActionList().isEmpty()) {
×
126
                List<AbstractLink> links = new ArrayList<>();
×
127
                for (IRI actionIri : view.getViewEntryActionList()) {
×
128
                    // TODO Copied code and adjusted from QueryResultTableBuilder:
129
                    Template t = view.getTemplateForAction(actionIri);
×
130
                    if (t == null) continue;
×
131
                    String targetField = view.getTemplateTargetFieldForAction(actionIri);
×
132
                    if (targetField == null) targetField = "resource";
×
133
                    String labelForAction = view.getLabelForAction(actionIri);
×
134
                    if (labelForAction == null) labelForAction = "action...";
×
135
                    PageParameters params = new PageParameters().set("template", t.getId()).set("param_" + targetField, contextId).set("context", contextId);
×
136
                    String partField = view.getTemplatePartFieldForAction(actionIri);
×
137
                    if (partField != null) {
×
138
                        // TODO Find a better way to pass the MaintainedResource object to this method:
139
                        MaintainedResource r = MaintainedResource.get(contextId);
×
140
                        if (r != null && r.getNamespace() != null) {
×
141
                            params.set("param_" + partField, r.getNamespace() + "<SET-SUFFIX>");
×
142
                        }
143
                    }
144
                    String queryMapping = view.getTemplateQueryMapping(actionIri);
×
145
                    if (queryMapping != null && queryMapping.contains(":")) {
×
146
                        // This part is different from the code in QueryResultTableBuilder:
147
                        String queryParam = queryMapping.split(":")[0];
×
148
                        String templateParam = queryMapping.split(":")[1];
×
149
                        params.set("param_" + templateParam, entry.get(queryParam));
×
150
                    }
151
                    params.set("refresh-upon-publish", queryRef.getAsUrlString());
×
152
                    AbstractLink button = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, params);
×
153
                    button.setBody(Model.of(labelForAction));
×
154
                    links.add(button);
×
155
                }
×
156
                components.add(new ButtonList("component", space, links, null, null));
×
157
            }
158
            ComponentSequence componentSequence = new ComponentSequence(listItems.newChildId(), SEPARATOR, components);
×
159
            listItems.add(componentSequence);
×
160
        }
×
161
        add(listItems);
×
162
    }
×
163

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