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

knowledgepixels / nanodash / 23046278881

13 Mar 2026 10:15AM UTC coverage: 15.676% (-0.06%) from 15.734%
23046278881

push

github

web-flow
Merge pull request #388 from knowledgepixels/387-improve-user-page-buttons

Improve user page buttons (#387)

710 of 5489 branches covered (12.93%)

Branch coverage included in aggregate %.

1751 of 10210 relevant lines covered (17.15%)

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

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