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

knowledgepixels / nanodash / 17518110100

06 Sep 2025 06:34PM UTC coverage: 11.955% (-0.1%) from 12.094%
17518110100

push

github

tkuhn
Undo custom AjaxLazyLoadPanel to fix paging navigation

334 of 3876 branches covered (8.62%)

Branch coverage included in aggregate %.

958 of 6931 relevant lines covered (13.82%)

0.61 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/ChannelPage.java
1
package com.knowledgepixels.nanodash.page;
2

3
import java.util.ArrayList;
4
import java.util.HashMap;
5
import java.util.Map;
6
import java.util.Optional;
7

8
import org.apache.wicket.ajax.AjaxRequestTarget;
9
import org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior;
10
import org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel;
11
import org.apache.wicket.markup.html.WebMarkupContainer;
12
import org.apache.wicket.markup.html.basic.Label;
13
import org.apache.wicket.markup.html.form.CheckBoxMultipleChoice;
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.nanopub.extra.services.ApiResponse;
19
import org.slf4j.Logger;
20
import org.slf4j.LoggerFactory;
21

22
import com.knowledgepixels.nanodash.ApiCache;
23
import com.knowledgepixels.nanodash.NanodashSession;
24
import com.knowledgepixels.nanodash.User;
25
import com.knowledgepixels.nanodash.Utils;
26
import com.knowledgepixels.nanodash.component.NanopubResults;
27
import com.knowledgepixels.nanodash.component.TitleBar;
28

29
/**
30
 * Page for displaying a channel of nanopublications associated with a user.
31
 */
32
public class ChannelPage extends NanodashPage {
33

34
    private static final long serialVersionUID = 1L;
35
    private static final Logger logger = LoggerFactory.getLogger(ChannelPage.class);
×
36

37
    /**
38
     * The mount path for this page.
39
     */
40
    public static final String MOUNT_PATH = "/channel";
41

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

50
    private Model<ArrayList<String>> selected = new Model<>();
×
51
    private IRI userIri;
52
    private boolean added = false;
×
53
    private Map<String, String> pubKeyMap;
54
    private CheckBoxMultipleChoice<String> pubkeySelection;
55

56
    /**
57
     * Constructor for the ChannelPage.
58
     *
59
     * @param parameters Page parameters containing the user ID.
60
     */
61
    public ChannelPage(final PageParameters parameters) {
62
        super(parameters);
×
63

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

68
        String pageType = "users";
×
69
        if (session.getUserIri() != null && userIri.equals(session.getUserIri())) pageType = "mychannel";
×
70
        add(new TitleBar("titlebar", this, pageType));
×
71

72
        final String displayName = User.getShortDisplayName(userIri);
×
73
        add(new Label("pagetitle", displayName + " (channel) | nanodash"));
×
74
        add(new Label("username", displayName));
×
75

76
        ArrayList<String> pubKeyList = new ArrayList<>();
×
77
        pubKeyMap = new HashMap<>();
×
78
        if (userIri.equals(session.getUserIri())) {
×
79
            String lKeyShort = Utils.getShortPubkeyLocationLabel(session.getPubkeyString(), userIri);
×
80
            pubKeyList.add(lKeyShort);
×
81
            pubKeyMap.put(lKeyShort, session.getPubkeyString());
×
82
        }
83
        for (String pk : User.getPubkeyhashes(userIri, null)) {
×
84
            String keyShort = Utils.getShortPubkeyLocationLabel(pk, userIri);
×
85
            if (!pubKeyMap.containsKey(keyShort)) {
×
86
                pubKeyList.add(keyShort);
×
87
                pubKeyMap.put(keyShort, pk);
×
88
            }
89
        }
×
90

91
        pubkeySelection = new CheckBoxMultipleChoice<String>("pubkeygroup", selected, pubKeyList);
×
92
        pubkeySelection.setDefaultModelObject(new ArrayList<String>(pubKeyList));
×
93
        pubkeySelection.add(new AjaxFormChoiceComponentUpdatingBehavior() {
×
94

95
            private static final long serialVersionUID = -6398658082085108029L;
96

97
            @Override
98
            protected void onUpdate(AjaxRequestTarget target) {
99
                logger.info("PUBKEYS SELECTED:");
×
100
                for (String s : selected.getObject()) {
×
101
                    logger.info(" {}", pubKeyMap.get(s));
×
102
                }
×
103
                logger.info("\n");
×
104
                refresh();
×
105
                setResponsePage(target.getPage());
×
106
                target.appendJavaScript("updateElements();");
×
107
            }
×
108

109
        });
110
        WebMarkupContainer selectPanel = new WebMarkupContainer("selectpanel");
×
111
        selectPanel.setVisible(!pubKeyList.isEmpty());
×
112
        selectPanel.add(pubkeySelection);
×
113
        add(selectPanel);
×
114

115
        refresh();
×
116
    }
×
117

118
    /**
119
     * Checks if auto-refresh is enabled for this page.
120
     *
121
     * @return true if auto-refresh is enabled, false otherwise.
122
     */
123
    protected boolean hasAutoRefreshEnabled() {
124
        return true;
×
125
    }
126

127
    private synchronized void refresh() {
128
        if (added) {
×
129
            remove("nanopubs");
×
130
        }
131
        added = true;
×
132
        final Map<String, String> params = new HashMap<>();
×
133
        final String queryName;
134
        String pubkeyHashes = getPubkeyHashesString();
×
135
        if (pubkeyHashes == null) {
×
136
            queryName = "get-latest-nanopubs-from-userid";
×
137
            params.put("userid", userIri.stringValue());
×
138
        } else {
139
            queryName = "get-latest-nanopubs-from-pubkeys";
×
140
            params.put("pubkeyhashes", pubkeyHashes);
×
141
            params.put("userid", userIri.stringValue());
×
142
        }
143
        ApiResponse cachedResponse = ApiCache.retrieveResponse(queryName, params);
×
144
        if (cachedResponse != null) {
×
145
            add(NanopubResults.fromApiResponse("nanopubs", cachedResponse));
×
146
        } else {
147
            add(new AjaxLazyLoadPanel<NanopubResults>("nanopubs") {
×
148

149
                private static final long serialVersionUID = 1L;
150

151
                @Override
152
                public NanopubResults getLazyLoadComponent(String markupId) {
153
                    ApiResponse r = null;
×
154
                    while (true) {
155
                        try {
156
                            Thread.sleep(500);
×
157
                        } catch (InterruptedException ex) {
×
158
                            logger.error("Interrupted while waiting for API response", ex);
×
159
                        }
×
160
                        if (!ApiCache.isRunning(queryName, params)) {
×
161
                            r = ApiCache.retrieveResponse(queryName, params);
×
162
                            if (r != null) break;
×
163
                        }
164
                    }
165
                    return NanopubResults.fromApiResponse(markupId, r);
×
166
                }
167

168
                @Override
169
                protected void onContentLoaded(NanopubResults content, Optional<AjaxRequestTarget> target) {
170
                    super.onContentLoaded(content, target);
×
171
                    if (target.isPresent()) {
×
172
                        target.get().appendJavaScript("updateElements();");
×
173
                    }
174
                }
×
175

176
            });
177
        }
178
    }
×
179

180
    private String getPubkeyHashesString() {
181
        String pubkeyHashes = "";
×
182
        for (String s : selected.getObject()) {
×
183
            pubkeyHashes += " " + pubKeyMap.get(s);
×
184
        }
×
185
        if (pubkeyHashes.isEmpty()) return null;
×
186
        return pubkeyHashes.substring(1);
×
187
    }
188

189
//        @Override
190
//        public void onBeforeRender() {
191
//                super.onBeforeRender();
192
//                if (hasBeenRendered()) {
193
//                        setResponsePage(getPageClass(), getPageParameters());
194
//                }
195
//        }
196

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