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

knowledgepixels / nanodash / 20264440287

16 Dec 2025 10:18AM UTC coverage: 15.358% (-0.1%) from 15.457%
20264440287

push

github

tkuhn
feat: Make use of template-version=latest in more places

593 of 4976 branches covered (11.92%)

Branch coverage included in aggregate %.

1571 of 9114 relevant lines covered (17.24%)

2.22 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.*;
4
import com.knowledgepixels.nanodash.page.PublishPage;
5
import com.knowledgepixels.nanodash.template.Template;
6
import org.apache.wicket.Component;
7
import org.apache.wicket.request.mapper.parameter.PageParameters;
8
import org.eclipse.rdf4j.model.IRI;
9
import org.nanopub.extra.services.ApiResponse;
10
import org.nanopub.extra.services.QueryRef;
11

12
import java.io.Serializable;
13

14
/**
15
 * Builder class for creating QueryResultTable components with various configurations.
16
 */
17
public class QueryResultTableBuilder implements Serializable {
18

19
    private String markupId;
20
    private boolean plain = false;
×
21
    private ViewDisplay viewDisplay;
22
    private String contextId = null;
×
23
    private QueryRef queryRef;
24
    private ProfiledResource profiledResource = null;
×
25
    private String id = null;
×
26

27
    private QueryResultTableBuilder(String markupId, QueryRef queryRef, ViewDisplay viewDisplay) {
×
28
        this.markupId = markupId;
×
29
        this.queryRef = queryRef;
×
30
        this.viewDisplay = viewDisplay;
×
31
    }
×
32

33
    /**
34
     * Creates a new QueryResultTableBuilder instance.
35
     *
36
     * @param markupId    the markup ID for the component
37
     * @param queryRef    the query reference
38
     * @param viewDisplay the view display object
39
     * @return a new QueryResultTableBuilder instance
40
     */
41
    public static QueryResultTableBuilder create(String markupId, QueryRef queryRef, ViewDisplay viewDisplay) {
42
        return new QueryResultTableBuilder(markupId, queryRef, viewDisplay);
×
43
    }
44

45
    /**
46
     * Sets the profiled resource for the QueryResultTable.
47
     *
48
     * @param profiledResource the profiled resource object
49
     * @return the current QueryResultTableBuilder instance
50
     */
51
    public QueryResultTableBuilder profiledResource(ProfiledResource profiledResource) {
52
        this.profiledResource = profiledResource;
×
53
        return this;
×
54
    }
55

56
    /**
57
     * Sets the ID for the QueryResultTable.
58
     *
59
     * @param id the ID string
60
     * @return the current QueryResultTableBuilder instance
61
     */
62
    public QueryResultTableBuilder id(String id) {
63
        this.id = id;
×
64
        return this;
×
65
    }
66

67
    /**
68
     * Sets whether the table should be plain.
69
     *
70
     * @param plain true for plain table, false otherwise
71
     * @return the current QueryResultTableBuilder instance
72
     */
73
    public QueryResultTableBuilder plain(boolean plain) {
74
        this.plain = plain;
×
75
        return this;
×
76
    }
77

78
    /**
79
     * Sets the context ID for the QueryResultTable.
80
     *
81
     * @param contextId the context ID string
82
     * @return the current QueryResultTableBuilder instance
83
     */
84
    public QueryResultTableBuilder contextId(String contextId) {
85
        this.contextId = contextId;
×
86
        return this;
×
87
    }
88

89
    /**
90
     * Builds the QueryResultTable component based on the configured parameters.
91
     *
92
     * @return the constructed Component
93
     */
94
    public Component build() {
95
        ApiResponse response = ApiCache.retrieveResponse(queryRef);
×
96
        if (profiledResource != null) {
×
97
            if (response != null) {
×
98
                QueryResultTable table = new QueryResultTable(markupId, queryRef, response, viewDisplay, false);
×
99
                table.setContextId(contextId);
×
100
                table.setProfiledResource(profiledResource);
×
101
                ResourceView view = viewDisplay.getView();
×
102
                if (view != null) {
×
103
                    for (IRI actionIri : view.getViewResultActionList()) {
×
104
                        Template t = view.getTemplateForAction(actionIri);
×
105
                        if (t == null) continue;
×
106
                        String targetField = view.getTemplateTargetFieldForAction(actionIri);
×
107
                        if (targetField == null) targetField = "resource";
×
108
                        String label = view.getLabelForAction(actionIri);
×
109
                        if (label == null) label = "action...";
×
110
                        PageParameters params = new PageParameters().set("template", t.getId())
×
111
                                .set("param_" + targetField, id)
×
112
                                .set("context", contextId)
×
113
                                .set("template-version", "latest");
×
114
                        String partField = view.getTemplatePartFieldForAction(actionIri);
×
115
                        if (partField != null) {
×
116
                            // TODO Find a better way to pass the MaintainedResource object to this method:
117
                            MaintainedResource r = MaintainedResource.get(contextId);
×
118
                            if (r != null && r.getNamespace() != null) {
×
119
                                params.set("param_" + partField, r.getNamespace() + "<SET-SUFFIX>");
×
120
                            }
121
                        }
122
                        String queryMapping = view.getTemplateQueryMapping(actionIri);
×
123
                        if (queryMapping != null && queryMapping.contains(":")) {
×
124
                            params.set("values-from-query", queryRef.getAsUrlString());
×
125
                            params.set("values-from-query-mapping", queryMapping);
×
126
                        }
127
                        params.set("refresh-upon-publish", queryRef.getAsUrlString());
×
128
                        table.addButton(label, PublishPage.class, params);
×
129
                    }
×
130
                }
131
                return table;
×
132
            } else {
133
                return new ApiResultComponent(markupId, queryRef) {
×
134
                    @Override
135
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
136
                        QueryResultTable table = new QueryResultTable(markupId, queryRef, response, viewDisplay, false);
×
137
                        table.setContextId(contextId);
×
138
                        table.setProfiledResource(profiledResource);
×
139
                        ResourceView view = viewDisplay.getView();
×
140
                        if (view != null) {
×
141
                            for (IRI actionIri : view.getViewResultActionList()) {
×
142
                                Template t = view.getTemplateForAction(actionIri);
×
143
                                if (t == null) continue;
×
144
                                String targetField = view.getTemplateTargetFieldForAction(actionIri);
×
145
                                if (targetField == null) targetField = "resource";
×
146
                                String label = view.getLabelForAction(actionIri);
×
147
                                if (label == null) label = "action...";
×
148
                                PageParameters params = new PageParameters().set("template", t.getId())
×
149
                                        .set("param_" + targetField, id)
×
150
                                        .set("context", contextId)
×
151
                                        .set("template-version", "latest");
×
152
                                String partField = view.getTemplatePartFieldForAction(actionIri);
×
153
                                if (partField != null) {
×
154
                                    // TODO Find a better way to pass the MaintainedResource object to this method:
155
                                    MaintainedResource r = MaintainedResource.get(contextId);
×
156
                                    if (r != null && r.getNamespace() != null) {
×
157
                                        params.set("param_" + partField, r.getNamespace() + "<SET-SUFFIX>");
×
158
                                    }
159
                                }
160
                                String queryMapping = view.getTemplateQueryMapping(actionIri);
×
161
                                if (queryMapping != null && queryMapping.contains(":")) {
×
162
                                    params.set("values-from-query", queryRef.getAsUrlString());
×
163
                                    params.set("values-from-query-mapping", queryMapping);
×
164
                                }
165
                                params.set("refresh-upon-publish", queryRef.getAsUrlString());
×
166
                                table.addButton(label, PublishPage.class, params);
×
167
                            }
×
168
                        }
169
                        return table;
×
170
                    }
171
                };
172
            }
173
        } else {
174
            if (response != null) {
×
175
                QueryResultTable table = new QueryResultTable(markupId, queryRef, response, viewDisplay, plain);
×
176
                table.setContextId(contextId);
×
177
                return table;
×
178
            } else {
179
                return new ApiResultComponent(markupId, queryRef) {
×
180
                    @Override
181
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
182
                        QueryResultTable table = new QueryResultTable(markupId, queryRef, response, viewDisplay, plain);
×
183
                        table.setContextId(contextId);
×
184
                        return table;
×
185
                    }
186
                };
187
            }
188
        }
189
    }
190

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