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

knowledgepixels / nanodash / 27622310436

16 Jun 2026 01:49PM UTC coverage: 26.963% (+6.3%) from 20.697%
27622310436

Pull #483

github

web-flow
Merge dbba567c9 into 663f14f46
Pull Request #483: Space/resource About pages, ref-aware spaces, and magic query params

1542 of 6717 branches covered (22.96%)

Branch coverage included in aggregate %.

3407 of 11638 relevant lines covered (29.27%)

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

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

20
import java.io.Serializable;
21

22
/**
23
 * Builder class for creating QueryResultPlainParagraph components.
24
 */
25
public class QueryResultPlainParagraphBuilder implements Serializable {
26

27
    private String markupId;
28
    private ViewDisplay viewDisplay;
29
    private String contextId = null;
×
30
    private QueryRef queryRef;
31
    private Space space = null;
×
32
    private String id = null;
×
33
    private AbstractResourceWithProfile pageResource = null;
×
34

35
    // This method is the result of refactoring and copying code from other classes done
36
    // by Cursor. This should in general be aligned and refactored more with the other classes.
37
    private void addResultButtons(QueryResultPlainParagraph resultPlainParagraph) {
38
        View view = viewDisplay.getView();
×
39
        if (view == null) return;
×
40
        for (IRI actionIri : view.getViewResultActionList()) {
×
41
            // Per-action role gating (docs/role-specific-views.md): skip an action
42
            // whose gen:isVisibleTo the viewer does not satisfy.
43
            if (!SpaceMemberRole.isViewerEntitled(view.getActionVisibleTo(actionIri), pageResource)) continue;
×
44
            Template t = view.getTemplateForAction(actionIri);
×
45
            if (t == null) continue;
×
46
            String targetField = view.getTemplateTargetFieldForAction(actionIri);
×
47
            if (targetField == null) targetField = "resource";
×
48
            String label = view.getLabelForAction(actionIri);
×
49
            if (label == null) label = "action...";
×
50
            if (!label.endsWith("...")) label += "...";
×
51
            PageParameters params = new PageParameters().set("template", t.getId())
×
52
                    .set("param_" + targetField, id)
×
53
                    .set("context", contextId)
×
54
                    .set("template-version", "latest");
×
55
            if (id != null && contextId != null && !id.equals(contextId)) {
×
56
                params.set("part", id);
×
57
            }
58
            String partField = view.getTemplatePartFieldForAction(actionIri);
×
59
            if (partField != null) {
×
60
                // TODO Find a better way to pass the MaintainedResource object to this method:
61
                MaintainedResource r = MaintainedResourceRepository.get().findById(contextId);
×
62
                if (r != null && r.getNamespace() != null) {
×
63
                    params.set("param_" + partField, r.getNamespace() + "<SET-SUFFIX>");
×
64
                }
65
            }
66
            String queryMapping = view.getTemplateQueryMapping(actionIri);
×
67
            if (queryMapping != null && queryMapping.contains(":")) {
×
68
                params.set("values-from-query", queryRef.getAsUrlString());
×
69
                params.set("values-from-query-mapping", queryMapping);
×
70
            }
71
            params.set("refresh-upon-publish", queryRef.getAsUrlString());
×
72
            resultPlainParagraph.addButton(label, PublishPage.class, params);
×
73
        }
×
74
    }
×
75

76
    private QueryResultPlainParagraphBuilder(String markupId, QueryRef queryRef, ViewDisplay viewDisplay) {
×
77
        this.markupId = markupId;
×
78
        // Bind session-derived "magic" query parameters here on the request thread
79
        // (ApiCache fetches on background threads where the session is absent).
80
        this.queryRef = com.knowledgepixels.nanodash.MagicQueryParams.augment(queryRef);
×
81
        this.viewDisplay = viewDisplay;
×
82
    }
×
83

84
    /**
85
     * Creates a new QueryResultPlainParagraphBuilder instance.
86
     *
87
     * @param markupId    the markup ID for the component
88
     * @param queryRef    the query reference
89
     * @param viewDisplay the view display
90
     * @return a new QueryResultPlainParagraphBuilder instance
91
     */
92
    public static QueryResultPlainParagraphBuilder create(String markupId, QueryRef queryRef, ViewDisplay viewDisplay) {
93
        return new QueryResultPlainParagraphBuilder(markupId, queryRef, viewDisplay);
×
94
    }
95

96
    /**
97
     * Sets the context ID for the QueryResultPlainParagraph.
98
     *
99
     * @param contextId the context ID
100
     * @return the current QueryResultPlainParagraphBuilder instance
101
     */
102
    public QueryResultPlainParagraphBuilder contextId(String contextId) {
103
        this.contextId = contextId;
×
104
        return this;
×
105
    }
106

107
    public QueryResultPlainParagraphBuilder id(String id) {
108
        this.id = id;
×
109
        return this;
×
110
    }
111

112
    public QueryResultPlainParagraphBuilder pageResource(AbstractResourceWithProfile pageResource) {
113
        this.pageResource = pageResource;
×
114
        return this;
×
115
    }
116

117
    /**
118
     * Builds the QueryResultPlainParagraph component.
119
     *
120
     * @return the QueryResultPlainParagraph component
121
     */
122
    public Component build() {
123
        ApiResponse response = ApiCache.retrieveResponseAsync(queryRef);
×
124
        String colClass = " col-" + viewDisplay.getDisplayWidth();
×
125
        if (space != null) {
×
126
            if (response != null) {
×
127
                QueryResultPlainParagraph resultPlainParagraph = new QueryResultPlainParagraph(markupId, queryRef, response, viewDisplay);
×
128
                resultPlainParagraph.setResourceWithProfile(space);
×
129
                resultPlainParagraph.setPageResource(pageResource);
×
130
                resultPlainParagraph.setContextId(contextId);
×
131
                addResultButtons(resultPlainParagraph);
×
132
                resultPlainParagraph.add(new AttributeAppender("class", colClass));
×
133
                return resultPlainParagraph;
×
134
            } else {
135
                ApiResultComponent comp = new ApiResultComponent(markupId, queryRef) {
×
136
                    @Override
137
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
138
                        QueryResultPlainParagraph resultPlainParagraph = new QueryResultPlainParagraph(markupId, queryRef, response, viewDisplay);
×
139
                        resultPlainParagraph.setResourceWithProfile(space);
×
140
                        resultPlainParagraph.setPageResource(pageResource);
×
141
                        resultPlainParagraph.setContextId(contextId);
×
142
                        addResultButtons(resultPlainParagraph);
×
143
                        return resultPlainParagraph;
×
144
                    }
145
                };
146
                comp.add(new AttributeAppender("class", colClass));
×
147
                return comp;
×
148
            }
149
        } else {
150
            if (response != null) {
×
151
                QueryResultPlainParagraph resultPlainParagraph = new QueryResultPlainParagraph(markupId, queryRef, response, viewDisplay);
×
152
                resultPlainParagraph.setPageResource(pageResource);
×
153
                resultPlainParagraph.setContextId(contextId);
×
154
                addResultButtons(resultPlainParagraph);
×
155
                resultPlainParagraph.add(new AttributeAppender("class", colClass));
×
156
                return resultPlainParagraph;
×
157
            } else {
158
                ApiResultComponent comp = new ApiResultComponent(markupId, queryRef) {
×
159
                    @Override
160
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
161
                        QueryResultPlainParagraph resultPlainParagraph = new QueryResultPlainParagraph(markupId, queryRef, response, viewDisplay);
×
162
                        resultPlainParagraph.setPageResource(pageResource);
×
163
                        resultPlainParagraph.setContextId(contextId);
×
164
                        addResultButtons(resultPlainParagraph);
×
165
                        return resultPlainParagraph;
×
166
                    }
167
                };
168
                comp.add(new AttributeAppender("class", colClass));
×
169
                return comp;
×
170
            }
171
        }
172
    }
173

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