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

knowledgepixels / nanodash / 17545896063

08 Sep 2025 09:16AM UTC coverage: 11.975% (+0.003%) from 11.972%
17545896063

push

github

tkuhn
Sort user list

334 of 3876 branches covered (8.62%)

Branch coverage included in aggregate %.

961 of 6938 relevant lines covered (13.85%)

0.61 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/UserList.java
1
package com.knowledgepixels.nanodash.component;
2

3
import java.util.ArrayList;
4
import java.util.Comparator;
5
import java.util.HashMap;
6
import java.util.List;
7
import java.util.Map;
8

9
import org.apache.wicket.ajax.markup.html.navigation.paging.AjaxPagingNavigator;
10
import org.apache.wicket.extensions.markup.html.repeater.data.table.NavigatorLabel;
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.BookmarkablePageLink;
14
import org.apache.wicket.markup.html.panel.Panel;
15
import org.apache.wicket.markup.repeater.Item;
16
import org.apache.wicket.markup.repeater.data.DataView;
17
import org.apache.wicket.markup.repeater.data.ListDataProvider;
18
import org.apache.wicket.request.mapper.parameter.PageParameters;
19
import org.eclipse.rdf4j.model.IRI;
20
import org.nanopub.extra.services.ApiResponse;
21
import org.nanopub.extra.services.ApiResponseEntry;
22

23
import com.knowledgepixels.nanodash.User;
24
import com.knowledgepixels.nanodash.Utils;
25
import com.knowledgepixels.nanodash.page.UserPage;
26

27
/**
28
 * A panel that displays a list of users with links to their user pages.
29
 * Optionally, it can also display notes associated with each user.
30
 */
31
public class UserList extends Panel {
32

33
    private static final long serialVersionUID = 1L;
34

35
    /**
36
     * Constructor for UserList with a list of user IRI objects.
37
     *
38
     * @param id    the component id
39
     * @param users a list of user IRI objects
40
     */
41
    public UserList(String id, List<IRI> users, boolean sorted) {
42
        super(id);
×
43
        setOutputMarkupId(true);
×
44
        init(users, sorted);
×
45
    }
×
46

47
    /**
48
     * Constructor for UserList that initializes from an ApiResponse.
49
     *
50
     * @param id        the component id
51
     * @param resp      the ApiResponse containing user data
52
     * @param userIdKey the key in the ApiResponse entries that contains the user IRI
53
     */
54
    public UserList(String id, ApiResponse resp, String userIdKey, boolean sorted) {
55
        super(id);
×
56
        setOutputMarkupId(true);
×
57
        List<IRI> users = new ArrayList<>();
×
58
        for (ApiResponseEntry e : resp.getData()) {
×
59
            users.add(Utils.vf.createIRI(e.get(userIdKey)));
×
60
        }
×
61
        init(users, sorted);
×
62
    }
×
63

64
    private void init(List<IRI> users, boolean sorted) {
65
        final Map<IRI, String> userDisplayNameMap = new HashMap<>();
×
66
        for (IRI userIri : users) {
×
67
            userDisplayNameMap.put(userIri, User.getShortDisplayName(userIri));
×
68
        }
×
69
        if (sorted) {
×
70
            users.sort(new UserComparator(userDisplayNameMap));
×
71
        }
72
        DataView<IRI> dataView = new DataView<>("userlist", new ListDataProvider<IRI>(users)) {
×
73

74
            private static final long serialVersionUID = 1L;
75

76
            @Override
77
            protected void populateItem(Item<IRI> item) {
78
                IRI userIri = item.getModelObject();
×
79
                PageParameters params = new PageParameters();
×
80
                params.add("id", userIri);
×
81
                BookmarkablePageLink<Void> l = new BookmarkablePageLink<Void>("userlink", UserPage.class, params);
×
82
                l.add(new Label("linktext", userDisplayNameMap.get(userIri)));
×
83
                item.add(l);
×
84
            }
×
85

86
        };
87
        dataView.setItemsPerPage(10);
×
88
        dataView.setOutputMarkupId(true);
×
89
        add(dataView);
×
90

91
        WebMarkupContainer navigation = new WebMarkupContainer("navigation");
×
92
        navigation.add(new NavigatorLabel("navigatorLabel", dataView));
×
93
        AjaxPagingNavigator pagingNavigator = new AjaxPagingNavigator("navigator", dataView);
×
94
        navigation.setVisible(dataView.getPageCount() > 1);
×
95
        navigation.add(pagingNavigator);
×
96
        add(navigation);
×
97
    }
×
98

99
    private static class UserComparator implements Comparator<IRI> {
100

101
        private Map<IRI, String> userDisplayNameMap;
102
    
103
        UserComparator(Map<IRI, String> userDisplayNameMap) {
×
104
            this.userDisplayNameMap = userDisplayNameMap;
×
105
        }
×
106

107
        @Override
108
        public int compare(IRI userIri1, IRI userIri2) {
109
            String userName1 = userDisplayNameMap.get(userIri1);
×
110
            String userName2 = userDisplayNameMap.get(userIri2);
×
111
            return userName1.compareTo(userName2);
×
112
        }
113
        
114
    }
115

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