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

knowledgepixels / nanodash / 22620546567

03 Mar 2026 11:16AM UTC coverage: 15.845% (-0.04%) from 15.884%
22620546567

Pull #366

github

web-flow
Merge 6215c67ab into a8c4b4a77
Pull Request #366: fix(user-page): conditionally show latest nanopubs for unconfigured users

699 of 5301 branches covered (13.19%)

Branch coverage included in aggregate %.

1690 of 9776 relevant lines covered (17.29%)

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.*;
4
import com.knowledgepixels.nanodash.component.*;
5
import org.apache.wicket.AttributeModifier;
6
import org.apache.wicket.Component;
7
import org.apache.wicket.ajax.AjaxRequestTarget;
8
import org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel;
9
import org.apache.wicket.markup.html.basic.Label;
10
import org.apache.wicket.markup.html.link.AbstractLink;
11
import org.apache.wicket.markup.html.panel.EmptyPanel;
12
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
13
import org.apache.wicket.markup.html.WebMarkupContainer;
14
import org.apache.wicket.model.Model;
15
import org.apache.wicket.request.flow.RedirectToUrlException;
16
import org.apache.wicket.request.mapper.parameter.PageParameters;
17
import org.eclipse.rdf4j.model.IRI;
18
import org.slf4j.Logger;
19
import org.slf4j.LoggerFactory;
20

21
import java.util.ArrayList;
22
import java.util.List;
23
import java.util.Optional;
24

25
/**
26
 * Page that shows a user profile, including their nanopubs and stats.
27
 */
28
public class UserPage extends NanodashPage {
29

30
    private static final Logger logger = LoggerFactory.getLogger(UserPage.class);
×
31

32
    /**
33
     * The mount path for this page.
34
     */
35
    public static final String MOUNT_PATH = "/user";
36

37
    /**
38
     * {@inheritDoc}
39
     */
40
    @Override
41
    public String getMountPath() {
42
        return MOUNT_PATH;
×
43
    }
44

45
    private IRI userIri;
46
    private String pubkeyHashes = "";
×
47

48
    /**
49
     * Constructor for UserPage.
50
     *
51
     * @param parameters Page parameters, must include "id" with the user IRI.
52
     */
53
    public UserPage(final PageParameters parameters) {
54
        super(parameters);
×
55
        setOutputMarkupId(true);
×
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
        add(new JustPublishedMessagePanel("justPublishedMessage", parameters));
×
71

72
        final String displayName = User.getShortDisplayName(userIri);
×
73
        add(new Label("pagetitle", displayName + " (user) | nanodash"));
×
74
        EmptyPanel userIcon = new EmptyPanel("userIcon");
×
75
        userIcon.add(AttributeModifier.replace("class", User.isSoftware(userIri) ? "bot-icon" : "user-icon"));
×
76
        add(userIcon);
×
77
        add(new Label("username", displayName));
×
78

79
        add(new BookmarkablePageLink<Void>("fullid", ExplorePage.class, parameters.set("label", displayName)).setBody(Model.of(userIriString)));
×
80

81
        add(new BookmarkablePageLink<Void>("showprofile", ProfilePage.class).setVisible(userIri.equals(NanodashSession.get().getUserIri())));
×
82
        add(new BookmarkablePageLink<Void>("showchannel", ListPage.class, new PageParameters().add("userid", userIriString)));
×
83

84

85
//                final Map<String,String> statsParams = new HashMap<>();
86
//                final String statsQueryName;
87
//                if (pubkeyHashes.isEmpty()) {
88
//                        statsQueryName = "get-user-stats-from-userid";
89
//                        statsParams.put("userid", userIriString);
90
//                } else {
91
//                        statsQueryName = "get-user-stats-from-pubkeys";
92
//                        statsParams.put("userid", userIriString);
93
//                        statsParams.put("pubkeyhashes", pubkeyHashes);
94
//                } 
95
//                Map<String,String> statsMap = ApiCache.retrieveMap(statsQueryName, statsParams);
96
//                if (statsMap != null) {
97
//                        add(new StatsPanel("stats", userIriString, pubkeyHashes, statsMap));
98
//                } else {
99
//                        add(new AjaxLazyLoadPanel<Component>("stats") {
100
//        
101
//                                @Override
102
//                                public Component getLazyLoadComponent(String markupId) {
103
//                                        Map<String,String> m = null;
104
//                                        while (true) {
105
//                                                try {
106
//                                                        Thread.sleep(500);
107
//                                                } catch (InterruptedException ex) {
108
//                                                        logger.error();
109
//                                                }
110
//                                                if (!ApiCache.isRunning(statsQueryName, statsParams)) {
111
//                                                        m = ApiCache.retrieveMap(statsQueryName, statsParams);
112
//                                                        if (m != null) break;
113
//                                                }
114
//                                        }
115
//                                        return new StatsPanel(markupId, userIriString, pubkeyHashes, m);
116
//                                }
117
//
118
//                                @Override
119
//                                protected void onContentLoaded(Component content, Optional<AjaxRequestTarget> target) {
120
//                                        super.onContentLoaded(content, target);
121
//                                        if (target.get() != null) target.get().appendJavaScript("updateElements();");
122
//                                }
123
//        
124
//                        });
125
//                }
126

127
        final List<AbstractLink> viewButtons = new ArrayList<>();
×
128
        AbstractLink addViewButton = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, new PageParameters()
×
129
                .set("template", "https://w3id.org/np/RAQhTCHtfzGCj1YiE1LualWcZjg3thlRiquFWUE14UF-g")
×
130
                .set("template-version", "latest")
×
131
                .set("param_resource", userIriString)
×
132
                .set("param_appliesToResource", userIriString)
×
133
                .set("context", userIriString)
×
134
                .set("refresh-upon-publish", userIriString)
×
135
        );
136
        addViewButton.setBody(Model.of("+ view display"));
×
137
        viewButtons.add(addViewButton);
×
138

139
        IndividualAgent individualAgent = IndividualAgent.get(userIriString);
×
140
        if (individualAgent.isDataInitialized()) {
×
141
            boolean empty = individualAgent.getTopLevelViewDisplays().isEmpty();
×
142
            if (empty) {
×
143
                add(new WebMarkupContainer("views").setVisible(false));
×
144
            } else {
145
                add(new ViewList("views", individualAgent, null, null, null, individualAgent, viewButtons, false));
×
146
            }
147
            add(new WebMarkupContainer("unconfigured-notice").setVisible(empty));
×
148
            if (empty) {
×
149
                ViewDisplay defaultViewDisplay = new ViewDisplay(View.get("https://w3id.org/np/RAjYa33Z3H1whRl486AW3LMnV11WQqkTqvuHROhKbmtlE/latest-nanopubs-example"));
×
150
                add(new ViewList("latestnanopubsview", individualAgent, List.of(defaultViewDisplay), individualAgent, viewButtons));
×
151
            } else {
×
152
                add(new EmptyPanel("latestnanopubsview").setVisible(false));
×
153
            }
154
        } else {
×
155
            final WebMarkupContainer unconfiguredNotice = new WebMarkupContainer("unconfigured-notice");
×
156
            unconfiguredNotice.setVisible(false);
×
157
            unconfiguredNotice.setOutputMarkupPlaceholderTag(true);
×
158
            add(unconfiguredNotice);
×
159

160
            ViewDisplay defaultViewDisplay = new ViewDisplay(View.get("https://w3id.org/np/RAjYa33Z3H1whRl486AW3LMnV11WQqkTqvuHROhKbmtlE/latest-nanopubs-example"));
×
161
            final ViewList latestNanopubsView = new ViewList("latestnanopubsview", individualAgent, List.of(defaultViewDisplay), individualAgent, viewButtons);
×
162
            latestNanopubsView.setVisible(false);
×
163
            latestNanopubsView.setOutputMarkupPlaceholderTag(true);
×
164
            add(latestNanopubsView);
×
165

166
            add(new AjaxLazyLoadPanel<Component>("views") {
×
167

168
                @Override
169
                public Component getLazyLoadComponent(String markupId) {
170
                    if (individualAgent.getTopLevelViewDisplays().isEmpty()) {
×
171
                        return new ViewList(markupId, individualAgent, null, null, null, null, null, false);
×
172
                    }
173
                    return new ViewList(markupId, individualAgent, null, null, null, individualAgent, viewButtons, false);
×
174
                }
175

176
                @Override
177
                protected boolean isContentReady() {
178
                    return individualAgent.isDataInitialized();
×
179
                }
180

181
                @Override
182
                public Component getLoadingComponent(String id) {
183
                    return new Label(id, "<div class=\"row-section\"><div class=\"col-12\">" + ResultComponent.getWaitIconHtml() + "</div></div>").setEscapeModelStrings(false);
×
184
                }
185

186
                @Override
187
                protected void onContentLoaded(Component content, Optional<AjaxRequestTarget> target) {
188
                    super.onContentLoaded(content, target);
×
189
                    target.ifPresent(t -> {
×
190
                        boolean isEmpty = individualAgent.getTopLevelViewDisplays().isEmpty();
×
191
                        if (isEmpty) {
×
192
                            t.appendJavaScript("document.getElementById('" + getMarkupId() + "').remove();");
×
193
                        }
194
                        unconfiguredNotice.setVisible(isEmpty);
×
195
                        t.add(unconfiguredNotice);
×
196
                        latestNanopubsView.setVisible(isEmpty);
×
197
                        t.add(latestNanopubsView);
×
198
                    });
×
199
                }
×
200

201
            });
202
        }
203
    }
×
204

205
    /**
206
     * <p>hasAutoRefreshEnabled.</p>
207
     *
208
     * @return a boolean
209
     */
210
    protected boolean hasAutoRefreshEnabled() {
211
        return true;
×
212
    }
213

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