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

knowledgepixels / nanodash / 23046278881

13 Mar 2026 10:15AM UTC coverage: 15.676% (-0.06%) from 15.734%
23046278881

push

github

web-flow
Merge pull request #388 from knowledgepixels/387-improve-user-page-buttons

Improve user page buttons (#387)

710 of 5489 branches covered (12.93%)

Branch coverage included in aggregate %.

1751 of 10210 relevant lines covered (17.15%)

2.35 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.View;
5
import com.knowledgepixels.nanodash.ViewDisplay;
6
import com.knowledgepixels.nanodash.domain.AbstractResourceWithProfile;
7
import com.knowledgepixels.nanodash.domain.MaintainedResource;
8
import com.knowledgepixels.nanodash.domain.Space;
9
import com.knowledgepixels.nanodash.page.PublishPage;
10
import com.knowledgepixels.nanodash.repository.MaintainedResourceRepository;
11
import com.knowledgepixels.nanodash.template.Template;
12
import org.apache.wicket.Component;
13
import org.apache.wicket.request.mapper.parameter.PageParameters;
14
import org.eclipse.rdf4j.model.IRI;
15
import org.nanopub.extra.services.ApiResponse;
16
import org.nanopub.extra.services.QueryRef;
17

18
import java.io.Serializable;
19

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

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

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

71
    private QueryResultPlainParagraphBuilder(String markupId, QueryRef queryRef, ViewDisplay viewDisplay) {
×
72
        this.markupId = markupId;
×
73
        this.queryRef = queryRef;
×
74
        this.viewDisplay = viewDisplay;
×
75
    }
×
76

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

89
    /**
90
     * Sets the context ID for the QueryResultPlainParagraph.
91
     *
92
     * @param contextId the context ID
93
     * @return the current QueryResultPlainParagraphBuilder instance
94
     */
95
    public QueryResultPlainParagraphBuilder contextId(String contextId) {
96
        this.contextId = contextId;
×
97
        return this;
×
98
    }
99

100
    public QueryResultPlainParagraphBuilder id(String id) {
101
        this.id = id;
×
102
        return this;
×
103
    }
104

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

110
    /**
111
     * Builds the QueryResultPlainParagraph component.
112
     *
113
     * @return the QueryResultPlainParagraph component
114
     */
115
    public Component build() {
116
        ApiResponse response = ApiCache.retrieveResponseAsync(queryRef);
×
117
        if (space != null) {
×
118
            if (response != null) {
×
119
                QueryResultPlainParagraph resultPlainParagraph = new QueryResultPlainParagraph(markupId, queryRef, response, viewDisplay);
×
120
                resultPlainParagraph.setResourceWithProfile(space);
×
121
                resultPlainParagraph.setPageResource(pageResource);
×
122
                resultPlainParagraph.setContextId(contextId);
×
123
                addResultButtons(resultPlainParagraph);
×
124
                return resultPlainParagraph;
×
125
            } else {
126
                return new ApiResultComponent(markupId, queryRef) {
×
127
                    @Override
128
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
129
                        QueryResultPlainParagraph resultPlainParagraph = new QueryResultPlainParagraph(markupId, queryRef, response, viewDisplay);
×
130
                        resultPlainParagraph.setResourceWithProfile(space);
×
131
                        resultPlainParagraph.setPageResource(pageResource);
×
132
                        resultPlainParagraph.setContextId(contextId);
×
133
                        addResultButtons(resultPlainParagraph);
×
134
                        return resultPlainParagraph;
×
135
                    }
136
                };
137
            }
138
        } else {
139
            if (response != null) {
×
140
                QueryResultPlainParagraph resultPlainParagraph = new QueryResultPlainParagraph(markupId, queryRef, response, viewDisplay);
×
141
                resultPlainParagraph.setPageResource(pageResource);
×
142
                resultPlainParagraph.setContextId(contextId);
×
143
                addResultButtons(resultPlainParagraph);
×
144
                return resultPlainParagraph;
×
145
            } else {
146
                return new ApiResultComponent(markupId, queryRef) {
×
147
                    @Override
148
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
149
                        QueryResultPlainParagraph resultPlainParagraph = new QueryResultPlainParagraph(markupId, queryRef, response, viewDisplay);
×
150
                        resultPlainParagraph.setPageResource(pageResource);
×
151
                        resultPlainParagraph.setContextId(contextId);
×
152
                        addResultButtons(resultPlainParagraph);
×
153
                        return resultPlainParagraph;
×
154
                    }
155
                };
156
            }
157
        }
158
    }
159

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