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

knowledgepixels / nanodash / 22630596072

03 Mar 2026 03:41PM UTC coverage: 15.949% (-0.08%) from 16.03%
22630596072

Pull #369

github

web-flow
Merge 6951bc4cf into 85e0af2dc
Pull Request #369: Replace "^" for view displays with dropdown menu

699 of 5317 branches covered (13.15%)

Branch coverage included in aggregate %.

1721 of 9856 relevant lines covered (17.46%)

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.domain.MaintainedResource;
5
import com.knowledgepixels.nanodash.View;
6
import com.knowledgepixels.nanodash.ViewDisplay;
7
import com.knowledgepixels.nanodash.domain.AbstractResourceWithProfile;
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.request.mapper.parameter.PageParameters;
13
import org.eclipse.rdf4j.model.IRI;
14
import org.nanopub.extra.services.ApiResponse;
15
import org.nanopub.extra.services.QueryRef;
16

17
import java.io.Serializable;
18

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

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

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

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

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

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

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

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

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

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