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

knowledgepixels / nanodash / 27145358627

08 Jun 2026 02:39PM UTC coverage: 20.682% (-0.3%) from 20.947%
27145358627

push

github

web-flow
Merge pull request #479 from knowledgepixels/feat/about-pages-478

Resource-page tabs, presets, and role-gated view actions (#478, #302)

1052 of 6429 branches covered (16.36%)

Branch coverage included in aggregate %.

2642 of 11432 relevant lines covered (23.11%)

3.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
        add(new JustPublishedMessagePanel("justPublishedMessage", parameters));
×
77

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

90
            }
91
            add(userIcon);
×
92
        }
93

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

99
        add(new ExternalLinkWithActionsPanel("fullid", Model.of(userIriString), Model.of(displayName)));
×
100

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

143
        WebMarkupContainer contentContainer = new WebMarkupContainer("contentContainer");
×
144
        add(contentContainer);
×
145
        if (activeTab != ResourceTabs.Tab.CONTENT) {
×
146
            contentContainer.setVisible(false);
×
147
            if (activeTab == ResourceTabs.Tab.ABOUT) {
×
148
                add(new AboutUserPanel("otherTab", userIriString));
×
149
            } else if (activeTab == ResourceTabs.Tab.EXPLORE) {
×
150
                add(new ExplorePanel("otherTab", userIriString));
×
151
            } else {
152
                add(new DownloadRdfLinks("otherTab", "user", userIriString));
×
153
            }
154
        } else {
155
            add(new EmptyPanel("otherTab").setVisible(false));
×
156
            IndividualAgent individualAgent = IndividualAgent.get(userIriString);
×
157
            if (individualAgent.isDataInitialized()) {
×
158
                boolean empty = individualAgent.getTopLevelViewDisplays().isEmpty();
×
159
                if (empty) {
×
160
                    contentContainer.add(new WebMarkupContainer("views").setVisible(false));
×
161
                } else {
162
                    contentContainer.add(new ViewList("views", individualAgent));
×
163
                }
164
                contentContainer.add(new WebMarkupContainer("unconfigured-notice").setVisible(empty));
×
165
                if (empty) {
×
166
                    ViewDisplay defaultViewDisplay = new ViewDisplay(View.get("https://w3id.org/np/RAwktOZ3vwTZJcGRbueLpxIFSiOj7XmMG2-8rzPuDEpPc/latest-nanopubs-by-user"));
×
167
                    contentContainer.add(new ViewList("latestnanopubsview", individualAgent, List.of(defaultViewDisplay)));
×
168
                } else {
×
169
                    contentContainer.add(new EmptyPanel("latestnanopubsview").setVisible(false));
×
170
                }
171
            } else {
×
172
                final WebMarkupContainer unconfiguredNotice = new WebMarkupContainer("unconfigured-notice");
×
173
                unconfiguredNotice.setVisible(false);
×
174
                unconfiguredNotice.setOutputMarkupPlaceholderTag(true);
×
175
                contentContainer.add(unconfiguredNotice);
×
176

177
                ViewDisplay defaultViewDisplay = new ViewDisplay(View.get("https://w3id.org/np/RAwktOZ3vwTZJcGRbueLpxIFSiOj7XmMG2-8rzPuDEpPc/latest-nanopubs-by-user"));
×
178
                final ViewList latestNanopubsView = new ViewList("latestnanopubsview", individualAgent, List.of(defaultViewDisplay));
×
179
                latestNanopubsView.setVisible(false);
×
180
                latestNanopubsView.setOutputMarkupPlaceholderTag(true);
×
181
                contentContainer.add(latestNanopubsView);
×
182

183
                contentContainer.add(new AjaxLazyLoadPanel<Component>("views") {
×
184

185
                    @Override
186
                    public Component getLazyLoadComponent(String markupId) {
187
                        return new ViewList(markupId, individualAgent);
×
188
                    }
189

190
                    @Override
191
                    protected boolean isContentReady() {
192
                        return individualAgent.isDataInitialized();
×
193
                    }
194

195
                    @Override
196
                    public Component getLoadingComponent(String id) {
197
                        return new Label(id, "<div class=\"row-section\"><div class=\"col-12\">" + ResultComponent.getWaitIconHtml() + "</div></div>").setEscapeModelStrings(false);
×
198
                    }
199

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

215
                });
216
            }
217
        }
218
    }
×
219

220
    /**
221
     * <p>hasAutoRefreshEnabled.</p>
222
     *
223
     * @return a boolean
224
     */
225
    protected boolean hasAutoRefreshEnabled() {
226
        return true;
×
227
    }
228

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