• 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/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.domain.User;
10
import com.knowledgepixels.nanodash.vocabulary.KPXL_TERMS;
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
                                for (IRI userId : space.getUsers()) {
×
113
                                    for (String memberHash : User.getUserData().getPubkeyhashes(userId, true)) {
×
114
                                        queryRefParams.put("user_pubkey", memberHash);
×
115
                                    }
×
116
                                }
×
117
                            } else if (paramName.equals("admin_pubkey") && QueryParamField.isMultiPlaceholder(p) && resourceWithProfile instanceof Space space) {
×
118
                                for (IRI adminId : space.getAdmins()) {
×
119
                                    for (String adminHash : User.getUserData().getPubkeyhashes(adminId, true)) {
×
120
                                        queryRefParams.put("admin_pubkey", adminHash);
×
121
                                    }
×
122
                                }
×
123
                            } else if (!QueryParamField.isOptional(p)) {
×
124
                                item.add(new Label("view", "<span class=\"negative\">Error: Query has non-optional parameter</span>").setEscapeModelStrings(false));
×
125
                                logger.error("Error: Query has non-optional parameter: {} {}", view.getQuery().getQueryId(), p);
×
126
                                return;
×
127
                            }
128
                        }
×
129
                        QueryRef queryRef = new QueryRef(view.getQuery().getQueryId(), queryRefParams);
×
130
                        if (view.getViewType() != null && View.getSupportedViewTypes().contains(view.getViewType())) {
×
131
                            if (view.getViewType().equals(KPXL_TERMS.LIST_VIEW)) {
×
132
                                item.add(QueryResultListBuilder.create("view", queryRef, item.getModelObject())
×
133
                                        .resourceWithProfile(resourceWithProfile)
×
134
                                        .pageResource(resourceWithProfile)
×
135
                                        .id(id)
×
136
                                        .contextId(resourceWithProfile.getId())
×
137
                                        .build());
×
138
                            } else if (view.getViewType().equals(KPXL_TERMS.TABULAR_VIEW)) {
×
139
                                item.add(QueryResultTableBuilder.create("view", queryRef, item.getModelObject())
×
140
                                        .resourceWithProfile(resourceWithProfile)
×
141
                                        .contextId(resourceWithProfile.getId())
×
142
                                        .id(id)
×
143
                                        .build());
×
144
                            } else if (view.getViewType().equals(KPXL_TERMS.PLAIN_PARAGRAPH_VIEW)) {
×
145
                                item.add(QueryResultPlainParagraphBuilder.create("view", queryRef, item.getModelObject())
×
146
                                        .pageResource(resourceWithProfile)
×
147
                                        .contextId(resourceWithProfile.getId())
×
148
                                        .id(id)
×
149
                                        .build());
×
150
                            } else if (view.getViewType().equals(KPXL_TERMS.NANOPUB_SET_VIEW)) {
×
151
                                item.add(QueryResultNanopubSetBuilder.create("view", queryRef, item.getModelObject())
×
152
                                        .pageResource(resourceWithProfile)
×
153
                                        .contextId(resourceWithProfile.getId())
×
154
                                        .build());
×
155
                            } else {
156
                                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));
×
157
                                logger.error("View type \"{}\" is supported but its view is not implemented yet", view.getViewType().stringValue());
×
158
                            }
159
                        } else {
160
                            item.add(new Label("view", "<span class=\"negative\">Unsupported view type</span>").setEscapeModelStrings(false));
×
161
                            logger.error("Unsupported view type.");
×
162
                        }
163
                    }
×
164
                });
165
            }
×
166
        });
167

168
        add(new WebMarkupContainer("emptynotice").setVisible(showEmptyNotice && viewDisplays.isEmpty()));
×
169

170
        WebMarkupContainer footerSection = new WebMarkupContainer("footer-section");
×
171
        if (footerAdminButtons != null) {
×
172
            footerSection.add(new ButtonList("footer-buttons",
×
173
                    footerResource != null ? footerResource : resourceWithProfile,
×
174
                    null, null, footerAdminButtons));
175
        } else {
176
            footerSection.setVisible(false);
×
177
            footerSection.add(new Label("footer-buttons").setVisible(false));
×
178
        }
179
        add(footerSection);
×
180
    }
×
181

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