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

knowledgepixels / nanodash / 27126000317

08 Jun 2026 08:41AM UTC coverage: 20.384% (-0.5%) from 20.924%
27126000317

Pull #479

github

web-flow
Merge 2ab36e873 into 5556185a4
Pull Request #479: About pages for spaces, maintained resources, and users (#478)

1004 of 6333 branches covered (15.85%)

Branch coverage included in aggregate %.

2603 of 11362 relevant lines covered (22.91%)

3.28 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
                addViewActions(table, viewDisplay, queryRef, id, contextId);
×
113
                table.add(new AttributeAppender("class", colClass));
×
114
                return table;
×
115
            } else {
116
                ApiResultComponent comp = new ApiResultComponent(markupId, queryRef) {
×
117
                    @Override
118
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
119
                        QueryResultTable table = new QueryResultTable(markupId, queryRef, response, viewDisplay, false);
×
120
                        table.setContextId(contextId);
×
121
                        if (id != null && contextId != null && !id.equals(contextId)) {
×
122
                            table.setPartId(id);
×
123
                        }
124
                        table.setResourceWithProfile(resourceWithProfile);
×
125
                        table.setPageResource(resourceWithProfile);
×
126
                        addViewActions(table, viewDisplay, queryRef, id, contextId);
×
127
                        return table;
×
128
                    }
129
                };
130
                comp.add(new AttributeAppender("class", colClass));
×
131
                return comp;
×
132
            }
133
        } else {
134
            if (response != null) {
×
135
                QueryResultTable table = new QueryResultTable(markupId, queryRef, response, viewDisplay, plain);
×
136
                table.setContextId(contextId);
×
137
                addViewActions(table, viewDisplay, queryRef, id, contextId);
×
138
                table.add(new AttributeAppender("class", colClass));
×
139
                return table;
×
140
            } else {
141
                ApiResultComponent comp = new ApiResultComponent(markupId, queryRef) {
×
142
                    @Override
143
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
144
                        QueryResultTable table = new QueryResultTable(markupId, queryRef, response, viewDisplay, plain);
×
145
                        table.setContextId(contextId);
×
146
                        addViewActions(table, viewDisplay, queryRef, id, contextId);
×
147
                        return table;
×
148
                    }
149
                };
150
                comp.add(new AttributeAppender("class", colClass));
×
151
                return comp;
×
152
            }
153
        }
154
    }
155

156
    /**
157
     * Adds a button to the table for each result action declared by the view, linking to the
158
     * action's template on the publish page. Resource-context parameters (the target field, the
159
     * context, the part, and the part field) are only set when the corresponding id/contextId is
160
     * available, so this also works on resource-less listings such as the general Spaces page.
161
     *
162
     * @param table       the table to add the action buttons to
163
     * @param viewDisplay the view display whose view declares the actions
164
     * @param queryRef    the query reference backing the table (used for refresh and query mapping)
165
     * @param id          the resource id, or null if there is no specific resource in context
166
     * @param contextId   the context id, or null if there is no context
167
     */
168
    private static void addViewActions(QueryResultTable table, ViewDisplay viewDisplay, QueryRef queryRef, String id, String contextId) {
169
        View view = viewDisplay.getView();
×
170
        if (view == null) return;
×
171
        for (IRI actionIri : view.getViewResultActionList()) {
×
172
            Template t = view.getTemplateForAction(actionIri);
×
173
            if (t == null) continue;
×
174
            String targetField = view.getTemplateTargetFieldForAction(actionIri);
×
175
            if (targetField == null) targetField = "resource";
×
176
            String label = view.getLabelForAction(actionIri);
×
177
            if (label == null) label = "action...";
×
178
            if (!label.endsWith("...")) label += "...";
×
179
            PageParameters params = new PageParameters().set("template", t.getId())
×
180
                    .set("template-version", "latest");
×
181
            if (id != null) params.set("param_" + targetField, id);
×
182
            if (contextId != null) params.set("context", contextId);
×
183
            if (id != null && contextId != null && !id.equals(contextId)) {
×
184
                params.set("part", id);
×
185
            }
186
            String partField = view.getTemplatePartFieldForAction(actionIri);
×
187
            if (partField != null && contextId != null) {
×
188
                // TODO Find a better way to pass the MaintainedResource object to this method:
189
                MaintainedResource r = MaintainedResourceRepository.get().findById(contextId);
×
190
                if (r != null && r.getNamespace() != null) {
×
191
                    params.set("param_" + partField, r.getNamespace() + "<SET-SUFFIX>");
×
192
                }
193
            }
194
            String queryMapping = view.getTemplateQueryMapping(actionIri);
×
195
            if (queryMapping != null && queryMapping.contains(":")) {
×
196
                params.set("values-from-query", queryRef.getAsUrlString());
×
197
                params.set("values-from-query-mapping", queryMapping);
×
198
            }
199
            params.set("refresh-upon-publish", queryRef.getAsUrlString());
×
200
            table.addButton(label, PublishPage.class, params);
×
201
        }
×
202
    }
×
203

204
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc