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

knowledgepixels / nanodash / 24382503285

14 Apr 2026 05:24AM UTC coverage: 15.886% (-0.2%) from 16.094%
24382503285

push

github

web-flow
Merge pull request #438 from knowledgepixels/feature/item-list-view-435

feat: implement ItemListView and fix async view rendering

789 of 6130 branches covered (12.87%)

Branch coverage included in aggregate %.

1978 of 11288 relevant lines covered (17.52%)

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

3
import com.knowledgepixels.nanodash.ApiCache;
4
import com.knowledgepixels.nanodash.View;
5
import com.knowledgepixels.nanodash.ViewDisplay;
6
import com.knowledgepixels.nanodash.domain.AbstractResourceWithProfile;
7
import com.knowledgepixels.nanodash.domain.MaintainedResource;
8
import com.knowledgepixels.nanodash.page.PublishPage;
9
import com.knowledgepixels.nanodash.repository.MaintainedResourceRepository;
10
import com.knowledgepixels.nanodash.template.Template;
11
import org.apache.wicket.Component;
12
import org.apache.wicket.behavior.AttributeAppender;
13
import org.apache.wicket.request.mapper.parameter.PageParameters;
14
import org.eclipse.rdf4j.model.IRI;
15
import org.nanopub.extra.services.ApiResponse;
16
import org.nanopub.extra.services.QueryRef;
17

18
import java.io.Serializable;
19

20
/**
21
 * Builder class for creating QueryResultTable components with various configurations.
22
 */
23
public class QueryResultTableBuilder implements Serializable {
24

25
    private String markupId;
26
    private boolean plain = false;
×
27
    private ViewDisplay viewDisplay;
28
    private String contextId = null;
×
29
    private QueryRef queryRef;
30
    private AbstractResourceWithProfile resourceWithProfile = null;
×
31
    private String id = null;
×
32

33
    private QueryResultTableBuilder(String markupId, QueryRef queryRef, ViewDisplay viewDisplay) {
×
34
        this.markupId = markupId;
×
35
        this.queryRef = queryRef;
×
36
        this.viewDisplay = viewDisplay;
×
37
    }
×
38

39
    /**
40
     * Creates a new QueryResultTableBuilder instance.
41
     *
42
     * @param markupId    the markup ID for the component
43
     * @param queryRef    the query reference
44
     * @param viewDisplay the view display object
45
     * @return a new QueryResultTableBuilder instance
46
     */
47
    public static QueryResultTableBuilder create(String markupId, QueryRef queryRef, ViewDisplay viewDisplay) {
48
        return new QueryResultTableBuilder(markupId, queryRef, viewDisplay);
×
49
    }
50

51
    /**
52
     * Sets the resource with profile for the QueryResultTable.
53
     *
54
     * @param resourceWithProfile the ResourceWithProfile object
55
     * @return the current QueryResultTableBuilder instance
56
     */
57
    public QueryResultTableBuilder resourceWithProfile(AbstractResourceWithProfile resourceWithProfile) {
58
        this.resourceWithProfile = resourceWithProfile;
×
59
        return this;
×
60
    }
61

62
    /**
63
     * Sets the ID for the QueryResultTable.
64
     *
65
     * @param id the ID string
66
     * @return the current QueryResultTableBuilder instance
67
     */
68
    public QueryResultTableBuilder id(String id) {
69
        this.id = id;
×
70
        return this;
×
71
    }
72

73
    /**
74
     * Sets whether the table should be plain.
75
     *
76
     * @param plain true for plain table, false otherwise
77
     * @return the current QueryResultTableBuilder instance
78
     */
79
    public QueryResultTableBuilder plain(boolean plain) {
80
        this.plain = plain;
×
81
        return this;
×
82
    }
83

84
    /**
85
     * Sets the context ID for the QueryResultTable.
86
     *
87
     * @param contextId the context ID string
88
     * @return the current QueryResultTableBuilder instance
89
     */
90
    public QueryResultTableBuilder contextId(String contextId) {
91
        this.contextId = contextId;
×
92
        return this;
×
93
    }
94

95
    /**
96
     * Builds the QueryResultTable component based on the configured parameters.
97
     *
98
     * @return the constructed Component
99
     */
100
    public Component build() {
101
        ApiResponse response = ApiCache.retrieveResponseAsync(queryRef);
×
102
        String colClass = " col-" + viewDisplay.getDisplayWidth();
×
103
        if (resourceWithProfile != null) {
×
104
            if (response != null) {
×
105
                QueryResultTable table = new QueryResultTable(markupId, queryRef, response, viewDisplay, false);
×
106
                table.setContextId(contextId);
×
107
                if (id != null && contextId != null && !id.equals(contextId)) {
×
108
                    table.setPartId(id);
×
109
                }
110
                table.setResourceWithProfile(resourceWithProfile);
×
111
                table.setPageResource(resourceWithProfile);
×
112
                View view = viewDisplay.getView();
×
113
                if (view != null) {
×
114
                    for (IRI actionIri : view.getViewResultActionList()) {
×
115
                        Template t = view.getTemplateForAction(actionIri);
×
116
                        if (t == null) continue;
×
117
                        String targetField = view.getTemplateTargetFieldForAction(actionIri);
×
118
                        if (targetField == null) targetField = "resource";
×
119
                        String label = view.getLabelForAction(actionIri);
×
120
                        if (label == null) label = "action...";
×
121
                        if (!label.endsWith("...")) label += "...";
×
122
                        PageParameters params = new PageParameters().set("template", t.getId())
×
123
                                .set("param_" + targetField, id)
×
124
                                .set("context", contextId)
×
125
                                .set("template-version", "latest");
×
126
                        if (id != null && contextId != null && !id.equals(contextId)) {
×
127
                            params.set("part", id);
×
128
                        }
129
                        String partField = view.getTemplatePartFieldForAction(actionIri);
×
130
                        if (partField != null) {
×
131
                            // TODO Find a better way to pass the MaintainedResource object to this method:
132
                            MaintainedResource r = MaintainedResourceRepository.get().findById(contextId);
×
133
                            if (r != null && r.getNamespace() != null) {
×
134
                                params.set("param_" + partField, r.getNamespace() + "<SET-SUFFIX>");
×
135
                            }
136
                        }
137
                        String queryMapping = view.getTemplateQueryMapping(actionIri);
×
138
                        if (queryMapping != null && queryMapping.contains(":")) {
×
139
                            params.set("values-from-query", queryRef.getAsUrlString());
×
140
                            params.set("values-from-query-mapping", queryMapping);
×
141
                        }
142
                        params.set("refresh-upon-publish", queryRef.getAsUrlString());
×
143
                        table.addButton(label, PublishPage.class, params);
×
144
                    }
×
145
                }
146
                table.add(new AttributeAppender("class", colClass));
×
147
                return table;
×
148
            } else {
149
                ApiResultComponent comp = new ApiResultComponent(markupId, queryRef) {
×
150
                    @Override
151
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
152
                        QueryResultTable table = new QueryResultTable(markupId, queryRef, response, viewDisplay, false);
×
153
                        table.setContextId(contextId);
×
154
                        if (id != null && contextId != null && !id.equals(contextId)) {
×
155
                            table.setPartId(id);
×
156
                        }
157
                        table.setResourceWithProfile(resourceWithProfile);
×
158
                        table.setPageResource(resourceWithProfile);
×
159
                        View view = viewDisplay.getView();
×
160
                        if (view != null) {
×
161
                            for (IRI actionIri : view.getViewResultActionList()) {
×
162
                                Template t = view.getTemplateForAction(actionIri);
×
163
                                if (t == null) continue;
×
164
                                String targetField = view.getTemplateTargetFieldForAction(actionIri);
×
165
                                if (targetField == null) targetField = "resource";
×
166
                                String label = view.getLabelForAction(actionIri);
×
167
                                if (label == null) label = "action...";
×
168
                                PageParameters params = new PageParameters().set("template", t.getId())
×
169
                                        .set("param_" + targetField, id)
×
170
                                        .set("context", contextId)
×
171
                                        .set("template-version", "latest");
×
172
                                if (id != null && contextId != null && !id.equals(contextId)) {
×
173
                                    params.set("part", id);
×
174
                                }
175
                                String partField = view.getTemplatePartFieldForAction(actionIri);
×
176
                                if (partField != null) {
×
177
                                    // TODO Find a better way to pass the MaintainedResource object to this method:
178
                                    MaintainedResource r = MaintainedResourceRepository.get().findById(contextId);
×
179
                                    if (r != null && r.getNamespace() != null) {
×
180
                                        params.set("param_" + partField, r.getNamespace() + "<SET-SUFFIX>");
×
181
                                    }
182
                                }
183
                                String queryMapping = view.getTemplateQueryMapping(actionIri);
×
184
                                if (queryMapping != null && queryMapping.contains(":")) {
×
185
                                    params.set("values-from-query", queryRef.getAsUrlString());
×
186
                                    params.set("values-from-query-mapping", queryMapping);
×
187
                                }
188
                                params.set("refresh-upon-publish", queryRef.getAsUrlString());
×
189
                                table.addButton(label, PublishPage.class, params);
×
190
                            }
×
191
                        }
192
                        return table;
×
193
                    }
194
                };
195
                comp.add(new AttributeAppender("class", colClass));
×
196
                return comp;
×
197
            }
198
        } else {
199
            if (response != null) {
×
200
                QueryResultTable table = new QueryResultTable(markupId, queryRef, response, viewDisplay, plain);
×
201
                table.setContextId(contextId);
×
202
                table.add(new AttributeAppender("class", colClass));
×
203
                return table;
×
204
            } else {
205
                ApiResultComponent comp = new ApiResultComponent(markupId, queryRef) {
×
206
                    @Override
207
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
208
                        QueryResultTable table = new QueryResultTable(markupId, queryRef, response, viewDisplay, plain);
×
209
                        table.setContextId(contextId);
×
210
                        return table;
×
211
                    }
212
                };
213
                comp.add(new AttributeAppender("class", colClass));
×
214
                return comp;
×
215
            }
216
        }
217
    }
218

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