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

knowledgepixels / nanodash / 22760940566

06 Mar 2026 11:11AM UTC coverage: 15.877% (+0.009%) from 15.868%
22760940566

push

github

web-flow
Merge pull request #379 from knowledgepixels/222-profile-logo

Users can set a profile picture

705 of 5393 branches covered (13.07%)

Branch coverage included in aggregate %.

1741 of 10013 relevant lines covered (17.39%)

2.37 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.knowledgepixels.nanodash.NanodashSession;
4
import com.knowledgepixels.nanodash.Utils;
5
import com.knowledgepixels.nanodash.View;
6
import com.knowledgepixels.nanodash.ViewDisplay;
7
import com.knowledgepixels.nanodash.component.*;
8
import com.knowledgepixels.nanodash.domain.IndividualAgent;
9
import com.knowledgepixels.nanodash.domain.User;
10
import org.apache.wicket.Component;
11
import org.apache.wicket.ajax.AjaxRequestTarget;
12
import org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel;
13
import org.apache.wicket.markup.html.WebMarkupContainer;
14
import org.apache.wicket.markup.html.basic.Label;
15
import org.apache.wicket.markup.html.image.ExternalImage;
16
import org.apache.wicket.markup.html.image.Image;
17
import org.apache.wicket.markup.html.link.AbstractLink;
18
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
19
import org.apache.wicket.markup.html.panel.EmptyPanel;
20
import org.apache.wicket.model.Model;
21
import org.apache.wicket.request.flow.RedirectToUrlException;
22
import org.apache.wicket.request.mapper.parameter.PageParameters;
23
import org.apache.wicket.request.resource.ContextRelativeResourceReference;
24
import org.eclipse.rdf4j.model.IRI;
25
import org.slf4j.Logger;
26
import org.slf4j.LoggerFactory;
27

28
import java.util.ArrayList;
29
import java.util.List;
30
import java.util.Optional;
31

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

37
    private static final Logger logger = LoggerFactory.getLogger(UserPage.class);
×
38

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

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

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

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

64
        if (parameters.get("id") == null) throw new RedirectToUrlException(ProfilePage.MOUNT_PATH);
×
65
        final String userIriString = parameters.get("id").toString();
×
66
        userIri = Utils.vf.createIRI(userIriString);
×
67

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

73
        String pageType = "users";
×
74
        add(new TitleBar("titlebar", this, pageType));
×
75

76
        add(new JustPublishedMessagePanel("justPublishedMessage", parameters));
×
77

78
        final String displayName = User.getShortDisplayName(userIri);
×
79
        add(new Label("pagetitle", displayName + " (user) | nanodash"));
×
80

81
        IRI profilePictureIri = User.getProfilePicture(userIri);
×
82
        if (profilePictureIri != null) {
×
83
            ExternalImage userIcon = new ExternalImage("userIcon", profilePictureIri);
×
84
            add(userIcon);
×
85
        } else {
×
86
            boolean isSoftware = IndividualAgent.isSoftware(userIri);
×
87
            Image userIcon;
88
            if (isSoftware) {
×
89
                userIcon = new Image("userIcon", new ContextRelativeResourceReference("images/bot-icon.svg", false));
×
90
            } else {
91
                userIcon = new Image("userIcon", new ContextRelativeResourceReference("images/user-icon.svg", false));
×
92

93
            }
94
            add(userIcon);
×
95
        }
96

97
        add(new Label("username", displayName));
×
98

99
        add(new ExternalLinkWithActionsPanel("fullid", Model.of(userIriString), Model.of(displayName)));
×
100
        add(new BookmarkablePageLink<Void>("showprofile", ProfilePage.class).setVisible(userIri.equals(NanodashSession.get().getUserIri())));
×
101
        add(new BookmarkablePageLink<Void>("showchannel", ListPage.class, new PageParameters().add("userid", userIriString)));
×
102

103

104
//                final Map<String,String> statsParams = new HashMap<>();
105
//                final String statsQueryName;
106
//                if (pubkeyHashes.isEmpty()) {
107
//                        statsQueryName = "get-user-stats-from-userid";
108
//                        statsParams.put("userid", userIriString);
109
//                } else {
110
//                        statsQueryName = "get-user-stats-from-pubkeys";
111
//                        statsParams.put("userid", userIriString);
112
//                        statsParams.put("pubkeyhashes", pubkeyHashes);
113
//                } 
114
//                Map<String,String> statsMap = ApiCache.retrieveMap(statsQueryName, statsParams);
115
//                if (statsMap != null) {
116
//                        add(new StatsPanel("stats", userIriString, pubkeyHashes, statsMap));
117
//                } else {
118
//                        add(new AjaxLazyLoadPanel<Component>("stats") {
119
//        
120
//                                @Override
121
//                                public Component getLazyLoadComponent(String markupId) {
122
//                                        Map<String,String> m = null;
123
//                                        while (true) {
124
//                                                try {
125
//                                                        Thread.sleep(500);
126
//                                                } catch (InterruptedException ex) {
127
//                                                        logger.error();
128
//                                                }
129
//                                                if (!ApiCache.isRunning(statsQueryName, statsParams)) {
130
//                                                        m = ApiCache.retrieveMap(statsQueryName, statsParams);
131
//                                                        if (m != null) break;
132
//                                                }
133
//                                        }
134
//                                        return new StatsPanel(markupId, userIriString, pubkeyHashes, m);
135
//                                }
136
//
137
//                                @Override
138
//                                protected void onContentLoaded(Component content, Optional<AjaxRequestTarget> target) {
139
//                                        super.onContentLoaded(content, target);
140
//                                        if (target.get() != null) target.get().appendJavaScript("updateElements();");
141
//                                }
142
//        
143
//                        });
144
//                }
145

146
        final List<AbstractLink> viewButtons = new ArrayList<>();
×
147
        viewButtons.add(new AddViewDisplayButton("button",
×
148
                        "https://w3id.org/np/RAQhTCHtfzGCj1YiE1LualWcZjg3thlRiquFWUE14UF-g",
149
                        "latest",
150
                        userIriString,
151
                        userIriString,
152
                        new PageParameters()
153
                                .set("refresh-upon-publish", userIriString)
×
154
                                .set("param_appliesToResource", userIriString)
×
155
                )
156
        );
157

158
        IndividualAgent individualAgent = IndividualAgent.get(userIriString);
×
159
        if (individualAgent.isDataInitialized()) {
×
160
            boolean empty = individualAgent.getTopLevelViewDisplays().isEmpty();
×
161
            if (empty) {
×
162
                add(new WebMarkupContainer("views").setVisible(false));
×
163
            } else {
164
                add(new ViewList("views", individualAgent, null, null, null, individualAgent, viewButtons, false));
×
165
            }
166
            add(new WebMarkupContainer("unconfigured-notice").setVisible(empty));
×
167
            if (empty) {
×
168
                ViewDisplay defaultViewDisplay = new ViewDisplay(View.get("https://w3id.org/np/RAjYa33Z3H1whRl486AW3LMnV11WQqkTqvuHROhKbmtlE/latest-nanopubs-example"));
×
169
                add(new ViewList("latestnanopubsview", individualAgent, List.of(defaultViewDisplay), individualAgent, viewButtons));
×
170
            } else {
×
171
                add(new EmptyPanel("latestnanopubsview").setVisible(false));
×
172
            }
173
        } else {
×
174
            final WebMarkupContainer unconfiguredNotice = new WebMarkupContainer("unconfigured-notice");
×
175
            unconfiguredNotice.setVisible(false);
×
176
            unconfiguredNotice.setOutputMarkupPlaceholderTag(true);
×
177
            add(unconfiguredNotice);
×
178

179
            ViewDisplay defaultViewDisplay = new ViewDisplay(View.get("https://w3id.org/np/RAjYa33Z3H1whRl486AW3LMnV11WQqkTqvuHROhKbmtlE/latest-nanopubs-example"));
×
180
            final ViewList latestNanopubsView = new ViewList("latestnanopubsview", individualAgent, List.of(defaultViewDisplay), individualAgent, viewButtons);
×
181
            latestNanopubsView.setVisible(false);
×
182
            latestNanopubsView.setOutputMarkupPlaceholderTag(true);
×
183
            add(latestNanopubsView);
×
184

185
            add(new AjaxLazyLoadPanel<Component>("views") {
×
186

187
                @Override
188
                public Component getLazyLoadComponent(String markupId) {
189
                    if (individualAgent.getTopLevelViewDisplays().isEmpty()) {
×
190
                        return new ViewList(markupId, individualAgent, null, null, null, null, null, false);
×
191
                    }
192
                    return new ViewList(markupId, individualAgent, null, null, null, individualAgent, viewButtons, false);
×
193
                }
194

195
                @Override
196
                protected boolean isContentReady() {
197
                    return individualAgent.isDataInitialized();
×
198
                }
199

200
                @Override
201
                public Component getLoadingComponent(String id) {
202
                    return new Label(id, "<div class=\"row-section\"><div class=\"col-12\">" + ResultComponent.getWaitIconHtml() + "</div></div>").setEscapeModelStrings(false);
×
203
                }
204

205
                @Override
206
                protected void onContentLoaded(Component content, Optional<AjaxRequestTarget> target) {
207
                    super.onContentLoaded(content, target);
×
208
                    target.ifPresent(t -> {
×
209
                        boolean isEmpty = individualAgent.getTopLevelViewDisplays().isEmpty();
×
210
                        if (isEmpty) {
×
211
                            t.appendJavaScript("document.getElementById('" + getMarkupId() + "').remove();");
×
212
                        }
213
                        unconfiguredNotice.setVisible(isEmpty);
×
214
                        t.add(unconfiguredNotice);
×
215
                        latestNanopubsView.setVisible(isEmpty);
×
216
                        t.add(latestNanopubsView);
×
217
                    });
×
218
                }
×
219

220
            });
221
        }
222
    }
×
223

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

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