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

knowledgepixels / nanodash / 22618039211

03 Mar 2026 10:05AM UTC coverage: 16.058% (+0.2%) from 15.884%
22618039211

Pull #365

github

web-flow
Merge 1e7e700f0 into a8c4b4a77
Pull Request #365: Refactor of `ResourceWithProfile` and related classes

699 of 5287 branches covered (13.22%)

Branch coverage included in aggregate %.

1721 of 9783 relevant lines covered (17.59%)

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

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

25
public class ViewList extends Panel {
26

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

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

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

37
    public ViewList(String markupId, AbstractResourceWithProfile resourceWithProfile, String partId, String nanopubId, Set<IRI> partClasses, AbstractResourceWithProfile footerResource, List<AbstractLink> footerAdminButtons) {
38
        super(markupId);
×
39

40
        final String id = (partId == null ? resourceWithProfile.getId() : partId);
×
41
        final String npId = (nanopubId == null ? resourceWithProfile.getNanopubId() : nanopubId);
×
42
        final List<ViewDisplay> viewDisplays;
43
        if (partId == null) {
×
44
            viewDisplays = resourceWithProfile.getTopLevelViewDisplays();
×
45
        } else {
46
            viewDisplays = resourceWithProfile.getPartLevelViewDisplays(partId, partClasses);
×
47
        }
48

49
        // Group viewDisplays by the first segment of their structural position (e.g. "4" from "4.4.1.papers")
50
        List<List<ViewDisplay>> groups = new ArrayList<>();
×
51
        String currentGroupKey = null;
×
52
        List<ViewDisplay> currentGroup = null;
×
53
        for (ViewDisplay vd : viewDisplays) {
×
54
            String pos = vd.getStructuralPosition();
×
55
            int firstDot = pos.indexOf('.');
×
56
            String key = firstDot > 0 ? pos.substring(0, firstDot) : pos;
×
57
            if (!key.equals(currentGroupKey)) {
×
58
                currentGroup = new ArrayList<>();
×
59
                groups.add(currentGroup);
×
60
                currentGroupKey = key;
×
61
            }
62
            currentGroup.add(vd);
×
63
        }
×
64

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

146
        add(new WebMarkupContainer("emptynotice").setVisible(viewDisplays.isEmpty()));
×
147

148
        WebMarkupContainer footerSection = new WebMarkupContainer("footer-section");
×
149
        if (footerAdminButtons != null) {
×
150
            footerSection.add(new ButtonList("footer-buttons",
×
151
                    footerResource != null ? footerResource : resourceWithProfile,
×
152
                    null, null, footerAdminButtons));
153
        } else {
154
            footerSection.setVisible(false);
×
155
            footerSection.add(new Label("footer-buttons").setVisible(false));
×
156
        }
157
        add(footerSection);
×
158
    }
×
159

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