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

knowledgepixels / nanodash / 22618039211

03 Mar 2026 10:05AM UTC coverage: 16.058% (+0.2%) from 15.884%
22618039211

Pull #365

github

web-flow
Merge 1e7e700f0 into a8c4b4a77
Pull Request #365: Refactor of `ResourceWithProfile` and related classes

699 of 5287 branches covered (13.22%)

Branch coverage included in aggregate %.

1721 of 9783 relevant lines covered (17.59%)

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

17
import java.io.Serializable;
18

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

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

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

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

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

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

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

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

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