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

knowledgepixels / nanodash / 22769646883

06 Mar 2026 03:19PM UTC coverage: 15.877%. Remained the same
22769646883

push

github

web-flow
Merge pull request #377 from knowledgepixels/fix/376-add-button-missing-on-user-page

fix: Show view action buttons on list views for resources without a space

705 of 5393 branches covered (13.07%)

Branch coverage included in aggregate %.

1741 of 10013 relevant lines covered (17.39%)

2.37 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/QueryResultListBuilder.java
1
package com.knowledgepixels.nanodash.component;
2

3
import com.knowledgepixels.nanodash.*;
4
import com.knowledgepixels.nanodash.domain.AbstractResourceWithProfile;
5
import com.knowledgepixels.nanodash.domain.MaintainedResource;
6
import com.knowledgepixels.nanodash.page.PublishPage;
7
import com.knowledgepixels.nanodash.repository.MaintainedResourceRepository;
8
import com.knowledgepixels.nanodash.template.Template;
9
import org.apache.wicket.Component;
10
import org.apache.wicket.request.mapper.parameter.PageParameters;
11
import org.eclipse.rdf4j.model.IRI;
12
import org.nanopub.extra.services.ApiResponse;
13
import org.nanopub.extra.services.QueryRef;
14

15
import java.io.Serializable;
16

17
/**
18
 * Builder class for creating QueryResultList components.
19
 */
20
public class QueryResultListBuilder implements Serializable {
21

22
    private String markupId;
23
    private ViewDisplay viewDisplay;
24
    private String contextId = null;
×
25
    private QueryRef queryRef;
26
    private AbstractResourceWithProfile resourceWithProfile = null;
×
27
    private String id = null;
×
28
    private AbstractResourceWithProfile pageResource = null;
×
29

30
    private QueryResultListBuilder(String markupId, QueryRef queryRef, ViewDisplay viewDisplay) {
×
31
        this.markupId = markupId;
×
32
        this.queryRef = queryRef;
×
33
        this.viewDisplay = viewDisplay;
×
34
    }
×
35

36
    /**
37
     * Creates a new QueryResultListBuilder instance.
38
     *
39
     * @param markupId    the markup ID for the component
40
     * @param queryRef    the query reference
41
     * @param viewDisplay the view display
42
     * @return a new QueryResultListBuilder instance
43
     */
44
    public static QueryResultListBuilder create(String markupId, QueryRef queryRef, ViewDisplay viewDisplay) {
45
        return new QueryResultListBuilder(markupId, queryRef, viewDisplay);
×
46
    }
47

48
    public QueryResultListBuilder resourceWithProfile(AbstractResourceWithProfile resourceWithProfile) {
49
        this.resourceWithProfile = resourceWithProfile;
×
50
        return this;
×
51
    }
52

53
    /**
54
     * Sets the context ID for the QueryResultList.
55
     *
56
     * @param contextId the context ID
57
     * @return the current QueryResultListBuilder instance
58
     */
59
    public QueryResultListBuilder contextId(String contextId) {
60
        this.contextId = contextId;
×
61
        return this;
×
62
    }
63

64
    public QueryResultListBuilder id(String id) {
65
        this.id = id;
×
66
        return this;
×
67
    }
68

69
    public QueryResultListBuilder pageResource(AbstractResourceWithProfile pageResource) {
70
        this.pageResource = pageResource;
×
71
        return this;
×
72
    }
73

74
    /**
75
     * Builds the QueryResultList component.
76
     *
77
     * @return the QueryResultList component
78
     */
79
    public Component build() {
80
        ApiResponse response = ApiCache.retrieveResponseAsync(queryRef);
×
81
        if (resourceWithProfile != null) {
×
82
            if (response != null) {
×
83
                QueryResultList resultList = new QueryResultList(markupId, queryRef, response, viewDisplay);
×
84
                resultList.setResourceWithProfile(resourceWithProfile);
×
85
                resultList.setPageResource(pageResource);
×
86
                resultList.setContextId(contextId);
×
87
                View view = viewDisplay.getView();
×
88
                if (view != null) {
×
89
                    for (IRI actionIri : view.getViewResultActionList()) {
×
90
                        Template t = view.getTemplateForAction(actionIri);
×
91
                        if (t == null) continue;
×
92
                        String targetField = view.getTemplateTargetFieldForAction(actionIri);
×
93
                        if (targetField == null) targetField = "resource";
×
94
                        String label = view.getLabelForAction(actionIri);
×
95
                        if (label == null) label = "action...";
×
96
                        PageParameters params = new PageParameters().set("template", t.getId())
×
97
                                .set("param_" + targetField, id)
×
98
                                .set("context", contextId)
×
99
                                .set("template-version", "latest");
×
100
                        if (id != null && contextId != null && !id.equals(contextId)) {
×
101
                            params.set("part", id);
×
102
                        }
103
                        String partField = view.getTemplatePartFieldForAction(actionIri);
×
104
                        if (partField != null) {
×
105
                            // TODO Find a better way to pass the MaintainedResource object to this method:
106
                            MaintainedResource r = MaintainedResourceRepository.get().findById(contextId);
×
107
                            if (r != null && r.getNamespace() != null) {
×
108
                                params.set("param_" + partField, r.getNamespace() + "<SET-SUFFIX>");
×
109
                            }
110
                        }
111
                        String queryMapping = view.getTemplateQueryMapping(actionIri);
×
112
                        if (queryMapping != null && queryMapping.contains(":")) {
×
113
                            params.set("values-from-query", queryRef.getAsUrlString());
×
114
                            params.set("values-from-query-mapping", queryMapping);
×
115
                        }
116
                        params.set("refresh-upon-publish", queryRef.getAsUrlString());
×
117
                        resultList.addButton(label, PublishPage.class, params);
×
118
                    }
×
119
                }
120
                return resultList;
×
121
            } else {
122
                return new ApiResultComponent(markupId, queryRef) {
×
123
                    @Override
124
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
125
                        QueryResultList resultList = new QueryResultList(markupId, queryRef, response, viewDisplay);
×
126
                        resultList.setResourceWithProfile(resourceWithProfile);
×
127
                        resultList.setPageResource(pageResource);
×
128
                        resultList.setContextId(contextId);
×
129
                        View view = viewDisplay.getView();
×
130
                        if (view != null) {
×
131
                            for (IRI actionIri : view.getViewResultActionList()) {
×
132
                                Template t = view.getTemplateForAction(actionIri);
×
133
                                if (t == null) continue;
×
134
                                String targetField = view.getTemplateTargetFieldForAction(actionIri);
×
135
                                if (targetField == null) targetField = "resource";
×
136
                                String label = view.getLabelForAction(actionIri);
×
137
                                if (label == null) label = "action...";
×
138
                                PageParameters params = new PageParameters().set("template", t.getId())
×
139
                                        .set("param_" + targetField, id)
×
140
                                        .set("context", contextId)
×
141
                                        .set("template-version", "latest");
×
142
                                if (id != null && contextId != null && !id.equals(contextId)) {
×
143
                                    params.set("part", id);
×
144
                                }
145
                                String partField = view.getTemplatePartFieldForAction(actionIri);
×
146
                                if (partField != null) {
×
147
                                    // TODO Find a better way to pass the MaintainedResource object to this method:
148
                                    MaintainedResource r = MaintainedResourceRepository.get().findById(contextId);
×
149
                                    if (r != null && r.getNamespace() != null) {
×
150
                                        params.set("param_" + partField, r.getNamespace() + "<SET-SUFFIX>");
×
151
                                    }
152
                                }
153
                                String queryMapping = view.getTemplateQueryMapping(actionIri);
×
154
                                if (queryMapping != null && queryMapping.contains(":")) {
×
155
                                    params.set("values-from-query", queryRef.getAsUrlString());
×
156
                                    params.set("values-from-query-mapping", queryMapping);
×
157
                                }
158
                                params.set("refresh-upon-publish", queryRef.getAsUrlString());
×
159
                                resultList.addButton(label, PublishPage.class, params);
×
160
                            }
×
161
                        }
162
                        return resultList;
×
163
                    }
164
                };
165
            }
166
        } else {
167
            if (response != null) {
×
168
                QueryResultList resultList = new QueryResultList(markupId, queryRef, response, viewDisplay);
×
169
                resultList.setPageResource(pageResource);
×
170
                resultList.setContextId(contextId);
×
171
                return resultList;
×
172
            } else {
173
                return new ApiResultComponent(markupId, queryRef) {
×
174
                    @Override
175
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
176
                        QueryResultList resultList = new QueryResultList(markupId, queryRef, response, viewDisplay);
×
177
                        resultList.setPageResource(pageResource);
×
178
                        resultList.setContextId(contextId);
×
179
                        return resultList;
×
180
                    }
181
                };
182
            }
183
        }
184
    }
185

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