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

knowledgepixels / nanodash / 17320701451

29 Aug 2025 09:55AM UTC coverage: 12.02% (+0.01%) from 12.007%
17320701451

push

github

ashleycaselli
refactor: minor code style update

330 of 3842 branches covered (8.59%)

Branch coverage included in aggregate %.

950 of 6807 relevant lines covered (13.96%)

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 com.knowledgepixels.nanodash.ApiCache;
4
import com.knowledgepixels.nanodash.NanodashSession;
5
import com.knowledgepixels.nanodash.User;
6
import com.knowledgepixels.nanodash.Utils;
7
import com.knowledgepixels.nanodash.component.NanopubResults;
8
import com.knowledgepixels.nanodash.component.TitleBar;
9
import org.apache.wicket.ajax.AjaxRequestTarget;
10
import org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior;
11
import org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel;
12
import org.apache.wicket.markup.html.WebMarkupContainer;
13
import org.apache.wicket.markup.html.basic.Label;
14
import org.apache.wicket.markup.html.form.CheckBoxMultipleChoice;
15
import org.apache.wicket.model.Model;
16
import org.apache.wicket.request.flow.RedirectToUrlException;
17
import org.apache.wicket.request.mapper.parameter.PageParameters;
18
import org.eclipse.rdf4j.model.IRI;
19
import org.nanopub.extra.services.ApiResponse;
20
import org.slf4j.Logger;
21
import org.slf4j.LoggerFactory;
22

23
import java.util.ArrayList;
24
import java.util.HashMap;
25
import java.util.Map;
26
import java.util.Optional;
27

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

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

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

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

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

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

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

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

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

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

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

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

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

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

114
        refresh();
×
115
    }
×
116

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

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

148
                private static final long serialVersionUID = 1L;
149

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

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

175
            });
176
        }
177
    }
×
178

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

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

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