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

knowledgepixels / nanodash / 18188189824

02 Oct 2025 08:50AM UTC coverage: 13.724% (-0.4%) from 14.135%
18188189824

push

github

tkuhn
feat(ActivityPanel): Show activity panel on user pages

446 of 4114 branches covered (10.84%)

Branch coverage included in aggregate %.

1155 of 7552 relevant lines covered (15.29%)

0.68 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.ActivityPanel;
7
import com.knowledgepixels.nanodash.component.ApiResultComponent;
8
import com.knowledgepixels.nanodash.component.ItemListElement;
9
import com.knowledgepixels.nanodash.component.ItemListPanel;
10
import com.knowledgepixels.nanodash.component.NanopubResults;
11
import com.knowledgepixels.nanodash.component.TitleBar;
12
import org.apache.wicket.Component;
13
import org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel;
14
import org.apache.wicket.markup.html.basic.Label;
15
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
16
import org.apache.wicket.markup.html.link.ExternalLink;
17
import org.apache.wicket.request.flow.RedirectToUrlException;
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.QueryRef;
22
import org.slf4j.Logger;
23
import org.slf4j.LoggerFactory;
24

25
import java.util.ArrayList;
26
import java.util.List;
27

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

33
    private static final Logger logger = LoggerFactory.getLogger(UserPage.class);
×
34

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

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

48
    private IRI userIri;
49
    private String pubkeyHashes = "";
×
50

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

60
        if (parameters.get("id") == null) throw new RedirectToUrlException(ProfilePage.MOUNT_PATH);
×
61
        final String userIriString = parameters.get("id").toString();
×
62
        userIri = Utils.vf.createIRI(userIriString);
×
63
        //NanodashSession session = NanodashSession.get();
64

65
        for (String pk : User.getPubkeyhashes(userIri, null)) {
×
66
            pubkeyHashes += " " + pk;
×
67
        }
×
68
        if (!pubkeyHashes.isEmpty()) pubkeyHashes = pubkeyHashes.substring(1);
×
69

70
        String pageType = "users";
×
71
        add(new TitleBar("titlebar", this, pageType));
×
72

73
        final String displayName = User.getShortDisplayName(userIri);
×
74
        add(new Label("pagetitle", displayName + " (user) | nanodash"));
×
75
        add(new Label("username", displayName));
×
76

77
        add(new ExternalLink("fullid", userIriString, userIriString));
×
78

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

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

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

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

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

159
//                                @Override
160
//                                protected void onContentLoaded(Component content, Optional<AjaxRequestTarget> target) {
161
//                                        super.onContentLoaded(content, target);
162
//                                        if (target.get() != null) target.get().appendJavaScript("updateElements();");
163
//                                }
164

165
            });
166
        }
167

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

182
        if (pubkeyHashes.isEmpty()) {
×
183
            add(new Label("activity", "<span class=\"negative\">Activity cannot be shown for this user due to missing user introduction.</span>").setEscapeModelStrings(false));
×
184
        } else {
185
            final QueryRef activityQueryRef = new QueryRef("get-monthly-type-overview-by-pubkeys");
×
186
            for (String pk : pubkeyHashes.split(" ")) {
×
187
                activityQueryRef.getParams().put("pubkey", pk);
×
188
            }
189
            ApiResponse activityQueryResponse = ApiCache.retrieveResponse(activityQueryRef);
×
190
            if (activityQueryResponse != null) {
×
191
                if (activityQueryResponse.getData().isEmpty()) {
×
192
                    add(new Label("activity", "<em>No recent activity to show for this user.</em>").setEscapeModelStrings(false));
×
193
                } else {
194
                    add(new ActivityPanel("activity", activityQueryResponse));
×
195
                }
196
            } else {
197
                add(new ApiResultComponent("activity", activityQueryRef) {
×
198
    
199
                    @Override
200
                    public Component getApiResultComponent(String markupId, ApiResponse response) {
201
                        if (response.getData().isEmpty()) {
×
202
                            return new Label(markupId, "<em>No recent activity to show for this user.</em>").setEscapeModelStrings(false);
×
203
                        } else {
204
                            return new ActivityPanel(markupId, response);
×
205
                        }
206
                    }
207
                });
208
    
209
            }
210
        }
211
    }
×
212

213
    private static Component makeNanopubResultComponent(String markupId, ApiResponse response) {
214
        if (response.getData().isEmpty()) {
×
215
            return new Label(markupId, "(none)");
×
216
        } else {
217
            return NanopubResults.fromApiResponse(markupId, response);
×
218
        }
219
    }
220

221
    /**
222
     * <p>hasAutoRefreshEnabled.</p>
223
     *
224
     * @return a boolean
225
     */
226
    protected boolean hasAutoRefreshEnabled() {
227
        return true;
×
228
    }
229

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