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

knowledgepixels / nanodash / 26284735769

22 May 2026 11:18AM UTC coverage: 20.838% (+0.09%) from 20.748%
26284735769

Pull #468

github

web-flow
Merge ddda26da3 into 65b0c8452
Pull Request #468: Source space data from nanopub-query spaces repo

1034 of 6284 branches covered (16.45%)

Branch coverage included in aggregate %.

2668 of 11482 relevant lines covered (23.24%)

3.32 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.slf4j.Logger;
20
import org.slf4j.LoggerFactory;
21

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

26
public class ViewList extends Panel {
27

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

30
    public ViewList(String markupId, AbstractResourceWithProfile resourceWithProfile) {
31
        this(markupId, resourceWithProfile, null, null, null, null, null, true, null);
×
32
    }
×
33

34
    public ViewList(String markupId, AbstractResourceWithProfile resourceWithProfile, String partId, String nanopubId, Set<IRI> partClasses) {
35
        this(markupId, resourceWithProfile, partId, nanopubId, partClasses, null, null, true, null);
×
36
    }
×
37

38
    public ViewList(String markupId, AbstractResourceWithProfile resourceWithProfile, String partId, String nanopubId, Set<IRI> partClasses, AbstractResourceWithProfile footerResource, List<AbstractLink> footerAdminButtons) {
39
        this(markupId, resourceWithProfile, partId, nanopubId, partClasses, footerResource, footerAdminButtons, true, null);
×
40
    }
×
41

42
    public ViewList(String markupId, AbstractResourceWithProfile resourceWithProfile, String partId, String nanopubId, Set<IRI> partClasses, AbstractResourceWithProfile footerResource, List<AbstractLink> footerAdminButtons, boolean showEmptyNotice) {
43
        this(markupId, resourceWithProfile, partId, nanopubId, partClasses, footerResource, footerAdminButtons, showEmptyNotice, null);
×
44
    }
×
45

46
    public ViewList(String markupId, AbstractResourceWithProfile resourceWithProfile, List<ViewDisplay> explicitViewDisplays) {
47
        this(markupId, resourceWithProfile, null, null, null, null, null, false, explicitViewDisplays);
×
48
    }
×
49

50
    public ViewList(String markupId, AbstractResourceWithProfile resourceWithProfile, List<ViewDisplay> explicitViewDisplays, AbstractResourceWithProfile footerResource, List<AbstractLink> footerAdminButtons) {
51
        this(markupId, resourceWithProfile, null, null, null, footerResource, footerAdminButtons, false, explicitViewDisplays);
×
52
    }
×
53

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

57
        final String id = (partId == null ? resourceWithProfile.getId() : partId);
×
58
        final String npId = (nanopubId == null ? resourceWithProfile.getNanopubId() : nanopubId);
×
59
        final List<ViewDisplay> viewDisplays;
60
        if (explicitViewDisplays != null) {
×
61
            viewDisplays = explicitViewDisplays;
×
62
        } else if (partId == null) {
×
63
            viewDisplays = resourceWithProfile.getTopLevelViewDisplays();
×
64
        } else {
65
            viewDisplays = resourceWithProfile.getPartLevelViewDisplays(partId, partClasses);
×
66
        }
67

68
        // Group viewDisplays by the first segment of their structural position (e.g. "4" from "4.4.1.papers")
69
        List<List<ViewDisplay>> groups = new ArrayList<>();
×
70
        String currentGroupKey = null;
×
71
        List<ViewDisplay> currentGroup = null;
×
72
        for (ViewDisplay vd : viewDisplays) {
×
73
            String pos = vd.getStructuralPosition();
×
74
            int firstDot = pos.indexOf('.');
×
75
            String key = firstDot > 0 ? pos.substring(0, firstDot) : pos;
×
76
            if (!key.equals(currentGroupKey)) {
×
77
                currentGroup = new ArrayList<>();
×
78
                groups.add(currentGroup);
×
79
                currentGroupKey = key;
×
80
            }
81
            currentGroup.add(vd);
×
82
        }
×
83

84
        add(new ListView<List<ViewDisplay>>("groups", groups) {
×
85
            @Override
86
            protected void populateItem(ListItem<List<ViewDisplay>> groupItem) {
87
                List<ViewDisplay> group = groupItem.getModelObject();
×
88
                groupItem.add(new ListView<ViewDisplay>("views", group) {
×
89
                    @Override
90
                    protected void populateItem(ListItem<ViewDisplay> item) {
91
                        View view = item.getModelObject().getView();
×
92
                        Multimap<String, String> queryRefParams = ArrayListMultimap.create();
×
93
                        for (String p : view.getQuery().getPlaceholdersList()) {
×
94
                            String paramName = QueryParamField.getParamName(p);
×
95
                            if (paramName.equals(view.getQueryField())) {
×
96
                                queryRefParams.put(view.getQueryField(), id);
×
97
                                if (QueryParamField.isMultiPlaceholder(p) && resourceWithProfile instanceof Space space) {
×
98
                                    // TODO Support this also for maintained resources and users.
99
                                    for (String altId : space.getAltIDs()) {
×
100
                                        queryRefParams.put(view.getQueryField(), altId);
×
101
                                    }
×
102
                                }
103
                            } else if (paramName.equals(view.getQueryField() + "Namespace") && resourceWithProfile.getNamespace() != null) {
×
104
                                queryRefParams.put(view.getQueryField() + "Namespace", resourceWithProfile.getNamespace());
×
105
                            } else if (paramName.equals(view.getQueryField() + "Np")) {
×
106
                                if (!QueryParamField.isOptional(p) && npId == null) {
×
107
                                    queryRefParams.put(view.getQueryField() + "Np", "x:");
×
108
                                } else {
109
                                    queryRefParams.put(view.getQueryField() + "Np", npId);
×
110
                                }
111
                            } else if (paramName.equals("user_pubkey") && QueryParamField.isMultiPlaceholder(p) && resourceWithProfile instanceof Space space) {
×
112
                                // TODO Push this per-view pubkey filter server-side
113
                                // (a published grlc query that gates by user-of-space)
114
                                // so nanodash doesn't have to expand the placeholder
115
                                // client-side; see Space.getUserPubkeyHashes.
116
                                for (String hash : space.getUserPubkeyHashes()) {
×
117
                                    queryRefParams.put("user_pubkey", hash);
×
118
                                }
×
119
                            } else if (paramName.equals("admin_pubkey") && QueryParamField.isMultiPlaceholder(p) && resourceWithProfile instanceof Space space) {
×
120
                                // TODO Same as above for admin-of-space filtering.
121
                                for (String hash : space.getAdminPubkeyHashes()) {
×
122
                                    queryRefParams.put("admin_pubkey", hash);
×
123
                                }
×
124
                            } else if (!QueryParamField.isOptional(p)) {
×
125
                                item.add(new Label("view", "<span class=\"negative\">Error: Query has non-optional parameter</span>").setEscapeModelStrings(false));
×
126
                                logger.error("Error: Query has non-optional parameter: {} {}", view.getQuery().getQueryId(), p);
×
127
                                return;
×
128
                            }
129
                        }
×
130
                        QueryRef queryRef = new QueryRef(view.getQuery().getQueryId(), queryRefParams);
×
131
                        if (view.getViewType() != null && View.getSupportedViewTypes().contains(view.getViewType())) {
×
132
                            if (view.getViewType().equals(KPXL_TERMS.LIST_VIEW)) {
×
133
                                item.add(QueryResultListBuilder.create("view", queryRef, item.getModelObject())
×
134
                                        .resourceWithProfile(resourceWithProfile)
×
135
                                        .pageResource(resourceWithProfile)
×
136
                                        .id(id)
×
137
                                        .contextId(resourceWithProfile.getId())
×
138
                                        .build());
×
139
                            } else if (view.getViewType().equals(KPXL_TERMS.TABULAR_VIEW)) {
×
140
                                item.add(QueryResultTableBuilder.create("view", queryRef, item.getModelObject())
×
141
                                        .resourceWithProfile(resourceWithProfile)
×
142
                                        .contextId(resourceWithProfile.getId())
×
143
                                        .id(id)
×
144
                                        .build());
×
145
                            } else if (view.getViewType().equals(KPXL_TERMS.PLAIN_PARAGRAPH_VIEW)) {
×
146
                                item.add(QueryResultPlainParagraphBuilder.create("view", queryRef, item.getModelObject())
×
147
                                        .pageResource(resourceWithProfile)
×
148
                                        .contextId(resourceWithProfile.getId())
×
149
                                        .id(id)
×
150
                                        .build());
×
151
                            } else if (view.getViewType().equals(KPXL_TERMS.NANOPUB_SET_VIEW)) {
×
152
                                item.add(QueryResultNanopubSetBuilder.create("view", queryRef, item.getModelObject())
×
153
                                        .pageResource(resourceWithProfile)
×
154
                                        .contextId(resourceWithProfile.getId())
×
155
                                        .build());
×
156
                            } else if (view.getViewType().equals(KPXL_TERMS.ITEM_LIST_VIEW)) {
×
157
                                item.add(QueryResultItemListBuilder.create("view", queryRef, item.getModelObject())
×
158
                                        .resourceWithProfile(resourceWithProfile)
×
159
                                        .pageResource(resourceWithProfile)
×
160
                                        .id(id)
×
161
                                        .contextId(resourceWithProfile.getId())
×
162
                                        .build());
×
163
                            } else {
164
                                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));
×
165
                                logger.error("View type \"{}\" is supported but its view is not implemented yet", view.getViewType().stringValue());
×
166
                            }
167
                        } else {
168
                            item.add(new Label("view", "<span class=\"negative\">Unsupported view type</span>").setEscapeModelStrings(false));
×
169
                            logger.error("Unsupported view type.");
×
170
                        }
171
                    }
×
172
                });
173
            }
×
174
        });
175

176
        add(new WebMarkupContainer("emptynotice").setVisible(showEmptyNotice && viewDisplays.isEmpty()));
×
177

178
        WebMarkupContainer footerSection = new WebMarkupContainer("footer-section");
×
179
        if (footerAdminButtons != null) {
×
180
            footerSection.add(new ButtonList("footer-buttons",
×
181
                    footerResource != null ? footerResource : resourceWithProfile,
×
182
                    null, null, footerAdminButtons));
183
        } else {
184
            footerSection.setVisible(false);
×
185
            footerSection.add(new Label("footer-buttons").setVisible(false));
×
186
        }
187
        add(footerSection);
×
188

189
        add(new WebMarkupContainer("page-footer").setVisible(false));
×
190
    }
×
191

192
    public void setPageFooter(Component footer) {
193
        replace(footer);
×
194
    }
×
195

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