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

knowledgepixels / nanodash / 27622721129

16 Jun 2026 01:55PM UTC coverage: 26.963% (+6.3%) from 20.697%
27622721129

Pull #483

github

web-flow
Merge 73a4d0fe1 into 663f14f46
Pull Request #483: Space/resource About pages, ref-aware spaces, and magic query params

1542 of 6717 branches covered (22.96%)

Branch coverage included in aggregate %.

3407 of 11638 relevant lines covered (29.27%)

4.31 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.SpaceMemberRole;
5
import com.knowledgepixels.nanodash.View;
6
import com.knowledgepixels.nanodash.ViewDisplay;
7
import com.knowledgepixels.nanodash.domain.AbstractResourceWithProfile;
8
import com.knowledgepixels.nanodash.domain.MaintainedResource;
9
import com.knowledgepixels.nanodash.domain.Space;
10
import com.knowledgepixels.nanodash.page.PublishPage;
11
import com.knowledgepixels.nanodash.repository.MaintainedResourceRepository;
12
import com.knowledgepixels.nanodash.template.Template;
13
import org.apache.wicket.Component;
14
import org.apache.wicket.behavior.AttributeAppender;
15
import org.apache.wicket.request.mapper.parameter.PageParameters;
16
import org.eclipse.rdf4j.model.IRI;
17
import org.nanopub.extra.services.ApiResponse;
18
import org.nanopub.extra.services.QueryRef;
19

20
import java.io.Serializable;
21

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

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

36
    private QueryResultTableBuilder(String markupId, QueryRef queryRef, ViewDisplay viewDisplay) {
×
37
        this.markupId = markupId;
×
38
        // Bind session-derived "magic" query parameters here on the request thread
39
        // (ApiCache fetches on background threads where the session is absent).
40
        this.queryRef = com.knowledgepixels.nanodash.MagicQueryParams.augment(queryRef);
×
41
        this.viewDisplay = viewDisplay;
×
42
    }
×
43

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

56
    /**
57
     * Sets the resource with profile for the QueryResultTable.
58
     *
59
     * @param resourceWithProfile the ResourceWithProfile object
60
     * @return the current QueryResultTableBuilder instance
61
     */
62
    public QueryResultTableBuilder resourceWithProfile(AbstractResourceWithProfile resourceWithProfile) {
63
        this.resourceWithProfile = resourceWithProfile;
×
64
        return this;
×
65
    }
66

67
    /**
68
     * Sets the ID for the QueryResultTable.
69
     *
70
     * @param id the ID string
71
     * @return the current QueryResultTableBuilder instance
72
     */
73
    public QueryResultTableBuilder id(String id) {
74
        this.id = id;
×
75
        return this;
×
76
    }
77

78
    /**
79
     * Sets whether the table should be plain.
80
     *
81
     * @param plain true for plain table, false otherwise
82
     * @return the current QueryResultTableBuilder instance
83
     */
84
    public QueryResultTableBuilder plain(boolean plain) {
85
        this.plain = plain;
×
86
        return this;
×
87
    }
88

89
    /**
90
     * Sets the context ID for the QueryResultTable.
91
     *
92
     * @param contextId the context ID string
93
     * @return the current QueryResultTableBuilder instance
94
     */
95
    public QueryResultTableBuilder contextId(String contextId) {
96
        this.contextId = contextId;
×
97
        return this;
×
98
    }
99

100
    /**
101
     * Sets the tab to return to after publishing via one of the table's action
102
     * buttons (so the user stays on, e.g., the About tab).
103
     *
104
     * @param postPublishTab the tab name, or null for the default
105
     * @return the current QueryResultTableBuilder instance
106
     */
107
    public QueryResultTableBuilder postPublishTab(String postPublishTab) {
108
        this.postPublishTab = postPublishTab;
×
109
        return this;
×
110
    }
111

112
    /**
113
     * Builds the QueryResultTable component based on the configured parameters.
114
     *
115
     * @return the constructed Component
116
     */
117
    public Component build() {
118
        ApiResponse response = ApiCache.retrieveResponseAsync(queryRef);
×
119
        String colClass = " col-" + viewDisplay.getDisplayWidth();
×
120
        if (resourceWithProfile != null) {
×
121
            if (response != null) {
×
122
                QueryResultTable table = new QueryResultTable(markupId, queryRef, response, viewDisplay, false);
×
123
                table.setContextId(contextId);
×
124
                table.setPostPublishTab(postPublishTab);
×
125
                if (id != null && contextId != null && !id.equals(contextId)) {
×
126
                    table.setPartId(id);
×
127
                }
128
                table.setResourceWithProfile(resourceWithProfile);
×
129
                table.setPageResource(resourceWithProfile);
×
130
                addViewActions(table, viewDisplay, queryRef, id, contextId, resourceWithProfile);
×
131
                table.add(new AttributeAppender("class", colClass));
×
132
                return table;
×
133
            } else {
134
                ApiResultComponent comp = new ApiResultComponent(markupId, queryRef) {
×
135
                    @Override
136
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
137
                        QueryResultTable table = new QueryResultTable(markupId, queryRef, response, viewDisplay, false);
×
138
                        table.setContextId(contextId);
×
139
                        table.setPostPublishTab(postPublishTab);
×
140
                        if (id != null && contextId != null && !id.equals(contextId)) {
×
141
                            table.setPartId(id);
×
142
                        }
143
                        table.setResourceWithProfile(resourceWithProfile);
×
144
                        table.setPageResource(resourceWithProfile);
×
145
                        addViewActions(table, viewDisplay, queryRef, id, contextId, resourceWithProfile);
×
146
                        return table;
×
147
                    }
148
                };
149
                comp.add(new AttributeAppender("class", colClass));
×
150
                return comp;
×
151
            }
152
        } else {
153
            if (response != null) {
×
154
                QueryResultTable table = new QueryResultTable(markupId, queryRef, response, viewDisplay, plain);
×
155
                table.setContextId(contextId);
×
156
                table.setPostPublishTab(postPublishTab);
×
157
                addViewActions(table, viewDisplay, queryRef, id, contextId, resourceWithProfile);
×
158
                table.add(new AttributeAppender("class", colClass));
×
159
                return table;
×
160
            } else {
161
                ApiResultComponent comp = new ApiResultComponent(markupId, queryRef) {
×
162
                    @Override
163
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
164
                        QueryResultTable table = new QueryResultTable(markupId, queryRef, response, viewDisplay, plain);
×
165
                        table.setContextId(contextId);
×
166
                        table.setPostPublishTab(postPublishTab);
×
167
                        addViewActions(table, viewDisplay, queryRef, id, contextId, resourceWithProfile);
×
168
                        return table;
×
169
                    }
170
                };
171
                comp.add(new AttributeAppender("class", colClass));
×
172
                return comp;
×
173
            }
174
        }
175
    }
176

177
    /**
178
     * Adds a button to the table for each result action declared by the view, linking to the
179
     * action's template on the publish page. Resource-context parameters (the target field, the
180
     * context, the part, and the part field) are only set when the corresponding id/contextId is
181
     * available, so this also works on resource-less listings such as the general Spaces page.
182
     *
183
     * @param table       the table to add the action buttons to
184
     * @param viewDisplay the view display whose view declares the actions
185
     * @param queryRef    the query reference backing the table (used for refresh and query mapping)
186
     * @param id          the resource id, or null if there is no specific resource in context
187
     * @param contextId   the context id, or null if there is no context
188
     */
189
    private static void addViewActions(QueryResultTable table, ViewDisplay viewDisplay, QueryRef queryRef, String id, String contextId, AbstractResourceWithProfile resourceWithProfile) {
190
        View view = viewDisplay.getView();
×
191
        if (view == null) return;
×
192
        for (IRI actionIri : view.getViewResultActionList()) {
×
193
            // Per-action role gating (docs/role-specific-views.md): skip an action
194
            // whose gen:isVisibleTo the current viewer does not satisfy. Additive —
195
            // actions without gen:isVisibleTo are unaffected.
196
            if (!SpaceMemberRole.isViewerEntitled(view.getActionVisibleTo(actionIri), resourceWithProfile)) continue;
×
197
            Template t = view.getTemplateForAction(actionIri);
×
198
            if (t == null) continue;
×
199
            String targetField = view.getTemplateTargetFieldForAction(actionIri);
×
200
            if (targetField == null) targetField = "resource";
×
201
            String label = view.getLabelForAction(actionIri);
×
202
            if (label == null) label = "action...";
×
203
            if (!label.endsWith("...")) label += "...";
×
204
            PageParameters params = new PageParameters().set("template", t.getId())
×
205
                    .set("template-version", "latest");
×
206
            if (id != null) params.set("param_" + targetField, id);
×
207
            if (contextId != null) params.set("context", contextId);
×
208
            if (id != null && contextId != null && !id.equals(contextId)) {
×
209
                params.set("part", id);
×
210
            }
211
            String partField = view.getTemplatePartFieldForAction(actionIri);
×
212
            if (partField != null && contextId != null) {
×
213
                // The part field pre-fills a namespaced child IRI (the user fills the suffix).
214
                // TODO Find a better way to pass the MaintainedResource object to this method:
215
                MaintainedResource r = MaintainedResourceRepository.get().findById(contextId);
×
216
                String namespace = null;
×
217
                if (r != null) {
×
218
                    namespace = r.getNamespace();
×
219
                } else if (resourceWithProfile instanceof Space) {
×
220
                    // The Space-creation templates' `space` placeholder has a fixed
221
                    // `https://w3id.org/spaces/` prefix, so the pre-fill is relative to it.
222
                    // Nesting the new space's IRI under this space's path makes it a
223
                    // sub-space via the prefix match.
224
                    namespace = contextId.replaceFirst("https://w3id.org/spaces/", "") + "/";
×
225
                }
226
                if (namespace != null) {
×
227
                    params.set("param_" + partField, namespace + "<SET-SUFFIX>");
×
228
                }
229
            }
230
            String queryMapping = view.getTemplateQueryMapping(actionIri);
×
231
            if (queryMapping != null && queryMapping.contains(":")) {
×
232
                params.set("values-from-query", queryRef.getAsUrlString());
×
233
                params.set("values-from-query-mapping", queryMapping);
×
234
            }
235
            params.set("refresh-upon-publish", queryRef.getAsUrlString());
×
236
            if (table.getPostPublishTab() != null) params.set("postpub-tab", table.getPostPublishTab());
×
237
            table.addButton(label, PublishPage.class, params);
×
238
        }
×
239
    }
×
240

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