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

knowledgepixels / nanodash / 22660601761

04 Mar 2026 08:08AM UTC coverage: 15.94% (-0.09%) from 16.03%
22660601761

Pull #369

github

web-flow
Merge a19d3ced6 into 85e0af2dc
Pull Request #369: Replace "^" for view displays with dropdown menu

699 of 5319 branches covered (13.14%)

Branch coverage included in aggregate %.

1721 of 9863 relevant lines covered (17.45%)

2.39 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.ResourceWithProfile;
9
import com.knowledgepixels.nanodash.domain.Space;
10
import com.knowledgepixels.nanodash.domain.User;
11
import com.knowledgepixels.nanodash.vocabulary.KPXL_TERMS;
12
import org.apache.wicket.markup.html.WebMarkupContainer;
13
import org.apache.wicket.markup.html.basic.Label;
14
import org.apache.wicket.markup.html.link.AbstractLink;
15
import org.apache.wicket.markup.html.list.ListItem;
16
import org.apache.wicket.markup.html.list.ListView;
17
import org.apache.wicket.markup.html.panel.Panel;
18
import org.eclipse.rdf4j.model.IRI;
19
import org.nanopub.extra.services.QueryRef;
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
    public ViewList(String markupId, AbstractResourceWithProfile resourceWithProfile) {
32
        this(markupId, resourceWithProfile, null, null, null, null, null, true, null);
×
33
    }
×
34

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

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

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

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

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

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

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

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

85
        add(new ListView<List<ViewDisplay>>("groups", groups) {
×
86
            @Override
87
            protected void populateItem(ListItem<List<ViewDisplay>> groupItem) {
88
                List<ViewDisplay> group = groupItem.getModelObject();
×
89
                groupItem.add(new ListView<ViewDisplay>("views", group) {
×
90
                    @Override
91
                    protected void populateItem(ListItem<ViewDisplay> item) {
92
                        View view = item.getModelObject().getView();
×
93
                        Multimap<String, String> queryRefParams = ArrayListMultimap.create();
×
94
                        for (String p : view.getQuery().getPlaceholdersList()) {
×
95
                            String paramName = QueryParamField.getParamName(p);
×
96
                            if (paramName.equals(view.getQueryField())) {
×
97
                                queryRefParams.put(view.getQueryField(), id);
×
98
                                if (QueryParamField.isMultiPlaceholder(p) && resourceWithProfile instanceof Space space) {
×
99
                                    // TODO Support this also for maintained resources and users.
100
                                    for (String altId : space.getAltIDs()) {
×
101
                                        queryRefParams.put(view.getQueryField(), altId);
×
102
                                    }
×
103
                                }
104
                            } else if (paramName.equals(view.getQueryField() + "Namespace") && resourceWithProfile.getNamespace() != null) {
×
105
                                queryRefParams.put(view.getQueryField() + "Namespace", resourceWithProfile.getNamespace());
×
106
                            } else if (paramName.equals(view.getQueryField() + "Np")) {
×
107
                                if (!QueryParamField.isOptional(p) && npId == null) {
×
108
                                    queryRefParams.put(view.getQueryField() + "Np", "x:");
×
109
                                } else {
110
                                    queryRefParams.put(view.getQueryField() + "Np", npId);
×
111
                                }
112
                            } else if (paramName.equals("user_pubkey") && QueryParamField.isMultiPlaceholder(p) && resourceWithProfile instanceof Space space) {
×
113
                                for (IRI userId : space.getUsers()) {
×
114
                                    for (String memberHash : User.getUserData().getPubkeyhashes(userId, true)) {
×
115
                                        queryRefParams.put("user_pubkey", memberHash);
×
116
                                    }
×
117
                                }
×
118
                            } else if (paramName.equals("admin_pubkey") && QueryParamField.isMultiPlaceholder(p) && resourceWithProfile instanceof Space space) {
×
119
                                for (IRI adminId : space.getAdmins()) {
×
120
                                    for (String adminHash : User.getUserData().getPubkeyhashes(adminId, true)) {
×
121
                                        queryRefParams.put("admin_pubkey", adminHash);
×
122
                                    }
×
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
                                        .space(resourceWithProfile.getSpace())
×
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
                                        .profiledResource(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 {
157
                                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));
×
158
                                logger.error("View type \"{}\" is supported but its view is not implemented yet", view.getViewType().stringValue());
×
159
                            }
160
                        } else {
161
                            item.add(new Label("view", "<span class=\"negative\">Unsupported view type</span>").setEscapeModelStrings(false));
×
162
                            logger.error("Unsupported view type.");
×
163
                        }
164
                    }
×
165
                });
166
            }
×
167
        });
168

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

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

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