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

knowledgepixels / nanodash / 19772182304

28 Nov 2025 07:14PM UTC coverage: 13.901% (-0.2%) from 14.051%
19772182304

push

github

tkuhn
feat(UserPage): Add support for view displays

525 of 4894 branches covered (10.73%)

Branch coverage included in aggregate %.

1398 of 8940 relevant lines covered (15.64%)

0.69 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.*;
7
import org.apache.wicket.Component;
8
import org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel;
9
import org.apache.wicket.markup.html.basic.Label;
10
import org.apache.wicket.markup.html.link.AbstractLink;
11
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
12
import org.apache.wicket.model.Model;
13
import org.apache.wicket.request.flow.RedirectToUrlException;
14
import org.apache.wicket.request.mapper.parameter.PageParameters;
15
import org.eclipse.rdf4j.model.IRI;
16
import org.nanopub.extra.services.ApiResponse;
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

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 Logger logger = LoggerFactory.getLogger(UserPage.class);
×
30

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

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

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

47
    /**
48
     * Constructor for UserPage.
49
     *
50
     * @param parameters Page parameters, must include "id" with the user IRI.
51
     */
52
    public UserPage(final PageParameters parameters) {
53
        super(parameters);
×
54
        setOutputMarkupId(true);
×
55

56
        if (parameters.get("id") == null) throw new RedirectToUrlException(ProfilePage.MOUNT_PATH);
×
57
        final String userIriString = parameters.get("id").toString();
×
58
        userIri = Utils.vf.createIRI(userIriString);
×
59
        //NanodashSession session = NanodashSession.get();
60

61
        for (String pk : User.getPubkeyhashes(userIri, null)) {
×
62
            pubkeyHashes += " " + pk;
×
63
        }
×
64
        if (!pubkeyHashes.isEmpty()) pubkeyHashes = pubkeyHashes.substring(1);
×
65

66
        String pageType = "users";
×
67
        add(new TitleBar("titlebar", this, pageType));
×
68

69
        final String displayName = User.getShortDisplayName(userIri);
×
70
        add(new Label("pagetitle", displayName + " (user) | nanodash"));
×
71
        add(new Label("username", displayName));
×
72

73
        add(new BookmarkablePageLink<Void>("fullid", ExplorePage.class, parameters.set("label", displayName)).setBody(Model.of(userIriString)));
×
74

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

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

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

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

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

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

161
            });
162
        }
163

164
        Space.triggerAllDataUpdates();
×
165
        add(new ItemListPanel<Space>(
×
166
                "spaces",
167
                "Spaces",
168
                () -> Space.areAllSpacesInitialized(),
×
169
                () -> {
170
                    List<Space> spaces = new ArrayList<>();
×
171
                    for (Space space : Space.getSpaceList()) {
×
172
                        if (space.isMember(userIri)) spaces.add(space);
×
173
                    }
×
174
                    return spaces;
×
175
                },
176
                (s) -> new ItemListElement("item", SpacePage.class, new PageParameters().set("id", s.getId()), s.getLabel(), "(" + s.getTypeLabel() + ")", null)
×
177
        ));
178

179
        if (pubkeyHashes.isEmpty()) {
×
180
            add(new Label("activity", "<span class=\"negative\">Activity cannot be shown for this user due to missing user introduction.</span>").setEscapeModelStrings(false));
×
181
        } else {
182
            final QueryRef activityQueryRef = new QueryRef("get-monthly-type-overview-by-pubkeys");
×
183
            for (String pk : pubkeyHashes.split(" ")) {
×
184
                activityQueryRef.getParams().put("pubkey", pk);
×
185
            }
186
            ApiResponse activityQueryResponse = ApiCache.retrieveResponse(activityQueryRef);
×
187
            if (activityQueryResponse != null) {
×
188
                if (activityQueryResponse.getData().isEmpty()) {
×
189
                    add(new Label("activity", "<em>No recent activity to show for this user.</em>").setEscapeModelStrings(false));
×
190
                } else {
191
                    add(new ActivityPanel("activity", activityQueryResponse));
×
192
                }
193
            } else {
194
                add(new ApiResultComponent("activity", activityQueryRef) {
×
195

196
                    @Override
197
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
198
                        if (response.getData().isEmpty()) {
×
199
                            return new Label(markupId, "<em>No recent activity to show for this user.</em>").setEscapeModelStrings(false);
×
200
                        } else {
201
                            return new ActivityPanel(markupId, response);
×
202
                        }
203
                    }
204
                });
205

206
            }
207
        }
208

209
        final List<AbstractLink> viewButtons = new ArrayList<>();
×
210
        AbstractLink addViewButton = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, new PageParameters()
×
211
                .set("template", "https://w3id.org/np/RAxERE0cQ9jLQZ5VjeA-1v3XnE9ugxLpFG8vpkAd5FqHE")
×
212
                .set("template-version", "latest")
×
213
                .set("param_resource", userIriString)
×
214
                .set("context", userIriString)
×
215
            );
216
        addViewButton.setBody(Model.of("+ view"));
×
217
        viewButtons.add(addViewButton);
×
218

219
        IndividualAgent individualAgent = IndividualAgent.get(userIriString);
×
220
        if (individualAgent.isDataInitialized()) {
×
221
            add(new ViewList("views", individualAgent));
×
222
            add(new ButtonList("view-buttons", individualAgent, null, null, viewButtons));
×
223
        } else {
224
            add(new AjaxLazyLoadPanel<Component>("views") {
×
225
    
226
                @Override
227
                public Component getLazyLoadComponent(String markupId) {
228
                    return new ViewList(markupId, individualAgent);
×
229
                }
230
    
231
                @Override
232
                protected boolean isContentReady() {
233
                    return individualAgent.isDataInitialized();
×
234
                }
235
    
236
            });
237
            add(new AjaxLazyLoadPanel<Component>("view-buttons") {
×
238
    
239
                @Override
240
                public Component getLazyLoadComponent(String markupId) {
241
                    return new ButtonList(markupId, individualAgent, null, null, viewButtons);
×
242
                }
243
    
244
                @Override
245
                protected boolean isContentReady() {
246
                    return individualAgent.isDataInitialized();
×
247
                }
248

249
                public Component getLoadingComponent(String id) {
250
                    return new Label(id).setVisible(false);
×
251
                };
252
    
253
            });
254
        }
255
    }
×
256

257
    private static Component makeNanopubResultComponent(String markupId, ApiResponse response) {
258
        if (response.getData().isEmpty()) {
×
259
            return new Label(markupId, "(none)");
×
260
        } else {
261
            return NanopubResults.fromApiResponse(markupId, response, 5);
×
262
        }
263
    }
264

265
    /**
266
     * <p>hasAutoRefreshEnabled.</p>
267
     *
268
     * @return a boolean
269
     */
270
    protected boolean hasAutoRefreshEnabled() {
271
        return true;
×
272
    }
273

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