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

knowledgepixels / nanodash / 17380144000

01 Sep 2025 02:12PM UTC coverage: 12.03% (+0.05%) from 11.978%
17380144000

push

github

ashleycaselli
refactor: replace printStackTrace with logger.error for better error handling

330 of 3850 branches covered (8.57%)

Branch coverage included in aggregate %.

958 of 6857 relevant lines covered (13.97%)

0.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
src/main/java/com/knowledgepixels/nanodash/connector/GenOverviewPage.java
1
package com.knowledgepixels.nanodash.connector;
2

3
import com.knowledgepixels.nanodash.NanodashPreferences;
4
import com.knowledgepixels.nanodash.NanodashSession;
5
import com.knowledgepixels.nanodash.User;
6
import com.knowledgepixels.nanodash.Utils;
7
import com.knowledgepixels.nanodash.component.TitleBar;
8
import com.knowledgepixels.nanodash.page.OrcidLoginPage;
9
import com.knowledgepixels.nanodash.page.PublishPage;
10
import org.apache.wicket.ajax.AjaxRequestTarget;
11
import org.apache.wicket.ajax.markup.html.AjaxLink;
12
import org.apache.wicket.markup.html.WebMarkupContainer;
13
import org.apache.wicket.markup.html.basic.Label;
14
import org.apache.wicket.markup.html.image.Image;
15
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
16
import org.apache.wicket.markup.html.link.ExternalLink;
17
import org.apache.wicket.markup.repeater.Item;
18
import org.apache.wicket.markup.repeater.data.DataView;
19
import org.apache.wicket.markup.repeater.data.ListDataProvider;
20
import org.apache.wicket.request.mapper.parameter.PageParameters;
21
import org.apache.wicket.request.resource.PackageResourceReference;
22
import org.eclipse.rdf4j.model.IRI;
23
import org.nanopub.Nanopub;
24
import org.nanopub.extra.services.ApiResponse;
25
import org.nanopub.extra.services.ApiResponseEntry;
26
import org.slf4j.Logger;
27
import org.slf4j.LoggerFactory;
28

29
import java.util.ArrayList;
30
import java.util.HashMap;
31
import java.util.List;
32

33
/**
34
 * Overview page for a connector journal.
35
 */
36
public class GenOverviewPage extends ConnectorPage {
37

38
    private static final long serialVersionUID = 1L;
39
    private static final Logger logger = LoggerFactory.getLogger(GenOverviewPage.class);
×
40

41
    /**
42
     * The mount path for this page.
43
     */
44
    public static final String MOUNT_PATH = "/connector";
45

46
    private ConnectorConfig config;
47

48
    /**
49
     * Constructor for the overview page.
50
     *
51
     * @param params the page parameters, which should contain the journal ID
52
     */
53
    public GenOverviewPage(PageParameters params) {
54
        super(params);
×
55
        final String journalId = params.get("journal").toString();
×
56
        config = ConnectorConfig.get(journalId);
×
57

58
        add(new TitleBar("titlebar", this, "connectors"));
×
59
        add(new Image("logo", new PackageResourceReference(getConfig().getClass(), getConfig().getLogoFileName())));
×
60

61
        if (getConfig().getTechnicalEditorIds().contains(NanodashSession.get().getUserIri())) {
×
62
            WebMarkupContainer technicalEditorActions = new WebMarkupContainer("technical-editor-actions");
×
63

64
            technicalEditorActions.add(new BookmarkablePageLink<Void>("publish-article-metadata", PublishPage.class,
×
65
                    new PageParameters().add("template", "https://w3id.org/np/RA48p4Ct8tWL--rIc1Dcr2BcYpW_7X1pfuv_2LK3anolY")
×
66
                            .add("template-version", "latest")
×
67
                            .add("param_journal", getConfig().getJournalIssn())
×
68
                            .add("param_journal-title", getConfig().getJournalName())
×
69
                            .add("prtemplate", "https://w3id.org/np/RAekcN47h13fk6ZK4XiObgGgk-qB01sLOjyGyhMCq_jT4")
×
70
                            .add("pitemplate1", "https://w3id.org/np/RA5R_qv3VsZIrDKd8Mr37x3HoKCsKkwN5tJVqgQsKhjTE")
×
71
                            .add("piparam1_type", getConfig().getNanopubType() == null ? "" : getConfig().getNanopubType().stringValue())
×
72
                            .add("pitemplate2", "https://w3id.org/np/RA16U9Wo30ObhrK1NzH7EsmVRiRtvEuEA_Dfc-u8WkUCA")
×
73
                            .add("target-namespace", getConfig().getTargetNamespace() == null ? "https://w3id.org/np/" : getConfig().getTargetNamespace())
×
74
            ));
75
            add(technicalEditorActions);
×
76
        } else {
×
77
            add(new WebMarkupContainer("technical-editor-actions").setVisible(false));
×
78
        }
79

80
        try {
81

82
            final WebMarkupContainer c = new WebMarkupContainer("owncandidates-component");
×
83
            c.setOutputMarkupId(true);
×
84
            add(c);
×
85

86
            if (NanodashSession.get().getUserIri() != null) {
×
87

88
                HashMap<String, String> apiParam = new HashMap<>();
×
89
                apiParam.put("creator", NanodashSession.get().getUserIri().stringValue());
×
90
                ApiResponse resp = callApi(getConfig().getCandidateNanopubsApiCall(), apiParam);
×
91
                while (resp == null) {
×
92
                    // we only get here in case of second-generation API calls
93
                    // TODO Do this in an AJAX way:
94
                    try {
95
                        Thread.sleep(200);
×
96
                    } catch (InterruptedException ex) {
×
97
                    }
×
98
                    resp = callApi(getConfig().getCandidateNanopubsApiCall(), apiParam);
×
99
                }
100

101
                final List<ApiResponseEntry> listData = new ArrayList<ApiResponseEntry>();
×
102
                final ArrayList<ApiResponseEntry> fullList = new ArrayList<>();
×
103
                for (ApiResponseEntry a : resp.getData()) {
×
104
                    if (listData.size() < 10) listData.add(a);
×
105
                    // TODO This will become inefficient at some point:
106
                    fullList.add(a);
×
107
                }
×
108

109
                c.add(new DataView<ApiResponseEntry>("own", new ListDataProvider<ApiResponseEntry>(listData)) {
×
110

111
                    private static final long serialVersionUID = 1L;
112

113
                    @Override
114
                    protected void populateItem(Item<ApiResponseEntry> item) {
115
                        ApiResponseEntry e = item.getModelObject();
×
116
                        PageParameters params = new PageParameters().add("journal", journalId).add("id", e.get("np")).add("mode", "author");
×
117
                        BookmarkablePageLink<Void> l = new BookmarkablePageLink<Void>("ownlink", GenNanopubPage.class, params);
×
118
                        l.add(new Label("ownlinktext", "\"" + e.get("label") + "\""));
×
119
                        item.add(l);
×
120
                        String pubkeyhash = Utils.createSha256HexHash(e.get("pubkey"));
×
121
                        String username = User.getShortDisplayNameForPubkeyhash(null, pubkeyhash);
×
122
                        item.add(new Label("ownnote", "by " + username + " on " + e.get("date").substring(0, 10)));
×
123
                    }
×
124

125
                });
126

127
                c.add(new AjaxLink<>("allowncandidates") {
×
128

129
                    private static final long serialVersionUID = 1L;
130

131
                    @Override
132
                    public void onClick(AjaxRequestTarget target) {
133
                        try {
134
                            listData.clear();
×
135
                            listData.addAll(fullList);
×
136
                            target.add(c);
×
137
                            setVisible(false);
×
138
                            target.add(this);
×
139
                        } catch (Exception ex) {
×
140
                            logger.error("Error showing all candidates", ex);
×
141
                        }
×
142
                    }
×
143

144
                }.setVisible(fullList.size() > 10));
×
145

146
                add(new BookmarkablePageLink<Void>("create-new", GenSelectPage.class, params));
×
147
            } else {
×
148
                c.add(new Label("allowncandidates", "").setVisible(false));
×
149
                c.add(new Label("own", "").setVisible(false));
×
150
                if (NanodashPreferences.get().isOrcidLoginMode()) {
×
151
                    String loginUrl = OrcidLoginPage.getOrcidLoginUrl(getMountPath(), getPageParameters());
×
152
                    add(new ExternalLink("create-new", loginUrl, "Login to See More"));
×
153
                } else {
×
154
                    add(new ExternalLink("create-new", Utils.getUrlWithParameters(getMountPath(), getPageParameters()), "Complete Your Profile to See More"));
×
155
                }
156
            }
157
        } catch (Exception ex) {
×
158
            logger.error("Error in own candidates section", ex);
×
159
        }
×
160

161
        try {
162
            final WebMarkupContainer c = new WebMarkupContainer("candidates-component");
×
163
            c.setOutputMarkupId(true);
×
164
            add(c);
×
165

166
            ApiResponse resp = callApi(getConfig().getCandidateNanopubsApiCall(), new HashMap<>());
×
167
            while (resp == null) {
×
168
                // TODO Do this in an AJAX way:
169
                try {
170
                    Thread.sleep(200);
×
171
                } catch (InterruptedException ex) {
×
172
                    logger.error("Thread interrupted", ex);
×
173
                }
×
174
                resp = callApi(getConfig().getCandidateNanopubsApiCall(), new HashMap<>());
×
175
            }
176

177
            final List<ApiResponseEntry> listData = new ArrayList<ApiResponseEntry>();
×
178
            final ArrayList<ApiResponseEntry> fullList = new ArrayList<>();
×
179
            for (ApiResponseEntry a : resp.getData()) {
×
180
                if (listData.size() < 10) listData.add(a);
×
181
                // TODO This will become inefficient at some point:
182
                fullList.add(a);
×
183
            }
×
184

185
            c.add(new DataView<ApiResponseEntry>("candidates", new ListDataProvider<ApiResponseEntry>(listData)) {
×
186

187
                private static final long serialVersionUID = 1L;
188

189
                @Override
190
                protected void populateItem(Item<ApiResponseEntry> item) {
191
                    ApiResponseEntry e = item.getModelObject();
×
192
                    PageParameters params = new PageParameters().add("journal", journalId).add("id", e.get("np")).add("mode", "candidate");
×
193
                    BookmarkablePageLink<Void> l = new BookmarkablePageLink<Void>("candidatelink", GenNanopubPage.class, params);
×
194
                    l.add(new Label("candidatelinktext", "\"" + e.get("label") + "\""));
×
195
                    item.add(l);
×
196
                    String pubkeyhash = Utils.createSha256HexHash(e.get("pubkey"));
×
197
                    String username = User.getShortDisplayNameForPubkeyhash(null, pubkeyhash);
×
198
                    item.add(new Label("candidatenote", "by " + username + " on " + e.get("date").substring(0, 10)));
×
199
                }
×
200

201
            });
202

203
            c.add(new AjaxLink<>("allcandidates") {
×
204

205
                private static final long serialVersionUID = 1L;
206

207
                @Override
208
                public void onClick(AjaxRequestTarget target) {
209
                    try {
210
                        listData.clear();
×
211
                        listData.addAll(fullList);
×
212
                        target.add(c);
×
213
                        setVisible(false);
×
214
                        target.add(this);
×
215
                    } catch (Exception ex) {
×
216
                        logger.error("Error in all candidates click", ex);
×
217
                    }
×
218
                }
×
219

220
            }.setVisible(fullList.size() > 10));
×
221

222
        } catch (Exception ex) {
×
223
            logger.error("Error in candidates section", ex);
×
224
        }
×
225

226
        if (getConfig().getAcceptedNanopubsApiCall() != null) {
×
227
            try {
228
                final WebMarkupContainer c = new WebMarkupContainer("accepted-component");
×
229
                c.setOutputMarkupId(true);
×
230
                add(c);
×
231

232
                ApiResponse resp = callApi(getConfig().getAcceptedNanopubsApiCall(), new HashMap<>());
×
233
                while (resp == null) {
×
234
                    // TODO Do this in an AJAX way:
235
                    try {
236
                        Thread.sleep(200);
×
237
                    } catch (InterruptedException ex) {
×
238
                    }
×
239
                    resp = callApi(getConfig().getAcceptedNanopubsApiCall(), new HashMap<>());
×
240
                }
241

242
                final List<ApiResponseEntry> listData = new ArrayList<ApiResponseEntry>();
×
243
                final ArrayList<ApiResponseEntry> fullList = new ArrayList<>();
×
244
                for (ApiResponseEntry a : resp.getData()) {
×
245
                    if (listData.size() < 10) listData.add(a);
×
246
                    // TODO This will become inefficient at some point:
247
                    fullList.add(a);
×
248
                }
×
249

250
                c.add(new DataView<ApiResponseEntry>("accepted", new ListDataProvider<ApiResponseEntry>(listData)) {
×
251

252
                    private static final long serialVersionUID = 1L;
253

254
                    @Override
255
                    protected void populateItem(Item<ApiResponseEntry> item) {
256
                        ApiResponseEntry e = item.getModelObject();
×
257
                        PageParameters params = new PageParameters().add("journal", journalId).add("id", e.get("np")).add("mode", "final");
×
258
                        BookmarkablePageLink<Void> l = new BookmarkablePageLink<Void>("acceptedlink", GenNanopubPage.class, params);
×
259
                        l.add(new Label("acceptedlinktext", "\"" + e.get("label") + "\""));
×
260
                        item.add(l);
×
261
                        IRI firstAuthorIri = Utils.vf.createIRI(e.get("firstAuthor"));
×
262

263
                        // TODO Move this user name extraction to a helper method:
264
                        String username;
265
                        if (User.getName(firstAuthorIri) != null) {
×
266
                            username = User.getShortDisplayName(firstAuthorIri);
×
267
                        } else {
268
                            try {
269
                                Nanopub np = Utils.getAsNanopub(e.get("np"));
×
270
                                username = Utils.getFoafNameMap(np).get(e.get("firstAuthor"));
×
271
                            } catch (Exception ex) {
×
272
                                logger.error("Error getting FOAF name for {} in {}", e.get("firstAuthor"), e.get("np"), ex);
×
273
                                username = User.getShortDisplayName(firstAuthorIri);
×
274
                            }
×
275
                        }
276

277
                        item.add(new Label("acceptednote", "by " + username + " on " + e.get("date").substring(0, 10)));
×
278
                    }
×
279

280
                });
281

282
                c.add(new AjaxLink<>("allaccepted") {
×
283

284
                    private static final long serialVersionUID = 1L;
285

286
                    @Override
287
                    public void onClick(AjaxRequestTarget target) {
288
                        try {
289
                            listData.clear();
×
290
                            listData.addAll(fullList);
×
291
                            target.add(c);
×
292
                            setVisible(false);
×
293
                            target.add(this);
×
294
                        } catch (Exception ex) {
×
295
                            logger.error("Error showing all accepted", ex);
×
296
                        }
×
297
                    }
×
298

299
                }.setVisible(fullList.size() > 10));
×
300

301
            } catch (Exception ex) {
×
302
                logger.error("Error in accepted section", ex);
×
303
            }
×
304
        }
305

306
        if (getConfig().getGeneralReactionsApiCall() != null) {
×
307
            try {
308
                final WebMarkupContainer c = new WebMarkupContainer("reactions-component");
×
309
                c.setOutputMarkupId(true);
×
310
                add(c);
×
311

312
                ApiResponse resp = callApi(getConfig().getGeneralReactionsApiCall(), new HashMap<>());
×
313
                while (resp == null) {
×
314
                    // TODO Do this in an AJAX way:
315
                    try {
316
                        Thread.sleep(200);
×
317
                    } catch (InterruptedException ex) {
×
318
                    }
×
319
                    resp = callApi(getConfig().getGeneralReactionsApiCall(), new HashMap<>());
×
320
                }
321

322
                final List<ApiResponseEntry> listData = new ArrayList<ApiResponseEntry>();
×
323
                final ArrayList<ApiResponseEntry> fullList = new ArrayList<>();
×
324
                for (ApiResponseEntry a : resp.getData()) {
×
325
                    if (listData.size() < 10) listData.add(a);
×
326
                    // TODO This will become inefficient at some point:
327
                    fullList.add(a);
×
328
                }
×
329

330
                c.add(new DataView<ApiResponseEntry>("reactions", new ListDataProvider<ApiResponseEntry>(listData)) {
×
331

332
                    private static final long serialVersionUID = 1L;
333

334
                    @Override
335
                    protected void populateItem(Item<ApiResponseEntry> item) {
336
                        ApiResponseEntry e = item.getModelObject();
×
337
                        PageParameters params = new PageParameters().add("journal", journalId).add("id", e.get("ref_np")).add("mode", "candidate");
×
338
                        BookmarkablePageLink<Void> l = new BookmarkablePageLink<Void>("reactionlink", GenNanopubPage.class, params);
×
339
                        l.add(new Label("reactionlinktext", "\"" + e.get("comment") + "\""));
×
340
                        item.add(l);
×
341
                        String pubkeyhash = Utils.createSha256HexHash(e.get("pubkey"));
×
342
                        String username = User.getShortDisplayNameForPubkeyhash(null, pubkeyhash);
×
343
                        item.add(new Label("reactionnote", "by " + username + " on " + e.get("date").substring(0, 10)));
×
344
                    }
×
345

346
                });
347

348
                c.add(new AjaxLink<>("allreactions") {
×
349

350
                    private static final long serialVersionUID = 1L;
351

352
                    @Override
353
                    public void onClick(AjaxRequestTarget target) {
354
                        try {
355
                            listData.clear();
×
356
                            listData.addAll(fullList);
×
357
                            target.add(c);
×
358
                            setVisible(false);
×
359
                            target.add(this);
×
360
                        } catch (Exception ex) {
×
361
                            logger.error("Error showing all reactions", ex);
×
362
                        }
×
363
                    }
×
364

365
                }.setVisible(fullList.size() > 10));
×
366

367
            } catch (Exception ex) {
×
368
                logger.error("Error in reactions section", ex);
×
369
            }
×
370
        }
371

372
        add(new Label("pagetitle", config.getJournalName() + " | nanodash"));
×
373
        add(new Label("journal-name-title", config.getJournalName()));
×
374
        add(new ExternalLink("journal-link", config.getJournalUrl(), config.getJournalName()));
×
375
        add(new Label("extra-instructions", config.getExtraInstructions()).setEscapeModelStrings(false));
×
376

377
        if (getConfig().getGeneralReactionsApiCall() == null) {
×
378
            // TODO Fix this in OverviewPage code once refactoring is finished:
379
            add(new Label("reactions-component").setVisible(false));
×
380
        }
381
        add(new ExternalLink("support-link", "mailto:contact-project+knowledgepixels-support-desk@incoming.gitlab.com?subject=[" + config.getJournalAbbrev() + "%20general]%20my%20problem/question&body=type%20your%20problem/question%20here"));
×
382
    }
×
383

384
    /**
385
     * {@inheritDoc}
386
     */
387
    @Override
388
    public String getMountPath() {
389
        return MOUNT_PATH;
×
390
    }
391

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