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

knowledgepixels / nanodash / 17925397785

22 Sep 2025 06:52PM UTC coverage: 13.484% (-0.08%) from 13.566%
17925397785

push

github

web-flow
Merge pull request #259 from knowledgepixels/257-update-listpage

Update `ListPage`: add filtering section for filtering by type, user, date

436 of 4082 branches covered (10.68%)

Branch coverage included in aggregate %.

1124 of 7487 relevant lines covered (15.01%)

0.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
src/main/java/com/knowledgepixels/nanodash/page/UserPage.java
1
package com.knowledgepixels.nanodash.page;
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.component.ItemListElement;
7
import com.knowledgepixels.nanodash.component.ItemListPanel;
8
import com.knowledgepixels.nanodash.component.NanopubResults;
9
import com.knowledgepixels.nanodash.component.TitleBar;
10
import org.apache.wicket.Component;
11
import org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel;
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.link.ExternalLink;
15
import org.apache.wicket.request.flow.RedirectToUrlException;
16
import org.apache.wicket.request.mapper.parameter.PageParameters;
17
import org.eclipse.rdf4j.model.IRI;
18
import org.nanopub.extra.services.ApiResponse;
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

26
/**
27
 * Page that shows a user profile, including their nanopubs and stats.
28
 */
29
public class UserPage extends NanodashPage {
30

31
    private static final Logger logger = LoggerFactory.getLogger(UserPage.class);
×
32

33
    /**
34
     * The mount path for this page.
35
     */
36
    public static final String MOUNT_PATH = "/user";
37

38
    /**
39
     * {@inheritDoc}
40
     */
41
    @Override
42
    public String getMountPath() {
43
        return MOUNT_PATH;
×
44
    }
45

46
    private IRI userIri;
47
    private String pubkeyHashes = "";
×
48

49
    public UserPage(final PageParameters parameters) {
50
        super(parameters);
×
51

52
        if (parameters.get("id") == null) throw new RedirectToUrlException(ProfilePage.MOUNT_PATH);
×
53
        final String userIriString = parameters.get("id").toString();
×
54
        userIri = Utils.vf.createIRI(userIriString);
×
55
        //NanodashSession session = NanodashSession.get();
56

57
        for (String pk : User.getPubkeyhashes(userIri, null)) {
×
58
            pubkeyHashes += " " + pk;
×
59
        }
×
60
        if (!pubkeyHashes.isEmpty()) pubkeyHashes = pubkeyHashes.substring(1);
×
61

62
        String pageType = "users";
×
63
        add(new TitleBar("titlebar", this, pageType));
×
64

65
        final String displayName = User.getShortDisplayName(userIri);
×
66
        add(new Label("pagetitle", displayName + " (user) | nanodash"));
×
67
        add(new Label("username", displayName));
×
68

69
        add(new ExternalLink("fullid", userIriString, userIriString));
×
70

71
        add(new BookmarkablePageLink<Void>("showprofile", ProfilePage.class).setVisible(userIri.equals(NanodashSession.get().getUserIri())));
×
72

73
//                final Map<String,String> statsParams = new HashMap<>();
74
//                final String statsQueryName;
75
//                if (pubkeyHashes.isEmpty()) {
76
//                        statsQueryName = "get-user-stats-from-userid";
77
//                        statsParams.put("userid", userIriString);
78
//                } else {
79
//                        statsQueryName = "get-user-stats-from-pubkeys";
80
//                        statsParams.put("userid", userIriString);
81
//                        statsParams.put("pubkeyhashes", pubkeyHashes);
82
//                } 
83
//                Map<String,String> statsMap = ApiCache.retrieveMap(statsQueryName, statsParams);
84
//                if (statsMap != null) {
85
//                        add(new StatsPanel("stats", userIriString, pubkeyHashes, statsMap));
86
//                } else {
87
//                        add(new AjaxLazyLoadPanel<Component>("stats") {
88
//        
89
//                                @Override
90
//                                public Component getLazyLoadComponent(String markupId) {
91
//                                        Map<String,String> m = null;
92
//                                        while (true) {
93
//                                                try {
94
//                                                        Thread.sleep(500);
95
//                                                } catch (InterruptedException ex) {
96
//                                                        logger.error();
97
//                                                }
98
//                                                if (!ApiCache.isRunning(statsQueryName, statsParams)) {
99
//                                                        m = ApiCache.retrieveMap(statsQueryName, statsParams);
100
//                                                        if (m != null) break;
101
//                                                }
102
//                                        }
103
//                                        return new StatsPanel(markupId, userIriString, pubkeyHashes, m);
104
//                                }
105
//
106
//                                @Override
107
//                                protected void onContentLoaded(Component content, Optional<AjaxRequestTarget> target) {
108
//                                        super.onContentLoaded(content, target);
109
//                                        if (target.get() != null) target.get().appendJavaScript("updateElements();");
110
//                                }
111
//        
112
//                        });
113
//                }
114

115
        add(new BookmarkablePageLink<Void>("showchannel", ListPage.class, new PageParameters().add("userid", userIriString)));
×
116

117
        final Multimap<String, String> params = ArrayListMultimap.create();
×
118
        final String queryName;
119
        if (pubkeyHashes.isEmpty()) {
×
120
            queryName = "get-latest-nanopubs-from-userid";
×
121
            params.put("userid", userIri.stringValue());
×
122
        } else {
123
            queryName = "get-latest-nanopubs-from-pubkeys";
×
124
            params.put("pubkeyhashes", pubkeyHashes);
×
125
            params.put("userid", userIri.stringValue());
×
126
        }
127
        final QueryRef queryRef = new QueryRef(queryName, params);
×
128
        ApiResponse response = ApiCache.retrieveResponse(queryRef);
×
129
        if (response != null) {
×
130
            add(makeNanopubResultComponent("latestnanopubs", response));
×
131
        } else {
132
            add(new AjaxLazyLoadPanel<Component>("latestnanopubs") {
×
133

134
                @Override
135
                public Component getLazyLoadComponent(String markupId) {
136
                    ApiResponse r = null;
×
137
                    while (true) {
138
                        try {
139
                            Thread.sleep(500);
×
140
                        } catch (InterruptedException ex) {
×
141
                            logger.error("Thread interrupted while waiting for API response", ex);
×
142
                        }
×
143
                        if (!ApiCache.isRunning(queryRef)) {
×
144
                            r = ApiCache.retrieveResponse(queryRef);
×
145
                            if (r != null) break;
×
146
                        }
147
                    }
148
                    return makeNanopubResultComponent(markupId, r);
×
149
                }
150

151
//                                @Override
152
//                                protected void onContentLoaded(Component content, Optional<AjaxRequestTarget> target) {
153
//                                        super.onContentLoaded(content, target);
154
//                                        if (target.get() != null) target.get().appendJavaScript("updateElements();");
155
//                                }
156

157
            });
158
        }
159

160
        add(new ItemListPanel<Space>(
×
161
                "spaces",
162
                "Spaces",
163
                () -> Space.isLoaded(),
×
164
                () -> {
165
                    List<Space> spaces = new ArrayList<>();
×
166
                    for (Space space : Space.getSpaceList()) {
×
167
                        if (space.isMember(userIri)) spaces.add(space);
×
168
                    }
×
169
                    return spaces;
×
170
                },
171
                (s) -> new ItemListElement("item", SpacePage.class, new PageParameters().add("id", s.getId()), s.getLabel(), "(" + s.getTypeLabel() + ")")
×
172
        ));
173
    }
×
174

175
    private static Component makeNanopubResultComponent(String markupId, ApiResponse response) {
176
        if (response.getData().isEmpty()) {
×
177
            return new Label(markupId, "(none)");
×
178
        } else {
179
            return NanopubResults.fromApiResponse(markupId, response);
×
180
        }
181
    }
182

183
    /**
184
     * <p>hasAutoRefreshEnabled.</p>
185
     *
186
     * @return a boolean
187
     */
188
    protected boolean hasAutoRefreshEnabled() {
189
        return true;
×
190
    }
191

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