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

knowledgepixels / nanodash / 22618039211

03 Mar 2026 10:05AM UTC coverage: 16.058% (+0.2%) from 15.884%
22618039211

Pull #365

github

web-flow
Merge 1e7e700f0 into a8c4b4a77
Pull Request #365: Refactor of `ResourceWithProfile` and related classes

699 of 5287 branches covered (13.22%)

Branch coverage included in aggregate %.

1721 of 9783 relevant lines covered (17.59%)

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

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