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

knowledgepixels / nanodash / 27741419211

18 Jun 2026 06:35AM UTC coverage: 26.602% (-0.4%) from 26.963%
27741419211

Pull #484

github

web-flow
Merge eb7ba5ef8 into 0f6281554
Pull Request #484: Space-ref disambiguation: conflict notice, claimants overview, ref-pinned pages

1552 of 6853 branches covered (22.65%)

Branch coverage included in aggregate %.

3418 of 11830 relevant lines covered (28.89%)

4.25 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
    private String refRoot = null;
×
35

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

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

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

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

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

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

118
    /**
119
     * Pins this paragraph to a specific ref (root definition), so action visibility is gated
120
     * against that claimant's authority rather than the resource's representative ref. Used
121
     * on {@code ?root=}-pinned pages. Null leaves it on the representative ref.
122
     *
123
     * @param refRoot the ref's root nanopub, or null
124
     * @return the current QueryResultPlainParagraphBuilder instance
125
     */
126
    public QueryResultPlainParagraphBuilder refRoot(String refRoot) {
127
        this.refRoot = refRoot;
×
128
        return this;
×
129
    }
130

131
    /**
132
     * Builds the QueryResultPlainParagraph component.
133
     *
134
     * @return the QueryResultPlainParagraph component
135
     */
136
    public Component build() {
137
        ApiResponse response = ApiCache.retrieveResponseAsync(queryRef);
×
138
        String colClass = " col-" + viewDisplay.getDisplayWidth();
×
139
        if (space != null) {
×
140
            if (response != null) {
×
141
                QueryResultPlainParagraph resultPlainParagraph = new QueryResultPlainParagraph(markupId, queryRef, response, viewDisplay);
×
142
                resultPlainParagraph.setResourceWithProfile(space);
×
143
                resultPlainParagraph.setPageResource(pageResource);
×
144
                resultPlainParagraph.setContextId(contextId);
×
145
                addResultButtons(resultPlainParagraph);
×
146
                resultPlainParagraph.add(new AttributeAppender("class", colClass));
×
147
                return resultPlainParagraph;
×
148
            } else {
149
                ApiResultComponent comp = new ApiResultComponent(markupId, queryRef) {
×
150
                    @Override
151
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
152
                        QueryResultPlainParagraph resultPlainParagraph = new QueryResultPlainParagraph(markupId, queryRef, response, viewDisplay);
×
153
                        resultPlainParagraph.setResourceWithProfile(space);
×
154
                        resultPlainParagraph.setPageResource(pageResource);
×
155
                        resultPlainParagraph.setContextId(contextId);
×
156
                        addResultButtons(resultPlainParagraph);
×
157
                        return resultPlainParagraph;
×
158
                    }
159
                };
160
                comp.add(new AttributeAppender("class", colClass));
×
161
                return comp;
×
162
            }
163
        } else {
164
            if (response != null) {
×
165
                QueryResultPlainParagraph resultPlainParagraph = new QueryResultPlainParagraph(markupId, queryRef, response, viewDisplay);
×
166
                resultPlainParagraph.setPageResource(pageResource);
×
167
                resultPlainParagraph.setContextId(contextId);
×
168
                addResultButtons(resultPlainParagraph);
×
169
                resultPlainParagraph.add(new AttributeAppender("class", colClass));
×
170
                return resultPlainParagraph;
×
171
            } else {
172
                ApiResultComponent comp = new ApiResultComponent(markupId, queryRef) {
×
173
                    @Override
174
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
175
                        QueryResultPlainParagraph resultPlainParagraph = new QueryResultPlainParagraph(markupId, queryRef, response, viewDisplay);
×
176
                        resultPlainParagraph.setPageResource(pageResource);
×
177
                        resultPlainParagraph.setContextId(contextId);
×
178
                        addResultButtons(resultPlainParagraph);
×
179
                        return resultPlainParagraph;
×
180
                    }
181
                };
182
                comp.add(new AttributeAppender("class", colClass));
×
183
                return comp;
×
184
            }
185
        }
186
    }
187

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