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

knowledgepixels / nanodash / 27145358627

08 Jun 2026 02:39PM UTC coverage: 20.682% (-0.3%) from 20.947%
27145358627

push

github

web-flow
Merge pull request #479 from knowledgepixels/feat/about-pages-478

Resource-page tabs, presets, and role-gated view actions (#478, #302)

1052 of 6429 branches covered (16.36%)

Branch coverage included in aggregate %.

2642 of 11432 relevant lines covered (23.11%)

3.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
        this.queryRef = queryRef;
×
79
        this.viewDisplay = viewDisplay;
×
80
    }
×
81

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

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

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

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

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

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