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

knowledgepixels / nanodash / 17852532121

19 Sep 2025 08:10AM UTC coverage: 13.568% (-0.3%) from 13.87%
17852532121

push

github

tkuhn
feat: Switch to QueryRef provided by nanopub, using multimap

428 of 4008 branches covered (10.68%)

Branch coverage included in aggregate %.

1104 of 7283 relevant lines covered (15.16%)

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.List;
5

6
import org.apache.wicket.Component;
7
import org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel;
8
import org.apache.wicket.markup.html.basic.Label;
9
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
10
import org.apache.wicket.markup.html.link.ExternalLink;
11
import org.apache.wicket.request.flow.RedirectToUrlException;
12
import org.apache.wicket.request.mapper.parameter.PageParameters;
13
import org.eclipse.rdf4j.model.IRI;
14
import org.nanopub.extra.services.ApiResponse;
15
import org.nanopub.extra.services.QueryRef;
16
import org.slf4j.Logger;
17
import org.slf4j.LoggerFactory;
18

19
import com.google.common.collect.ArrayListMultimap;
20
import com.google.common.collect.Multimap;
21
import com.knowledgepixels.nanodash.ApiCache;
22
import com.knowledgepixels.nanodash.NanodashSession;
23
import com.knowledgepixels.nanodash.Space;
24
import com.knowledgepixels.nanodash.User;
25
import com.knowledgepixels.nanodash.Utils;
26
import com.knowledgepixels.nanodash.component.ItemListElement;
27
import com.knowledgepixels.nanodash.component.ItemListPanel;
28
import com.knowledgepixels.nanodash.component.NanopubResults;
29
import com.knowledgepixels.nanodash.component.TitleBar;
30

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

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
//                                @Override
95
//                                public Component getLazyLoadComponent(String markupId) {
96
//                                        Map<String,String> m = null;
97
//                                        while (true) {
98
//                                                try {
99
//                                                        Thread.sleep(500);
100
//                                                } catch (InterruptedException ex) {
101
//                                                        logger.error();
102
//                                                }
103
//                                                if (!ApiCache.isRunning(statsQueryName, statsParams)) {
104
//                                                        m = ApiCache.retrieveMap(statsQueryName, statsParams);
105
//                                                        if (m != null) break;
106
//                                                }
107
//                                        }
108
//                                        return new StatsPanel(markupId, userIriString, pubkeyHashes, m);
109
//                                }
110
//
111
//                                @Override
112
//                                protected void onContentLoaded(Component content, Optional<AjaxRequestTarget> target) {
113
//                                        super.onContentLoaded(content, target);
114
//                                        if (target.get() != null) target.get().appendJavaScript("updateElements();");
115
//                                }
116
//        
117
//                        });
118
//                }
119

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

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

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

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

162
            });
163
        }
164

165
        add(new ItemListPanel<Space>(
×
166
                "spaces",
167
                "Spaces",
168
                () -> Space.isLoaded(),
×
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().add("id", s.getId()), s.getLabel(), "(" + s.getTypeLabel() + ")")
×
177
            ));
178
    }
×
179

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

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

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