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

knowledgepixels / nanodash / 22620546567

03 Mar 2026 11:16AM UTC coverage: 15.845% (-0.04%) from 15.884%
22620546567

Pull #366

github

web-flow
Merge 6215c67ab into a8c4b4a77
Pull Request #366: fix(user-page): conditionally show latest nanopubs for unconfigured users

699 of 5301 branches covered (13.19%)

Branch coverage included in aggregate %.

1690 of 9776 relevant lines covered (17.29%)

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/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.*;
6
import com.knowledgepixels.nanodash.vocabulary.KPXL_TERMS;
7
import org.apache.wicket.markup.html.WebMarkupContainer;
8
import org.apache.wicket.markup.html.basic.Label;
9
import org.apache.wicket.markup.html.link.AbstractLink;
10
import org.apache.wicket.markup.html.list.ListItem;
11
import org.apache.wicket.markup.html.list.ListView;
12
import org.apache.wicket.markup.html.panel.Panel;
13
import org.eclipse.rdf4j.model.IRI;
14
import org.nanopub.extra.services.QueryRef;
15
import org.slf4j.Logger;
16
import org.slf4j.LoggerFactory;
17

18
import java.util.ArrayList;
19
import java.util.List;
20
import java.util.Set;
21

22
public class ViewList extends Panel {
23

24
    private static final Logger logger = LoggerFactory.getLogger(ViewList.class);
×
25

26
    public ViewList(String markupId, ResourceWithProfile resourceWithProfile) {
27
        this(markupId, resourceWithProfile, null, null, null, null, null, true, null);
×
28
    }
×
29

30
    public ViewList(String markupId, ResourceWithProfile resourceWithProfile, String partId, String nanopubId, Set<IRI> partClasses) {
31
        this(markupId, resourceWithProfile, partId, nanopubId, partClasses, null, null, true, null);
×
32
    }
×
33

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

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

42
    public ViewList(String markupId, ResourceWithProfile resourceWithProfile, List<ViewDisplay> explicitViewDisplays) {
43
        this(markupId, resourceWithProfile, null, null, null, null, null, false, explicitViewDisplays);
×
44
    }
×
45

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

50
    private ViewList(String markupId, ResourceWithProfile resourceWithProfile, String partId, String nanopubId, Set<IRI> partClasses, ResourceWithProfile footerResource, List<AbstractLink> footerAdminButtons, boolean showEmptyNotice, List<ViewDisplay> explicitViewDisplays) {
51
        super(markupId);
×
52

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

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

80
        add(new ListView<List<ViewDisplay>>("groups", groups) {
×
81
            @Override
82
            protected void populateItem(ListItem<List<ViewDisplay>> groupItem) {
83
                List<ViewDisplay> group = groupItem.getModelObject();
×
84
                groupItem.add(new ListView<ViewDisplay>("views", group) {
×
85
                    @Override
86
                    protected void populateItem(ListItem<ViewDisplay> item) {
87
                        View view = item.getModelObject().getView();
×
88
                        Multimap<String, String> queryRefParams = ArrayListMultimap.create();
×
89
                        for (String p : view.getQuery().getPlaceholdersList()) {
×
90
                            String paramName = QueryParamField.getParamName(p);
×
91
                            if (paramName.equals(view.getQueryField())) {
×
92
                                queryRefParams.put(view.getQueryField(), id);
×
93
                                if (QueryParamField.isMultiPlaceholder(p) && resourceWithProfile instanceof Space space) {
×
94
                                    // TODO Support this also for maintained resources and users.
95
                                    for (String altId : space.getAltIDs()) {
×
96
                                        queryRefParams.put(view.getQueryField(), altId);
×
97
                                    }
×
98
                                }
99
                            } else if (paramName.equals(view.getQueryField() + "Namespace") && resourceWithProfile.getNamespace() != null) {
×
100
                                queryRefParams.put(view.getQueryField() + "Namespace", resourceWithProfile.getNamespace());
×
101
                            } else if (paramName.equals(view.getQueryField() + "Np")) {
×
102
                                if (!QueryParamField.isOptional(p) && npId == null) {
×
103
                                    queryRefParams.put(view.getQueryField() + "Np", "x:");
×
104
                                } else {
105
                                    queryRefParams.put(view.getQueryField() + "Np", npId);
×
106
                                }
107
                            } else if (paramName.equals("user_pubkey") && QueryParamField.isMultiPlaceholder(p) && resourceWithProfile instanceof Space space) {
×
108
                                for (IRI userId : space.getUsers()) {
×
109
                                    for (String memberHash : User.getUserData().getPubkeyhashes(userId, true)) {
×
110
                                        queryRefParams.put("user_pubkey", memberHash);
×
111
                                    }
×
112
                                }
×
113
                            } else if (paramName.equals("admin_pubkey") && QueryParamField.isMultiPlaceholder(p) && resourceWithProfile instanceof Space space) {
×
114
                                for (IRI adminId : space.getAdmins()) {
×
115
                                    for (String adminHash : User.getUserData().getPubkeyhashes(adminId, true)) {
×
116
                                        queryRefParams.put("admin_pubkey", adminHash);
×
117
                                    }
×
118
                                }
×
119
                            } else if (!QueryParamField.isOptional(p)) {
×
120
                                item.add(new Label("view", "<span class=\"negative\">Error: Query has non-optional parameter</span>").setEscapeModelStrings(false));
×
121
                                logger.error("Error: Query has non-optional parameter: {} {}", view.getQuery().getQueryId(), p);
×
122
                                return;
×
123
                            }
124
                        }
×
125
                        QueryRef queryRef = new QueryRef(view.getQuery().getQueryId(), queryRefParams);
×
126
                        if (view.getViewType() != null && View.getSupportedViewTypes().contains(view.getViewType())) {
×
127
                            if (view.getViewType().equals(KPXL_TERMS.LIST_VIEW)) {
×
128
                                item.add(QueryResultListBuilder.create("view", queryRef, item.getModelObject())
×
129
                                        .space(resourceWithProfile.getSpace())
×
130
                                        .id(id)
×
131
                                        .contextId(resourceWithProfile.getId())
×
132
                                        .build());
×
133
                            } else if (view.getViewType().equals(KPXL_TERMS.TABULAR_VIEW)) {
×
134
                                item.add(QueryResultTableBuilder.create("view", queryRef, item.getModelObject())
×
135
                                        .profiledResource(resourceWithProfile)
×
136
                                        .contextId(resourceWithProfile.getId())
×
137
                                        .id(id)
×
138
                                        .build());
×
139
                            } else if (view.getViewType().equals(KPXL_TERMS.PLAIN_PARAGRAPH_VIEW)) {
×
140
                                item.add(QueryResultPlainParagraphBuilder.create("view", queryRef, item.getModelObject())
×
141
                                        .contextId(resourceWithProfile.getId())
×
142
                                        .id(id)
×
143
                                        .build());
×
144
                            } else if (view.getViewType().equals(KPXL_TERMS.NANOPUB_SET_VIEW)) {
×
145
                                item.add(QueryResultNanopubSetBuilder.create("view", queryRef, item.getModelObject())
×
146
                                        .contextId(resourceWithProfile.getId())
×
147
                                        .build());
×
148
                            } else {
149
                                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));
×
150
                                logger.error("View type \"{}\" is supported but its view is not implemented yet", view.getViewType().stringValue());
×
151
                            }
152
                        } else {
153
                            item.add(new Label("view", "<span class=\"negative\">Unsupported view type</span>").setEscapeModelStrings(false));
×
154
                            logger.error("Unsupported view type.");
×
155
                        }
156
                    }
×
157
                });
158
            }
×
159
        });
160

161
        add(new WebMarkupContainer("emptynotice").setVisible(showEmptyNotice && viewDisplays.isEmpty()));
×
162

163
        WebMarkupContainer footerSection = new WebMarkupContainer("footer-section");
×
164
        if (footerAdminButtons != null) {
×
165
            footerSection.add(new ButtonList("footer-buttons",
×
166
                    footerResource != null ? footerResource : resourceWithProfile,
×
167
                    null, null, footerAdminButtons));
168
        } else {
169
            footerSection.setVisible(false);
×
170
            footerSection.add(new Label("footer-buttons").setVisible(false));
×
171
        }
172
        add(footerSection);
×
173
    }
×
174

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