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

knowledgepixels / nanodash / 27963160946

22 Jun 2026 03:13PM UTC coverage: 26.549% (-0.02%) from 26.57%
27963160946

Pull #494

github

web-flow
Merge a6c43f110 into 4c33b803f
Pull Request #494: feat: drive view-displays tables by the view's query, ref-scope maintained resources

1552 of 6885 branches covered (22.54%)

Branch coverage included in aggregate %.

3418 of 11835 relevant lines covered (28.88%)

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

3
import com.google.common.collect.ArrayListMultimap;
4
import com.google.common.collect.Multimap;
5
import com.knowledgepixels.nanodash.View;
6
import com.knowledgepixels.nanodash.ViewDisplay;
7
import com.knowledgepixels.nanodash.domain.AbstractResourceWithProfile;
8
import com.knowledgepixels.nanodash.domain.Space;
9
import com.knowledgepixels.nanodash.vocabulary.KPXL_TERMS;
10
import org.apache.wicket.Component;
11
import org.apache.wicket.markup.html.WebMarkupContainer;
12
import org.apache.wicket.markup.html.basic.Label;
13
import org.apache.wicket.markup.html.link.AbstractLink;
14
import org.apache.wicket.markup.html.list.ListItem;
15
import org.apache.wicket.markup.html.list.ListView;
16
import org.apache.wicket.markup.html.panel.Panel;
17
import org.eclipse.rdf4j.model.IRI;
18
import org.nanopub.extra.services.QueryRef;
19
import org.nanopub.extra.services.QueryTemplate;
20
import org.slf4j.Logger;
21
import org.slf4j.LoggerFactory;
22

23
import java.util.ArrayList;
24
import java.util.List;
25
import java.util.Set;
26

27
public class ViewList extends Panel {
28

29
    private static final Logger logger = LoggerFactory.getLogger(ViewList.class);
×
30

31
    // The ref (root definition) this list is pinned to (?root=), used to gate each view's
32
    // action visibility against the claimant being viewed rather than the resource's
33
    // representative ref. Null = representative ref. Read at render time by the inner
34
    // ListView, so it may be set after the delegating constructor. See docs/space-ref-identity.md.
35
    private String refRoot;
36

37
    public ViewList(String markupId, AbstractResourceWithProfile resourceWithProfile) {
38
        this(markupId, resourceWithProfile, null, null, null, null, null, true, null);
×
39
    }
×
40

41
    public ViewList(String markupId, AbstractResourceWithProfile resourceWithProfile, String partId, String nanopubId, Set<IRI> partClasses) {
42
        this(markupId, resourceWithProfile, partId, nanopubId, partClasses, null, null, true, null);
×
43
    }
×
44

45
    public ViewList(String markupId, AbstractResourceWithProfile resourceWithProfile, String partId, String nanopubId, Set<IRI> partClasses, AbstractResourceWithProfile footerResource, List<AbstractLink> footerAdminButtons) {
46
        this(markupId, resourceWithProfile, partId, nanopubId, partClasses, footerResource, footerAdminButtons, true, null);
×
47
    }
×
48

49
    public ViewList(String markupId, AbstractResourceWithProfile resourceWithProfile, String partId, String nanopubId, Set<IRI> partClasses, AbstractResourceWithProfile footerResource, List<AbstractLink> footerAdminButtons, boolean showEmptyNotice) {
50
        this(markupId, resourceWithProfile, partId, nanopubId, partClasses, footerResource, footerAdminButtons, showEmptyNotice, null);
×
51
    }
×
52

53
    public ViewList(String markupId, AbstractResourceWithProfile resourceWithProfile, List<ViewDisplay> explicitViewDisplays) {
54
        this(markupId, resourceWithProfile, null, null, null, null, null, false, explicitViewDisplays);
×
55
    }
×
56

57
    /**
58
     * As {@link #ViewList(String, AbstractResourceWithProfile, List)} but pinned to a specific
59
     * ref (root definition), so each view's action visibility is gated against that claimant's
60
     * authority. Used for {@code ?root=}-pinned space pages. See docs/space-ref-identity.md.
61
     */
62
    public ViewList(String markupId, AbstractResourceWithProfile resourceWithProfile, List<ViewDisplay> explicitViewDisplays, String refRoot) {
63
        this(markupId, resourceWithProfile, null, null, null, null, null, false, explicitViewDisplays);
×
64
        this.refRoot = refRoot;
×
65
    }
×
66

67
    public ViewList(String markupId, AbstractResourceWithProfile resourceWithProfile, List<ViewDisplay> explicitViewDisplays, AbstractResourceWithProfile footerResource, List<AbstractLink> footerAdminButtons) {
68
        this(markupId, resourceWithProfile, null, null, null, footerResource, footerAdminButtons, false, explicitViewDisplays);
×
69
    }
×
70

71
    private ViewList(String markupId, AbstractResourceWithProfile resourceWithProfile, String partId, String nanopubId, Set<IRI> partClasses, AbstractResourceWithProfile footerResource, List<AbstractLink> footerAdminButtons, boolean showEmptyNotice, List<ViewDisplay> explicitViewDisplays) {
72
        super(markupId);
×
73

74
        final String id = (partId == null ? resourceWithProfile.getId() : partId);
×
75
        final String npId = (nanopubId == null ? resourceWithProfile.getNanopubId() : nanopubId);
×
76
        final List<ViewDisplay> viewDisplays;
77
        if (explicitViewDisplays != null) {
×
78
            viewDisplays = explicitViewDisplays;
×
79
        } else if (partId == null) {
×
80
            viewDisplays = resourceWithProfile.getTopLevelViewDisplays();
×
81
        } else {
82
            viewDisplays = resourceWithProfile.getPartLevelViewDisplays(partId, partClasses);
×
83
        }
84

85
        // Group viewDisplays by the first segment of their structural position (e.g. "4" from "4.4.1.papers")
86
        List<List<ViewDisplay>> groups = new ArrayList<>();
×
87
        String currentGroupKey = null;
×
88
        List<ViewDisplay> currentGroup = null;
×
89
        for (ViewDisplay vd : viewDisplays) {
×
90
            String pos = vd.getStructuralPosition();
×
91
            int firstDot = pos.indexOf('.');
×
92
            String key = firstDot > 0 ? pos.substring(0, firstDot) : pos;
×
93
            if (!key.equals(currentGroupKey)) {
×
94
                currentGroup = new ArrayList<>();
×
95
                groups.add(currentGroup);
×
96
                currentGroupKey = key;
×
97
            }
98
            currentGroup.add(vd);
×
99
        }
×
100

101
        add(new ListView<List<ViewDisplay>>("groups", groups) {
×
102
            @Override
103
            protected void populateItem(ListItem<List<ViewDisplay>> groupItem) {
104
                List<ViewDisplay> group = groupItem.getModelObject();
×
105
                groupItem.add(new ListView<ViewDisplay>("views", group) {
×
106
                    @Override
107
                    protected void populateItem(ListItem<ViewDisplay> item) {
108
                        View view = item.getModelObject().getView();
×
109
                        Multimap<String, String> queryRefParams = ArrayListMultimap.create();
×
110
                        for (String p : view.getQuery().getPlaceholdersList()) {
×
111
                            String paramName = QueryTemplate.getParamName(p);
×
112
                            if (paramName.equals(view.getQueryField())) {
×
113
                                queryRefParams.put(view.getQueryField(), id);
×
114
                                if (QueryTemplate.isMultiPlaceholder(p) && resourceWithProfile instanceof Space space) {
×
115
                                    // TODO Support this also for maintained resources and users.
116
                                    for (String altId : space.getAltIDs()) {
×
117
                                        queryRefParams.put(view.getQueryField(), altId);
×
118
                                    }
×
119
                                }
120
                            } else if (paramName.equals(view.getQueryField() + "Namespace") && resourceWithProfile.getNamespace() != null) {
×
121
                                queryRefParams.put(view.getQueryField() + "Namespace", resourceWithProfile.getNamespace());
×
122
                            } else if (paramName.equals(view.getQueryField() + "Np")) {
×
123
                                if (!QueryTemplate.isOptionalPlaceholder(p) && npId == null) {
×
124
                                    queryRefParams.put(view.getQueryField() + "Np", "x:");
×
125
                                } else {
126
                                    queryRefParams.put(view.getQueryField() + "Np", npId);
×
127
                                }
128
                            } else if (paramName.equals("root_np")) {
×
129
                                // Auto-fill the ref scope (root nanopub) from the page's effective ref,
130
                                // the same way the resource IRI above is filled, so a content-tab view
131
                                // whose query opts into ref-scoping is scoped without the panel threading
132
                                // it. Left empty when no ref is known (an optional placeholder tolerates
133
                                // the empty VALUES; the ref-scoped query then yields its no-ref result).
134
                                if (refRoot != null && !refRoot.isEmpty()) {
×
135
                                    queryRefParams.put("root_np", refRoot);
×
136
                                }
137
                            } else if (!QueryTemplate.isOptionalPlaceholder(p)) {
×
138
                                item.add(new Label("view", "<span class=\"negative\">Error: Query has non-optional parameter</span>").setEscapeModelStrings(false));
×
139
                                logger.error("Error: Query has non-optional parameter: {} {}", view.getQuery().getQueryId(), p);
×
140
                                return;
×
141
                            }
142
                        }
×
143
                        QueryRef queryRef = new QueryRef(view.getQuery().getQueryId(), queryRefParams);
×
144
                        if (view.getViewType() != null && View.getSupportedViewTypes().contains(view.getViewType())) {
×
145
                            if (view.getViewType().equals(KPXL_TERMS.LIST_VIEW)) {
×
146
                                item.add(QueryResultListBuilder.create("view", queryRef, item.getModelObject())
×
147
                                        .resourceWithProfile(resourceWithProfile)
×
148
                                        .pageResource(resourceWithProfile)
×
149
                                        .id(id)
×
150
                                        .contextId(resourceWithProfile.getId())
×
151
                                        .refRoot(refRoot)
×
152
                                        .build());
×
153
                            } else if (view.getViewType().equals(KPXL_TERMS.TABULAR_VIEW)) {
×
154
                                item.add(QueryResultTableBuilder.create("view", queryRef, item.getModelObject())
×
155
                                        .resourceWithProfile(resourceWithProfile)
×
156
                                        .contextId(resourceWithProfile.getId())
×
157
                                        .id(id)
×
158
                                        .refRoot(refRoot)
×
159
                                        .build());
×
160
                            } else if (view.getViewType().equals(KPXL_TERMS.PLAIN_PARAGRAPH_VIEW)) {
×
161
                                item.add(QueryResultPlainParagraphBuilder.create("view", queryRef, item.getModelObject())
×
162
                                        .pageResource(resourceWithProfile)
×
163
                                        .contextId(resourceWithProfile.getId())
×
164
                                        .id(id)
×
165
                                        .refRoot(refRoot)
×
166
                                        .build());
×
167
                            } else if (view.getViewType().equals(KPXL_TERMS.NANOPUB_SET_VIEW)) {
×
168
                                item.add(QueryResultNanopubSetBuilder.create("view", queryRef, item.getModelObject())
×
169
                                        .pageResource(resourceWithProfile)
×
170
                                        .contextId(resourceWithProfile.getId())
×
171
                                        .build());
×
172
                            } else if (view.getViewType().equals(KPXL_TERMS.ITEM_LIST_VIEW)) {
×
173
                                item.add(QueryResultItemListBuilder.create("view", queryRef, item.getModelObject())
×
174
                                        .resourceWithProfile(resourceWithProfile)
×
175
                                        .pageResource(resourceWithProfile)
×
176
                                        .id(id)
×
177
                                        .contextId(resourceWithProfile.getId())
×
178
                                        .build());
×
179
                            } else {
180
                                item.add(new Label("view", "<span class=\"negative\">View type \"" + view.getViewType().stringValue() + "\" is supported but its view is not implemented yet</span>").setEscapeModelStrings(false));
×
181
                                logger.error("View type \"{}\" is supported but its view is not implemented yet", view.getViewType().stringValue());
×
182
                            }
183
                        } else {
184
                            item.add(new Label("view", "<span class=\"negative\">Unsupported view type</span>").setEscapeModelStrings(false));
×
185
                            logger.error("Unsupported view type.");
×
186
                        }
187
                    }
×
188
                });
189
            }
×
190
        });
191

192
        add(new WebMarkupContainer("emptynotice").setVisible(showEmptyNotice && viewDisplays.isEmpty()));
×
193

194
        WebMarkupContainer footerSection = new WebMarkupContainer("footer-section");
×
195
        if (footerAdminButtons != null) {
×
196
            footerSection.add(new ButtonList("footer-buttons",
×
197
                    footerResource != null ? footerResource : resourceWithProfile,
×
198
                    null, null, footerAdminButtons));
199
        } else {
200
            footerSection.setVisible(false);
×
201
            footerSection.add(new Label("footer-buttons").setVisible(false));
×
202
        }
203
        add(footerSection);
×
204

205
        add(new WebMarkupContainer("page-footer").setVisible(false));
×
206
    }
×
207

208
    public void setPageFooter(Component footer) {
209
        replace(footer);
×
210
    }
×
211

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