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

knowledgepixels / nanodash / 17518110100

06 Sep 2025 06:34PM UTC coverage: 11.955% (-0.1%) from 12.094%
17518110100

push

github

tkuhn
Undo custom AjaxLazyLoadPanel to fix paging navigation

334 of 3876 branches covered (8.62%)

Branch coverage included in aggregate %.

958 of 6931 relevant lines covered (13.82%)

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/page/UserPage.java
1
package com.knowledgepixels.nanodash.page;
2

3
import java.util.HashMap;
4
import java.util.Map;
5

6
import org.apache.wicket.Component;
7
import org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel;
8
import org.apache.wicket.markup.html.basic.Label;
9
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
10
import org.apache.wicket.markup.html.link.ExternalLink;
11
import org.apache.wicket.request.flow.RedirectToUrlException;
12
import org.apache.wicket.request.mapper.parameter.PageParameters;
13
import org.eclipse.rdf4j.model.IRI;
14
import org.nanopub.extra.services.ApiResponse;
15
import org.slf4j.Logger;
16
import org.slf4j.LoggerFactory;
17

18
import com.knowledgepixels.nanodash.ApiCache;
19
import com.knowledgepixels.nanodash.NanodashSession;
20
import com.knowledgepixels.nanodash.User;
21
import com.knowledgepixels.nanodash.Utils;
22
import com.knowledgepixels.nanodash.component.NanopubResults;
23
import com.knowledgepixels.nanodash.component.TitleBar;
24

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

30
    private static final long serialVersionUID = 1L;
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
//                                private static final long serialVersionUID = 1L;
90
//        
91
//                                @Override
92
//                                public Component getLazyLoadComponent(String markupId) {
93
//                                        Map<String,String> m = null;
94
//                                        while (true) {
95
//                                                try {
96
//                                                        Thread.sleep(500);
97
//                                                } catch (InterruptedException ex) {
98
//                                                        logger.error();
99
//                                                }
100
//                                                if (!ApiCache.isRunning(statsQueryName, statsParams)) {
101
//                                                        m = ApiCache.retrieveMap(statsQueryName, statsParams);
102
//                                                        if (m != null) break;
103
//                                                }
104
//                                        }
105
//                                        return new StatsPanel(markupId, userIriString, pubkeyHashes, m);
106
//                                }
107
//
108
//                                @Override
109
//                                protected void onContentLoaded(Component content, Optional<AjaxRequestTarget> target) {
110
//                                        super.onContentLoaded(content, target);
111
//                                        if (target.get() != null) target.get().appendJavaScript("updateElements();");
112
//                                }
113
//        
114
//                        });
115
//                }
116

117
        add(new BookmarkablePageLink<Void>("showchannel", ChannelPage.class, new PageParameters().add("id", userIriString)));
×
118

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

135
                private static final long serialVersionUID = 1L;
136

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

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

160
            });
161
        }
162

163
        ApiResponse acceptedNanopubList = ApiCache.retrieveResponse("get-accepted-nanopubs-by-author", "author", userIriString);
×
164
        if (acceptedNanopubList != null) {
×
165
            add(makeNanopubResultComponent("latestaccepted", acceptedNanopubList));
×
166
        } else {
167
            add(new AjaxLazyLoadPanel<Component>("latestaccepted") {
×
168

169
                private static final long serialVersionUID = 1L;
170

171
                @Override
172
                public Component getLazyLoadComponent(String markupId) {
173
                    ApiResponse r = null;
×
174
                    while (true) {
175
                        try {
176
                            Thread.sleep(500);
×
177
                        } catch (InterruptedException ex) {
×
178
                            logger.error("Thread interrupted while waiting for API response", ex);
×
179
                        }
×
180
                        if (!ApiCache.isRunning("get-accepted-nanopubs-by-author", "author", userIriString)) {
×
181
                            r = ApiCache.retrieveResponse("get-accepted-nanopubs-by-author", "author", userIriString);
×
182
                            if (r != null) break;
×
183
                        }
184
                    }
185
                    return makeNanopubResultComponent(markupId, r);
×
186
                }
187

188
//                                @Override
189
//                                protected void onContentLoaded(Component content, Optional<AjaxRequestTarget> target) {
190
//                                        super.onContentLoaded(content, target);
191
//                                        if (target.get() != null) target.get().appendJavaScript("updateElements();");
192
//                                }
193

194
            });
195
        }
196
    }
×
197

198
    private static Component makeNanopubResultComponent(String markupId, ApiResponse response) {
199
        if (response.getData().isEmpty()) {
×
200
            return new Label(markupId, "(none)");
×
201
        } else {
202
            return NanopubResults.fromApiResponse(markupId, response, 5);
×
203
        }
204
    }
205

206
    /**
207
     * <p>hasAutoRefreshEnabled.</p>
208
     *
209
     * @return a boolean
210
     */
211
    protected boolean hasAutoRefreshEnabled() {
212
        return true;
×
213
    }
214

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