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

knowledgepixels / nanodash / 22630596072

03 Mar 2026 03:41PM UTC coverage: 15.949% (-0.08%) from 16.03%
22630596072

Pull #369

github

web-flow
Merge 6951bc4cf into 85e0af2dc
Pull Request #369: Replace "^" for view displays with dropdown menu

699 of 5317 branches covered (13.15%)

Branch coverage included in aggregate %.

1721 of 9856 relevant lines covered (17.46%)

2.4 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
            PageParameters params = new PageParameters().set("template", t.getId())
×
46
                    .set("param_" + targetField, id)
×
47
                    .set("context", contextId)
×
48
                    .set("template-version", "latest");
×
49
            if (id != null && contextId != null && !id.equals(contextId)) {
×
50
                params.set("part", id);
×
51
            }
52
            String partField = view.getTemplatePartFieldForAction(actionIri);
×
53
            if (partField != null) {
×
54
                // TODO Find a better way to pass the MaintainedResource object to this method:
55
                MaintainedResource r = MaintainedResourceRepository.get().findById(contextId);
×
56
                if (r != null && r.getNamespace() != null) {
×
57
                    params.set("param_" + partField, r.getNamespace() + "<SET-SUFFIX>");
×
58
                }
59
            }
60
            String queryMapping = view.getTemplateQueryMapping(actionIri);
×
61
            if (queryMapping != null && queryMapping.contains(":")) {
×
62
                params.set("values-from-query", queryRef.getAsUrlString());
×
63
                params.set("values-from-query-mapping", queryMapping);
×
64
            }
65
            params.set("refresh-upon-publish", queryRef.getAsUrlString());
×
66
            resultPlainParagraph.addButton(label, PublishPage.class, params);
×
67
        }
×
68
    }
×
69

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

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

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

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

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

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

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