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

knowledgepixels / nanodash / 27622721129

16 Jun 2026 01:55PM UTC coverage: 26.963% (+6.3%) from 20.697%
27622721129

Pull #483

github

web-flow
Merge 73a4d0fe1 into 663f14f46
Pull Request #483: Space/resource About pages, ref-aware spaces, and magic query params

1542 of 6717 branches covered (22.96%)

Branch coverage included in aggregate %.

3407 of 11638 relevant lines covered (29.27%)

4.31 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.BookmarkablePageLink;
18
import org.apache.wicket.markup.html.panel.EmptyPanel;
19
import org.apache.wicket.model.Model;
20
import org.apache.wicket.request.flow.RedirectToUrlException;
21
import org.apache.wicket.request.mapper.parameter.PageParameters;
22
import org.apache.wicket.request.resource.ContextRelativeResourceReference;
23
import org.eclipse.rdf4j.model.IRI;
24
import org.slf4j.Logger;
25
import org.slf4j.LoggerFactory;
26

27
import java.util.List;
28
import java.util.Optional;
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
    /**
54
     * Constructor for UserPage.
55
     *
56
     * @param parameters Page parameters, must include "id" with the user IRI.
57
     */
58
    public UserPage(final PageParameters parameters) {
59
        super(parameters);
×
60
        setOutputMarkupId(true);
×
61

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

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

71
        ResourceTabs.Tab activeTab = ResourceTabs.activeFromParam(parameters);
×
72
        String pageType = "users";
×
73
        add(new TitleBar("titlebar", this, pageType)
×
74
                .setTabs(new ResourceTabs("tabs", "user", userIriString, activeTab)));
×
75

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

88
            }
89
            add(userIcon);
×
90
        }
91

92
        final String displayName = User.getShortDisplayName(userIri);
×
93
        add(new Label("pagetitle", displayName + " (user) | nanodash"));
×
94
        add(new Label("username", displayName));
×
95
        add(new Label("titlesuffix", ResourceTabs.titleSuffix(activeTab)));
×
96

97
        add(new ExternalLinkWithActionsPanel("fullid", Model.of(userIriString), Model.of(displayName)));
×
98

99
        // The owner's account + signing-key controls share the title/ORCID header
100
        // stripe (own About page only).
101
        boolean ownPage = NanodashSession.get().getUserIri() != null
×
102
                && NanodashSession.get().getUserIri().stringValue().equals(userIriString);
×
103
        if (ownPage && activeTab == ResourceTabs.Tab.ABOUT) {
×
104
            add(new ProfileAccountPanel("accountpart", userIriString));
×
105
        } else {
106
            add(new EmptyPanel("accountpart").setVisible(false));
×
107
        }
108

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

151
        WebMarkupContainer contentContainer = new WebMarkupContainer("contentContainer");
×
152
        add(contentContainer);
×
153
        if (activeTab != ResourceTabs.Tab.CONTENT) {
×
154
            contentContainer.setVisible(false);
×
155
            if (activeTab == ResourceTabs.Tab.ABOUT) {
×
156
                // The panel constructor resolves view nanopubs over the network when
157
                // they aren't freshly cached, which would block the initial page
158
                // render; the view-id list must mirror the panel's View.get calls.
159
                add(LazyContentPanel.of("otherTab", markupId -> new AboutUserPanel(markupId, userIriString),
×
160
                        AboutUserPanel.INTRODUCTIONS_VIEW, AboutUserPanel.PROFILE_VIEW,
161
                        AboutSpacePanel.PRESET_ASSIGNMENTS_VIEW, AboutSpacePanel.VIEW_DISPLAYS_VIEW));
162
            } else if (activeTab == ResourceTabs.Tab.EXPLORE) {
×
163
                add(LazyContentPanel.of("otherTab", markupId -> new ExplorePanel(markupId, userIriString),
×
164
                        ReferencesPage.REFERENCES_VIEW));
165
            } else {
166
                add(new DownloadRdfLinks("otherTab", "user", userIriString));
×
167
            }
168
        } else {
169
            add(new EmptyPanel("otherTab").setVisible(false));
×
170
            IndividualAgent individualAgent = IndividualAgent.get(userIriString);
×
171
            if (individualAgent.isDataInitialized()) {
×
172
                boolean empty = individualAgent.getTopLevelViewDisplays().isEmpty();
×
173
                if (empty) {
×
174
                    contentContainer.add(new WebMarkupContainer("views").setVisible(false));
×
175
                } else {
176
                    contentContainer.add(new ViewList("views", individualAgent));
×
177
                }
178
                contentContainer.add(new WebMarkupContainer("unconfigured-notice").setVisible(empty));
×
179
                if (empty) {
×
180
                    ViewDisplay defaultViewDisplay = new ViewDisplay(View.get("https://w3id.org/np/RAwktOZ3vwTZJcGRbueLpxIFSiOj7XmMG2-8rzPuDEpPc/latest-nanopubs-by-user"));
×
181
                    contentContainer.add(new ViewList("latestnanopubsview", individualAgent, List.of(defaultViewDisplay)));
×
182
                } else {
×
183
                    contentContainer.add(new EmptyPanel("latestnanopubsview").setVisible(false));
×
184
                }
185
            } else {
×
186
                final WebMarkupContainer unconfiguredNotice = new WebMarkupContainer("unconfigured-notice");
×
187
                unconfiguredNotice.setVisible(false);
×
188
                unconfiguredNotice.setOutputMarkupPlaceholderTag(true);
×
189
                contentContainer.add(unconfiguredNotice);
×
190

191
                ViewDisplay defaultViewDisplay = new ViewDisplay(View.get("https://w3id.org/np/RAwktOZ3vwTZJcGRbueLpxIFSiOj7XmMG2-8rzPuDEpPc/latest-nanopubs-by-user"));
×
192
                final ViewList latestNanopubsView = new ViewList("latestnanopubsview", individualAgent, List.of(defaultViewDisplay));
×
193
                latestNanopubsView.setVisible(false);
×
194
                latestNanopubsView.setOutputMarkupPlaceholderTag(true);
×
195
                contentContainer.add(latestNanopubsView);
×
196

197
                contentContainer.add(new AjaxLazyLoadPanel<Component>("views") {
×
198

199
                    @Override
200
                    public Component getLazyLoadComponent(String markupId) {
201
                        return new ViewList(markupId, individualAgent);
×
202
                    }
203

204
                    @Override
205
                    protected boolean isContentReady() {
206
                        return individualAgent.isDataInitialized();
×
207
                    }
208

209
                    @Override
210
                    public Component getLoadingComponent(String id) {
211
                        return new Label(id, "<div class=\"row-section\"><div class=\"col-12\">" + ResultComponent.getWaitIconHtml() + "</div></div>").setEscapeModelStrings(false);
×
212
                    }
213

214
                    @Override
215
                    protected void onContentLoaded(Component content, Optional<AjaxRequestTarget> target) {
216
                        super.onContentLoaded(content, target);
×
217
                        target.ifPresent(t -> {
×
218
                            boolean isEmpty = individualAgent.getTopLevelViewDisplays().isEmpty();
×
219
                            if (isEmpty) {
×
220
                                t.appendJavaScript("document.getElementById('" + getMarkupId() + "').remove();");
×
221
                            }
222
                            unconfiguredNotice.setVisible(isEmpty);
×
223
                            t.add(unconfiguredNotice);
×
224
                            latestNanopubsView.setVisible(isEmpty);
×
225
                            t.add(latestNanopubsView);
×
226
                        });
×
227
                    }
×
228

229
                });
230
            }
231
        }
232
    }
×
233

234
    /**
235
     * <p>hasAutoRefreshEnabled.</p>
236
     *
237
     * @return a boolean
238
     */
239
    protected boolean hasAutoRefreshEnabled() {
240
        return true;
×
241
    }
242

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