• 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/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, false, viewDisplay);
×
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()).set("param_" + targetField, id).set("context", contextId);
×
111
                        String partField = view.getTemplatePartFieldForAction(actionIri);
×
112
                        if (partField != null) {
×
113
                            // TODO Find a better way to pass the MaintainedResource object to this method:
114
                            MaintainedResource r = MaintainedResource.get(contextId);
×
115
                            if (r != null && r.getNamespace() != null) {
×
116
                                params.set("param_" + partField, r.getNamespace() + "<SET-SUFFIX>");
×
117
                            }
118
                        }
119
                        String queryMapping = view.getTemplateQueryMapping(actionIri);
×
120
                        if (queryMapping != null && queryMapping.contains(":")) {
×
121
                            params.set("values-from-query", queryRef.getAsUrlString());
×
122
                            params.set("values-from-query-mapping", queryMapping);
×
123
                        }
124
                        params.set("refresh-upon-publish", queryRef.getAsUrlString());
×
125
                        table.addButton(label, PublishPage.class, params);
×
126
                    }
×
127
                }
128
                return table;
×
129
            } else {
130
                return new ApiResultComponent(markupId, queryRef) {
×
131
                    @Override
132
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
133
                        QueryResultTable table = new QueryResultTable(markupId, queryRef, response, false, viewDisplay);
×
134
                        table.setContextId(contextId);
×
135
                        table.setProfiledResource(profiledResource);
×
136
                        ResourceView view = viewDisplay.getView();
×
137
                        if (view != null) {
×
138
                            for (IRI actionIri : view.getViewResultActionList()) {
×
139
                                Template t = view.getTemplateForAction(actionIri);
×
140
                                if (t == null) continue;
×
141
                                String targetField = view.getTemplateTargetFieldForAction(actionIri);
×
142
                                if (targetField == null) targetField = "resource";
×
143
                                String label = view.getLabelForAction(actionIri);
×
144
                                if (label == null) label = "action...";
×
145
                                PageParameters params = new PageParameters().set("template", t.getId()).set("param_" + targetField, id).set("context", contextId);
×
146
                                String partField = view.getTemplatePartFieldForAction(actionIri);
×
147
                                if (partField != null) {
×
148
                                    // TODO Find a better way to pass the MaintainedResource object to this method:
149
                                    MaintainedResource r = MaintainedResource.get(contextId);
×
150
                                    if (r != null && r.getNamespace() != null) {
×
151
                                        params.set("param_" + partField, r.getNamespace() + "<SET-SUFFIX>");
×
152
                                    }
153
                                }
154
                                String queryMapping = view.getTemplateQueryMapping(actionIri);
×
155
                                if (queryMapping != null && queryMapping.contains(":")) {
×
156
                                    params.set("values-from-query", queryRef.getAsUrlString());
×
157
                                    params.set("values-from-query-mapping", queryMapping);
×
158
                                }
159
                                params.set("refresh-upon-publish", queryRef.getAsUrlString());
×
160
                                table.addButton(label, PublishPage.class, params);
×
161
                            }
×
162
                        }
163
                        return table;
×
164
                    }
165
                };
166
            }
167
        } else {
168
            if (response != null) {
×
169
                QueryResultTable table = new QueryResultTable(markupId, queryRef, response, plain, viewDisplay);
×
170
                table.setContextId(contextId);
×
171
                return table;
×
172
            } else {
173
                return new ApiResultComponent(markupId, queryRef) {
×
174
                    @Override
175
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
176
                        QueryResultTable table = new QueryResultTable(markupId, queryRef, response, plain, viewDisplay);
×
177
                        table.setContextId(contextId);
×
178
                        return table;
×
179
                    }
180
                };
181
            }
182
        }
183
    }
184

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