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

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

15
import java.io.Serializable;
16

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

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

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

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

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

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

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

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

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