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

knowledgepixels / nanodash / 17380144000

01 Sep 2025 02:12PM UTC coverage: 12.03% (+0.05%) from 11.978%
17380144000

push

github

ashleycaselli
refactor: replace printStackTrace with logger.error for better error handling

330 of 3850 branches covered (8.57%)

Branch coverage included in aggregate %.

958 of 6857 relevant lines covered (13.97%)

0.62 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.knowledgepixels.nanodash.ApiCache;
4
import com.knowledgepixels.nanodash.NanodashSession;
5
import com.knowledgepixels.nanodash.User;
6
import com.knowledgepixels.nanodash.Utils;
7
import com.knowledgepixels.nanodash.component.NanopubResults;
8
import com.knowledgepixels.nanodash.component.TitleBar;
9
import org.apache.wicket.Component;
10
import org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel;
11
import org.apache.wicket.markup.html.basic.Label;
12
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
13
import org.apache.wicket.markup.html.link.ExternalLink;
14
import org.apache.wicket.request.flow.RedirectToUrlException;
15
import org.apache.wicket.request.mapper.parameter.PageParameters;
16
import org.eclipse.rdf4j.model.IRI;
17
import org.nanopub.extra.services.ApiResponse;
18
import org.slf4j.Logger;
19
import org.slf4j.LoggerFactory;
20

21
import java.util.HashMap;
22
import java.util.Map;
23

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

29
    private static final long serialVersionUID = 1L;
30
    private static final Logger logger = LoggerFactory.getLogger(UserPage.class);
×
31

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

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

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

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

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

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

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

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

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

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

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

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

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

134
                private static final long serialVersionUID = 1L;
135

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

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

159
            });
160
        }
161

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

168
                private static final long serialVersionUID = 1L;
169

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

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

193
            });
194
        }
195
    }
×
196

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

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

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