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

knowledgepixels / nanodash / 27811003513

19 Jun 2026 07:06AM UTC coverage: 26.612% (-0.4%) from 26.963%
27811003513

Pull #484

github

web-flow
Merge 2b4ad3339 into 0f6281554
Pull Request #484: Space-ref disambiguation: conflict notice, claimants overview, ref-pinned pages

1552 of 6853 branches covered (22.65%)

Branch coverage included in aggregate %.

3420 of 11830 relevant lines covered (28.91%)

4.26 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 (!QueryTemplate.isOptionalPlaceholder(p)) {
×
129
                                item.add(new Label("view", "<span class=\"negative\">Error: Query has non-optional parameter</span>").setEscapeModelStrings(false));
×
130
                                logger.error("Error: Query has non-optional parameter: {} {}", view.getQuery().getQueryId(), p);
×
131
                                return;
×
132
                            }
133
                        }
×
134
                        QueryRef queryRef = new QueryRef(view.getQuery().getQueryId(), queryRefParams);
×
135
                        if (view.getViewType() != null && View.getSupportedViewTypes().contains(view.getViewType())) {
×
136
                            if (view.getViewType().equals(KPXL_TERMS.LIST_VIEW)) {
×
137
                                item.add(QueryResultListBuilder.create("view", queryRef, item.getModelObject())
×
138
                                        .resourceWithProfile(resourceWithProfile)
×
139
                                        .pageResource(resourceWithProfile)
×
140
                                        .id(id)
×
141
                                        .contextId(resourceWithProfile.getId())
×
142
                                        .refRoot(refRoot)
×
143
                                        .build());
×
144
                            } else if (view.getViewType().equals(KPXL_TERMS.TABULAR_VIEW)) {
×
145
                                item.add(QueryResultTableBuilder.create("view", queryRef, item.getModelObject())
×
146
                                        .resourceWithProfile(resourceWithProfile)
×
147
                                        .contextId(resourceWithProfile.getId())
×
148
                                        .id(id)
×
149
                                        .refRoot(refRoot)
×
150
                                        .build());
×
151
                            } else if (view.getViewType().equals(KPXL_TERMS.PLAIN_PARAGRAPH_VIEW)) {
×
152
                                item.add(QueryResultPlainParagraphBuilder.create("view", queryRef, item.getModelObject())
×
153
                                        .pageResource(resourceWithProfile)
×
154
                                        .contextId(resourceWithProfile.getId())
×
155
                                        .id(id)
×
156
                                        .refRoot(refRoot)
×
157
                                        .build());
×
158
                            } else if (view.getViewType().equals(KPXL_TERMS.NANOPUB_SET_VIEW)) {
×
159
                                item.add(QueryResultNanopubSetBuilder.create("view", queryRef, item.getModelObject())
×
160
                                        .pageResource(resourceWithProfile)
×
161
                                        .contextId(resourceWithProfile.getId())
×
162
                                        .build());
×
163
                            } else if (view.getViewType().equals(KPXL_TERMS.ITEM_LIST_VIEW)) {
×
164
                                item.add(QueryResultItemListBuilder.create("view", queryRef, item.getModelObject())
×
165
                                        .resourceWithProfile(resourceWithProfile)
×
166
                                        .pageResource(resourceWithProfile)
×
167
                                        .id(id)
×
168
                                        .contextId(resourceWithProfile.getId())
×
169
                                        .build());
×
170
                            } else {
171
                                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));
×
172
                                logger.error("View type \"{}\" is supported but its view is not implemented yet", view.getViewType().stringValue());
×
173
                            }
174
                        } else {
175
                            item.add(new Label("view", "<span class=\"negative\">Unsupported view type</span>").setEscapeModelStrings(false));
×
176
                            logger.error("Unsupported view type.");
×
177
                        }
178
                    }
×
179
                });
180
            }
×
181
        });
182

183
        add(new WebMarkupContainer("emptynotice").setVisible(showEmptyNotice && viewDisplays.isEmpty()));
×
184

185
        WebMarkupContainer footerSection = new WebMarkupContainer("footer-section");
×
186
        if (footerAdminButtons != null) {
×
187
            footerSection.add(new ButtonList("footer-buttons",
×
188
                    footerResource != null ? footerResource : resourceWithProfile,
×
189
                    null, null, footerAdminButtons));
190
        } else {
191
            footerSection.setVisible(false);
×
192
            footerSection.add(new Label("footer-buttons").setVisible(false));
×
193
        }
194
        add(footerSection);
×
195

196
        add(new WebMarkupContainer("page-footer").setVisible(false));
×
197
    }
×
198

199
    public void setPageFooter(Component footer) {
200
        replace(footer);
×
201
    }
×
202

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