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

knowledgepixels / nanodash / 22628863420

03 Mar 2026 03:00PM UTC coverage: 16.03% (-0.04%) from 16.069%
22628863420

Pull #366

github

web-flow
Merge 3d3b286fd into d4f274b5b
Pull Request #366: fix(user-page): conditionally show latest nanopubs for unconfigured users

699 of 5297 branches covered (13.2%)

Branch coverage included in aggregate %.

1721 of 9800 relevant lines covered (17.56%)

2.41 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.AttributeModifier;
11
import org.apache.wicket.Component;
12
import org.apache.wicket.ajax.AjaxRequestTarget;
13
import org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel;
14
import org.apache.wicket.markup.html.WebMarkupContainer;
15
import org.apache.wicket.markup.html.basic.Label;
16
import org.apache.wicket.markup.html.link.AbstractLink;
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.eclipse.rdf4j.model.IRI;
23
import org.slf4j.Logger;
24
import org.slf4j.LoggerFactory;
25

26
import java.util.ArrayList;
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
        //NanodashSession session = NanodashSession.get();
66

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

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

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

77
        final String displayName = User.getShortDisplayName(userIri);
×
78
        add(new Label("pagetitle", displayName + " (user) | nanodash"));
×
79
        EmptyPanel userIcon = new EmptyPanel("userIcon");
×
80
        userIcon.add(AttributeModifier.replace("class", IndividualAgent.isSoftware(userIri) ? "bot-icon" : "user-icon"));
×
81
        add(userIcon);
×
82
        add(new Label("username", displayName));
×
83

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

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

89

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

132
        final List<AbstractLink> viewButtons = new ArrayList<>();
×
133
        viewButtons.add(new AddViewDisplayButton("button",
×
134
                        "https://w3id.org/np/RAQhTCHtfzGCj1YiE1LualWcZjg3thlRiquFWUE14UF-g",
135
                        "latest",
136
                        userIriString,
137
                        userIriString,
138
                        new PageParameters()
139
                                .set("refresh-upon-publish", userIriString)
×
140
                                .set("param_appliesToResource", userIriString)
×
141
                )
142
        );
143

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

165
            ViewDisplay defaultViewDisplay = new ViewDisplay(View.get("https://w3id.org/np/RAjYa33Z3H1whRl486AW3LMnV11WQqkTqvuHROhKbmtlE/latest-nanopubs-example"));
×
166
            final ViewList latestNanopubsView = new ViewList("latestnanopubsview", individualAgent, List.of(defaultViewDisplay), individualAgent, viewButtons);
×
167
            latestNanopubsView.setVisible(false);
×
168
            latestNanopubsView.setOutputMarkupPlaceholderTag(true);
×
169
            add(latestNanopubsView);
×
170

171
            add(new AjaxLazyLoadPanel<Component>("views") {
×
172

173
                @Override
174
                public Component getLazyLoadComponent(String markupId) {
175
                    if (individualAgent.getTopLevelViewDisplays().isEmpty()) {
×
176
                        return new ViewList(markupId, individualAgent, null, null, null, null, null, false);
×
177
                    }
178
                    return new ViewList(markupId, individualAgent, null, null, null, individualAgent, viewButtons, false);
×
179
                }
180

181
                @Override
182
                protected boolean isContentReady() {
183
                    return individualAgent.isDataInitialized();
×
184
                }
185

186
                @Override
187
                public Component getLoadingComponent(String id) {
188
                    return new Label(id, "<div class=\"row-section\"><div class=\"col-12\">" + ResultComponent.getWaitIconHtml() + "</div></div>").setEscapeModelStrings(false);
×
189
                }
190

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

206
            });
207
        }
208
    }
×
209

210
    /**
211
     * <p>hasAutoRefreshEnabled.</p>
212
     *
213
     * @return a boolean
214
     */
215
    protected boolean hasAutoRefreshEnabled() {
216
        return true;
×
217
    }
218

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