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

3
import com.knowledgepixels.nanodash.ApiCache;
4
import com.knowledgepixels.nanodash.Utils;
5
import com.knowledgepixels.nanodash.component.NanopubResults;
6
import com.knowledgepixels.nanodash.component.TitleBar;
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.ExternalLink;
11
import org.apache.wicket.request.flow.RedirectToUrlException;
12
import org.apache.wicket.request.mapper.parameter.PageParameters;
13
import org.eclipse.rdf4j.model.IRI;
14
import org.nanopub.extra.services.ApiResponse;
15
import org.slf4j.Logger;
16
import org.slf4j.LoggerFactory;
17

18
import java.util.HashMap;
19
import java.util.Map;
20
import java.util.Optional;
21

22
/**
23
 * Page that displays all nanopublications of a specific type.
24
 */
25
public class TypePage extends NanodashPage {
26

27
    private static final long serialVersionUID = 1L;
28

29
    /**
30
     * The mount path for this page.
31
     */
32
    public static final String MOUNT_PATH = "/type";
33

34
    /**
35
     * {@inheritDoc}
36
     */
37
    @Override
38
    public String getMountPath() {
39
        return MOUNT_PATH;
×
40
    }
41

42
    private IRI typeIri;
43
    private boolean added = false;
×
44
    private static final Logger logger = LoggerFactory.getLogger(TypePage.class);
×
45

46
    /**
47
     * Constructor for the TypePage.
48
     *
49
     * @param parameters Page parameters containing the type IRI.
50
     */
51
    public TypePage(final PageParameters parameters) {
52
        super(parameters);
×
53

54
        if (parameters.get("id") == null) throw new RedirectToUrlException(HomePage.MOUNT_PATH);
×
55
        typeIri = Utils.vf.createIRI(parameters.get("id").toString());
×
56

57
        add(new TitleBar("titlebar", this, null));
×
58

59
        final String displayName = Utils.getTypeLabel(typeIri);
×
60
        add(new Label("pagetitle", displayName + " (type) | nanodash"));
×
61
        add(new Label("type", displayName));
×
62

63
        add(new ExternalLink("urilink", typeIri.stringValue(), typeIri.stringValue()));
×
64

65
        refresh();
×
66
    }
×
67

68
    /**
69
     * <p>hasAutoRefreshEnabled.</p>
70
     *
71
     * @return a boolean
72
     */
73
    protected boolean hasAutoRefreshEnabled() {
74
        return true;
×
75
    }
76

77
    private synchronized void refresh() {
78
        if (added) {
×
79
            remove("nanopubs");
×
80
        }
81
        added = true;
×
82
        final Map<String, String> params = new HashMap<>();
×
83
        params.put("type", typeIri.stringValue());
×
84
        final String queryName = "get-latest-nanopubs-by-type";
×
85
        ApiResponse cachedResponse = ApiCache.retrieveResponse(queryName, params);
×
86
        if (cachedResponse != null) {
×
87
            add(NanopubResults.fromApiResponse("nanopubs", cachedResponse));
×
88
        } else {
89
            add(new AjaxLazyLoadPanel<NanopubResults>("nanopubs") {
×
90

91
                private static final long serialVersionUID = 1L;
92

93
                @Override
94
                public NanopubResults getLazyLoadComponent(String markupId) {
95
                    ApiResponse r = null;
×
96
                    while (true) {
97
                        try {
98
                            Thread.sleep(500);
×
99
                        } catch (InterruptedException ex) {
×
100
                            logger.error("Interrupted while waiting for API response", ex);
×
101
                        }
×
102
                        if (!ApiCache.isRunning(queryName, params)) {
×
103
                            r = ApiCache.retrieveResponse(queryName, params);
×
104
                            if (r != null) break;
×
105
                        }
106
                    }
107
                    return NanopubResults.fromApiResponse(markupId, r);
×
108
                }
109

110
                @Override
111
                protected void onContentLoaded(NanopubResults content, Optional<AjaxRequestTarget> target) {
112
                    super.onContentLoaded(content, target);
×
113
                    if (target.isPresent()) {
×
114
                        target.get().appendJavaScript("updateElements();");
×
115
                    }
116
                }
×
117

118
            });
119
        }
120
    }
×
121

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