• 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

85.59
src/main/java/com/knowledgepixels/nanodash/WicketApplication.java
1
package com.knowledgepixels.nanodash;
2

3
import com.knowledgepixels.nanodash.connector.*;
4
import com.knowledgepixels.nanodash.connector.ios.DsNanopubPage;
5
import com.knowledgepixels.nanodash.connector.ios.DsOverviewPage;
6
import com.knowledgepixels.nanodash.connector.pensoft.BdjNanopubPage;
7
import com.knowledgepixels.nanodash.connector.pensoft.BdjOverviewPage;
8
import com.knowledgepixels.nanodash.connector.pensoft.RioNanopubPage;
9
import com.knowledgepixels.nanodash.connector.pensoft.RioOverviewPage;
10
import com.knowledgepixels.nanodash.page.*;
11
import org.apache.http.HttpResponse;
12
import org.apache.http.client.methods.HttpGet;
13
import org.apache.http.impl.client.CloseableHttpClient;
14
import org.apache.http.impl.client.HttpClientBuilder;
15
import org.apache.wicket.RuntimeConfigurationType;
16
import org.apache.wicket.Session;
17
import org.apache.wicket.protocol.http.WebApplication;
18
import org.apache.wicket.request.Request;
19
import org.apache.wicket.request.Response;
20
import org.apache.wicket.settings.ExceptionSettings;
21
import org.slf4j.Logger;
22
import org.slf4j.LoggerFactory;
23

24
import java.awt.*;
25
import java.io.BufferedReader;
26
import java.io.IOException;
27
import java.io.InputStreamReader;
28
import java.net.URI;
29
import java.net.URISyntaxException;
30
import java.util.Properties;
31

32
/**
33
 * WicketApplication is the main application class for the Nanodash web application.
34
 * It initializes the application, mounts pages, and provides version information.
35
 */
36
public class WicketApplication extends WebApplication {
37

38
    /**
39
     * URL to fetch the latest release information from GitHub.
40
     * This URL points to the releases of the Nanodash repository.
41
     */
42
    public static final String LATEST_RELEASE_URL = "https://api.github.com/repos/knowledgepixels/nanodash/releases";
43
    private static final Logger logger = LoggerFactory.getLogger(WicketApplication.class);
3✔
44

45
    /**
46
     * Constructor for the WicketApplication.
47
     * Displays version information and provides instructions for accessing the application.
48
     */
49
    public WicketApplication() {
2✔
50
        if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
2!
51
            try {
52
                Desktop.getDesktop().browse(new URI("http://localhost:37373"));
×
53
            } catch (IOException | URISyntaxException ex) {
×
54
                logger.error("Error in opening browser", ex);
×
55
            }
×
56
        }
57
        String v = getThisVersion();
2✔
58
        String lv = getLatestVersion();
2✔
59
        System.err.println("");
3✔
60
        System.err.println("----------------------------------------");
3✔
61
        System.err.println("               Nanodash");
3✔
62
        System.err.println("----------------------------------------");
3✔
63
        System.err.println(" You are using version: " + v);
4✔
64
        System.err.println(" Latest public version: " + lv);
4✔
65
        System.err.println("----------------------------------------");
3✔
66
        System.err.println(" Your browser should show the Nanodash");
3✔
67
        System.err.println(" interface in a few seconds.");
3✔
68
        System.err.println("");
3✔
69
        System.err.println(" If not, point your browser to:");
3✔
70
        System.err.println(" http://localhost:37373");
3✔
71
        System.err.println("----------------------------------------");
3✔
72
        System.err.println("");
3✔
73
    }
1✔
74

75
    /**
76
     * Returns the home page class for the application.
77
     *
78
     * @return The HomePage class.
79
     */
80
    public Class<HomePage> getHomePage() {
81
        return HomePage.class;
2✔
82
    }
83

84
    /**
85
     * {@inheritDoc}
86
     * <p>
87
     * Initializes the application settings and mounts pages.
88
     */
89
    @Override
90
    protected void init() {
91
        super.init();
2✔
92

93
        getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
5✔
94

95
        getExceptionSettings().setUnexpectedExceptionDisplay(ExceptionSettings.SHOW_NO_EXCEPTION_PAGE);
5✔
96

97
        mountPage(ErrorPage.MOUNT_PATH, ErrorPage.class);
5✔
98
        mountPage("/error/404", ErrorPage.class);
5✔
99
        mountPage("/error/500", ErrorPage.class);
5✔
100

101
        mountPage(UserPage.MOUNT_PATH, UserPage.class);
5✔
102
        mountPage(ChannelPage.MOUNT_PATH, ChannelPage.class);
5✔
103
        mountPage(SearchPage.MOUNT_PATH, SearchPage.class);
5✔
104
        mountPage(ExplorePage.MOUNT_PATH, ExplorePage.class);
5✔
105
        mountPage(ReferenceTablePage.MOUNT_PATH, ReferenceTablePage.class);
5✔
106
        mountPage(PublishPage.MOUNT_PATH, PublishPage.class);
5✔
107
        mountPage(PublishConfirmPage.MOUNT_PATH, PublishConfirmPage.class);
5✔
108
        mountPage(ProfilePage.MOUNT_PATH, ProfilePage.class);
5✔
109
        mountPage(UserListPage.MOUNT_PATH, UserListPage.class);
5✔
110
        mountPage(GroupDemoPage.MOUNT_PATH, GroupDemoPage.class);
5✔
111
        mountPage(GroupDemoPageSoc.MOUNT_PATH, GroupDemoPageSoc.class);
5✔
112
        mountPage(OrcidLinkingPage.MOUNT_PATH, OrcidLinkingPage.class);
5✔
113
        mountPage(OrcidLoginPage.MOUNT_PATH, OrcidLoginPage.class);
5✔
114
        mountPage(ConnectorListPage.MOUNT_PATH, ConnectorListPage.class);
5✔
115
        mountPage(MyChannelPage.MOUNT_PATH, MyChannelPage.class);
5✔
116
        mountPage(TermForwarder.MOUNT_PATH, TermForwarder.class);
5✔
117
        mountPage(ViewPage.MOUNT_PATH, ViewPage.class);
5✔
118
        mountPage(GetViewPage.MOUNT_PATH, GetViewPage.class);
5✔
119
        mountPage(DsOverviewPage.MOUNT_PATH, DsOverviewPage.class);
5✔
120
        mountPage(DsNanopubPage.MOUNT_PATH, DsNanopubPage.class);
5✔
121
        mountPage(RioOverviewPage.MOUNT_PATH, RioOverviewPage.class);
5✔
122
        mountPage(RioNanopubPage.MOUNT_PATH, RioNanopubPage.class);
5✔
123
        mountPage(BdjOverviewPage.MOUNT_PATH, BdjOverviewPage.class);
5✔
124
        mountPage(BdjNanopubPage.MOUNT_PATH, BdjNanopubPage.class);
5✔
125
        mountPage(FdoForwarder.MOUNT_PATH, FdoForwarder.class);
5✔
126
        mountPage(GetNamePage.MOUNT_PATH, GetNamePage.class);
5✔
127
        mountPage(TypePage.MOUNT_PATH, TypePage.class);
5✔
128
        mountPage(TestPage.MOUNT_PATH, TestPage.class);
5✔
129
        mountPage(ThingListPage.MOUNT_PATH, ThingListPage.class);
5✔
130
        mountPage(ResultTablePage.MOUNT_PATH, ResultTablePage.class);
5✔
131
        mountPage(GenOverviewPage.MOUNT_PATH, GenOverviewPage.class);
5✔
132
        mountPage(GenSelectPage.MOUNT_PATH, GenSelectPage.class);
5✔
133
        mountPage(GenPublishPage.MOUNT_PATH, GenPublishPage.class);
5✔
134
        mountPage(GenConnectPage.MOUNT_PATH, GenConnectPage.class);
5✔
135
        mountPage(GenNanopubPage.MOUNT_PATH, GenNanopubPage.class);
5✔
136
        mountPage(ProjectPage.MOUNT_PATH, ProjectPage.class);
5✔
137
        mountPage(QueryPage.MOUNT_PATH, QueryPage.class);
5✔
138
        mountPage(QueryListPage.MOUNT_PATH, QueryListPage.class);
5✔
139

140
        getCspSettings().blocking().disabled();
5✔
141
    }
1✔
142

143
    /**
144
     * {@inheritDoc}
145
     * <p>
146
     * Returns the runtime configuration type for the application.
147
     */
148
    @Override
149
    public RuntimeConfigurationType getConfigurationType() {
150
        return RuntimeConfigurationType.DEPLOYMENT;
2✔
151
    }
152

153

154
    private static String latestVersion = null;
2✔
155

156
    /**
157
     * Retrieves the latest version of the application from the GitHub API.
158
     *
159
     * @return The latest version as a string.
160
     */
161
    public static String getLatestVersion() {
162
        if (latestVersion != null) return latestVersion;
4✔
163
        try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
3✔
164
            HttpResponse resp = client.execute(new HttpGet(LATEST_RELEASE_URL));
7✔
165
            int c = resp.getStatusLine().getStatusCode();
4✔
166
            if (c < 200 || c >= 300) throw new RuntimeException("HTTP error: " + c);
6!
167
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(resp.getEntity().getContent()))) {
10✔
168
                while (reader.ready()) {
3!
169
                    String line = reader.readLine();
3✔
170
                    // TODO: Do proper JSON parsing
171
                    if (line.matches(".*\"tag_name\":\\s*\"nanodash-[0-9]+\\.[0-9]+\".*")) {
4!
172
                        latestVersion = line.replaceFirst(".*?\"tag_name\":\\s*\"nanodash-([0-9]+\\.[0-9]+)\".*", "$1");
5✔
173
                        break;
1✔
174
                    }
175
                }
×
176
            }
177
        } catch (Exception ex) {
×
178
            logger.error("Error in fetching latest version", ex);
×
179
        }
1✔
180
        return latestVersion;
2✔
181
    }
182

183
    /**
184
     * Properties object to hold application properties.
185
     */
186
    public final static Properties properties = new Properties();
4✔
187

188
    static {
189
        try {
190
            properties.load(WicketApplication.class.getClassLoader().getResourceAsStream("nanodash.properties"));
6✔
191
        } catch (IOException ex) {
×
192
            logger.error("Error in loading properties", ex);
×
193
        }
1✔
194
    }
1✔
195

196
    /**
197
     * Retrieves the current version of the application.
198
     *
199
     * @return The current version as a string.
200
     */
201
    public static String getThisVersion() {
202
        return properties.getProperty("nanodash.version");
4✔
203
    }
204

205
    /**
206
     * {@inheritDoc}
207
     */
208
    @Override
209
    public Session newSession(Request request, Response response) {
210
        return new NanodashSession(request);
5✔
211
    }
212

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