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

knowledgepixels / nanodash / 17736678926

15 Sep 2025 02:33PM UTC coverage: 13.709% (-0.07%) from 13.782%
17736678926

push

github

tkuhn
feat: Show related spaces on user pages

433 of 3994 branches covered (10.84%)

Branch coverage included in aggregate %.

1112 of 7276 relevant lines covered (15.28%)

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 java.util.ArrayList;
4
import java.util.HashMap;
5
import java.util.List;
6
import java.util.Map;
7

8
import org.apache.wicket.Component;
9
import org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel;
10
import org.apache.wicket.markup.html.basic.Label;
11
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
12
import org.apache.wicket.markup.html.link.ExternalLink;
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.slf4j.Logger;
18
import org.slf4j.LoggerFactory;
19

20
import com.knowledgepixels.nanodash.ApiCache;
21
import com.knowledgepixels.nanodash.NanodashSession;
22
import com.knowledgepixels.nanodash.Space;
23
import com.knowledgepixels.nanodash.User;
24
import com.knowledgepixels.nanodash.Utils;
25
import com.knowledgepixels.nanodash.component.ItemListElement;
26
import com.knowledgepixels.nanodash.component.ItemListPanel;
27
import com.knowledgepixels.nanodash.component.NanopubResults;
28
import com.knowledgepixels.nanodash.component.TitleBar;
29

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

35
    private static final long serialVersionUID = 1L;
36
    private static final Logger logger = LoggerFactory.getLogger(UserPage.class);
×
37

38
    /**
39
     * The mount path for this page.
40
     */
41
    public static final String MOUNT_PATH = "/user";
42

43
    /**
44
     * {@inheritDoc}
45
     */
46
    @Override
47
    public String getMountPath() {
48
        return MOUNT_PATH;
×
49
    }
50

51
    private IRI userIri;
52
    private String pubkeyHashes = "";
×
53

54
    public UserPage(final PageParameters parameters) {
55
        super(parameters);
×
56

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

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

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

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

74
        add(new ExternalLink("fullid", userIriString, userIriString));
×
75

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

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

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

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

140
                private static final long serialVersionUID = 1L;
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(queryName, params)) {
×
152
                            r = ApiCache.retrieveResponse(queryName, params);
×
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

183
    private static Component makeNanopubResultComponent(String markupId, ApiResponse response) {
184
        if (response.getData().isEmpty()) {
×
185
            return new Label(markupId, "(none)");
×
186
        } else {
187
            return NanopubResults.fromApiResponse(markupId, response);
×
188
        }
189
    }
190

191
    /**
192
     * <p>hasAutoRefreshEnabled.</p>
193
     *
194
     * @return a boolean
195
     */
196
    protected boolean hasAutoRefreshEnabled() {
197
        return true;
×
198
    }
199

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