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

knowledgepixels / nanodash / 24382503285

14 Apr 2026 05:24AM UTC coverage: 15.886% (-0.2%) from 16.094%
24382503285

push

github

web-flow
Merge pull request #438 from knowledgepixels/feature/item-list-view-435

feat: implement ItemListView and fix async view rendering

789 of 6130 branches covered (12.87%)

Branch coverage included in aggregate %.

1978 of 11288 relevant lines covered (17.52%)

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.behavior.AttributeAppender;
14
import org.apache.wicket.request.mapper.parameter.PageParameters;
15
import org.eclipse.rdf4j.model.IRI;
16
import org.nanopub.extra.services.ApiResponse;
17
import org.nanopub.extra.services.QueryRef;
18

19
import java.io.Serializable;
20

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

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

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

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

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

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

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

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

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

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