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

knowledgepixels / nanodash / 17837235071

18 Sep 2025 05:58PM UTC coverage: 13.87%. Remained the same
17837235071

push

github

tkuhn
chore: Remove serialVersionUIDs

443 of 4022 branches covered (11.01%)

Branch coverage included in aggregate %.

1133 of 7341 relevant lines covered (15.43%)

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

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

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

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

53
    public UserPage(final PageParameters parameters) {
54
        super(parameters);
×
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 ExternalLink("fullid", userIriString, 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", ChannelPage.class, new PageParameters().add("id", userIriString)));
×
120

121
        final Map<String, String> params = new HashMap<>();
×
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
        ApiResponse response = ApiCache.retrieveResponse(queryName, params);
×
132
        if (response != null) {
×
133
            add(makeNanopubResultComponent("latestnanopubs", response));
×
134
        } else {
135
            add(new AjaxLazyLoadPanel<Component>("latestnanopubs") {
×
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
        add(new ItemListPanel<Space>(
×
164
                "spaces",
165
                "Spaces",
166
                () -> Space.isLoaded(),
×
167
                () -> {
168
                        List<Space> spaces = new ArrayList<>();
×
169
                        for (Space space : Space.getSpaceList()) {
×
170
                            if (space.isMember(userIri)) spaces.add(space);
×
171
                        }
×
172
                        return spaces;
×
173
                    },
174
                (s) -> new ItemListElement("item", SpacePage.class, new PageParameters().add("id", s.getId()), s.getLabel(), "(" + s.getTypeLabel() + ")")
×
175
            ));
176
    }
×
177

178
    private static Component makeNanopubResultComponent(String markupId, ApiResponse response) {
179
        if (response.getData().isEmpty()) {
×
180
            return new Label(markupId, "(none)");
×
181
        } else {
182
            return NanopubResults.fromApiResponse(markupId, response);
×
183
        }
184
    }
185

186
    /**
187
     * <p>hasAutoRefreshEnabled.</p>
188
     *
189
     * @return a boolean
190
     */
191
    protected boolean hasAutoRefreshEnabled() {
192
        return true;
×
193
    }
194

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