• 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/QueryResultListBuilder.java
1
package com.knowledgepixels.nanodash.component;
2

3
import com.knowledgepixels.nanodash.*;
4
import com.knowledgepixels.nanodash.domain.AbstractResourceWithProfile;
5
import com.knowledgepixels.nanodash.domain.MaintainedResource;
6
import com.knowledgepixels.nanodash.domain.Space;
7
import com.knowledgepixels.nanodash.page.PublishPage;
8
import com.knowledgepixels.nanodash.repository.MaintainedResourceRepository;
9
import com.knowledgepixels.nanodash.template.Template;
10
import org.apache.wicket.Component;
11
import org.apache.wicket.request.mapper.parameter.PageParameters;
12
import org.eclipse.rdf4j.model.IRI;
13
import org.nanopub.extra.services.ApiResponse;
14
import org.nanopub.extra.services.QueryRef;
15

16
import java.io.Serializable;
17

18
/**
19
 * Builder class for creating QueryResultList components.
20
 */
21
public class QueryResultListBuilder implements Serializable {
22

23
    private String markupId;
24
    private ViewDisplay viewDisplay;
25
    private String contextId = null;
×
26
    private QueryRef queryRef;
27
    private Space space = null;
×
28
    private String id = null;
×
29
    private AbstractResourceWithProfile pageResource = null;
×
30

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

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

49
    public QueryResultListBuilder space(Space space) {
50
        this.space = space;
×
51
        return this;
×
52
    }
53

54
    /**
55
     * Sets the context ID for the QueryResultList.
56
     *
57
     * @param contextId the context ID
58
     * @return the current QueryResultListBuilder instance
59
     */
60
    public QueryResultListBuilder contextId(String contextId) {
61
        this.contextId = contextId;
×
62
        return this;
×
63
    }
64

65
    public QueryResultListBuilder id(String id) {
66
        this.id = id;
×
67
        return this;
×
68
    }
69

70
    public QueryResultListBuilder pageResource(AbstractResourceWithProfile pageResource) {
71
        this.pageResource = pageResource;
×
72
        return this;
×
73
    }
74

75
    /**
76
     * Builds the QueryResultList component.
77
     *
78
     * @return the QueryResultList component
79
     */
80
    public Component build() {
81
        ApiResponse response = ApiCache.retrieveResponseAsync(queryRef);
×
82
        if (space != null) {
×
83
            if (response != null) {
×
84
                QueryResultList resultList = new QueryResultList(markupId, queryRef, response, viewDisplay);
×
85
                resultList.setProfiledResource(space);
×
86
                resultList.setPageResource(pageResource);
×
87
                resultList.setContextId(contextId);
×
88
                View view = viewDisplay.getView();
×
89
                if (view != null) {
×
90
                    for (IRI actionIri : view.getViewResultActionList()) {
×
91
                        Template t = view.getTemplateForAction(actionIri);
×
92
                        if (t == null) continue;
×
93
                        String targetField = view.getTemplateTargetFieldForAction(actionIri);
×
94
                        if (targetField == null) targetField = "resource";
×
95
                        String label = view.getLabelForAction(actionIri);
×
96
                        if (label == null) label = "action...";
×
97
                        PageParameters params = new PageParameters().set("template", t.getId())
×
98
                                .set("param_" + targetField, id)
×
99
                                .set("context", contextId)
×
100
                                .set("template-version", "latest");
×
101
                        if (id != null && contextId != null && !id.equals(contextId)) {
×
102
                            params.set("part", id);
×
103
                        }
104
                        String partField = view.getTemplatePartFieldForAction(actionIri);
×
105
                        if (partField != null) {
×
106
                            // TODO Find a better way to pass the MaintainedResource object to this method:
107
                            MaintainedResource r = MaintainedResourceRepository.get().findById(contextId);
×
108
                            if (r != null && r.getNamespace() != null) {
×
109
                                params.set("param_" + partField, r.getNamespace() + "<SET-SUFFIX>");
×
110
                            }
111
                        }
112
                        String queryMapping = view.getTemplateQueryMapping(actionIri);
×
113
                        if (queryMapping != null && queryMapping.contains(":")) {
×
114
                            params.set("values-from-query", queryRef.getAsUrlString());
×
115
                            params.set("values-from-query-mapping", queryMapping);
×
116
                        }
117
                        params.set("refresh-upon-publish", queryRef.getAsUrlString());
×
118
                        resultList.addButton(label, PublishPage.class, params);
×
119
                    }
×
120
                }
121
                return resultList;
×
122
            } else {
123
                return new ApiResultComponent(markupId, queryRef) {
×
124
                    @Override
125
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
126
                        QueryResultList resultList = new QueryResultList(markupId, queryRef, response, viewDisplay);
×
127
                        resultList.setProfiledResource(space);
×
128
                        resultList.setPageResource(pageResource);
×
129
                        resultList.setContextId(contextId);
×
130
                        View view = viewDisplay.getView();
×
131
                        if (view != null) {
×
132
                            for (IRI actionIri : view.getViewResultActionList()) {
×
133
                                Template t = view.getTemplateForAction(actionIri);
×
134
                                if (t == null) continue;
×
135
                                String targetField = view.getTemplateTargetFieldForAction(actionIri);
×
136
                                if (targetField == null) targetField = "resource";
×
137
                                String label = view.getLabelForAction(actionIri);
×
138
                                if (label == null) label = "action...";
×
139
                                PageParameters params = new PageParameters().set("template", t.getId())
×
140
                                        .set("param_" + targetField, id)
×
141
                                        .set("context", contextId)
×
142
                                        .set("template-version", "latest");
×
143
                                if (id != null && contextId != null && !id.equals(contextId)) {
×
144
                                    params.set("part", id);
×
145
                                }
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 = MaintainedResourceRepository.get().findById(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
                                resultList.addButton(label, PublishPage.class, params);
×
161
                            }
×
162
                        }
163
                        return resultList;
×
164
                    }
165
                };
166
            }
167
        } else {
168
            if (response != null) {
×
169
                QueryResultList resultList = new QueryResultList(markupId, queryRef, response, viewDisplay);
×
170
                resultList.setPageResource(pageResource);
×
171
                resultList.setContextId(contextId);
×
172
                return resultList;
×
173
            } else {
174
                return new ApiResultComponent(markupId, queryRef) {
×
175
                    @Override
176
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
177
                        QueryResultList resultList = new QueryResultList(markupId, queryRef, response, viewDisplay);
×
178
                        resultList.setPageResource(pageResource);
×
179
                        resultList.setContextId(contextId);
×
180
                        return resultList;
×
181
                    }
182
                };
183
            }
184
        }
185
    }
186

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