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

knowledgepixels / nanodash / 23133101585

16 Mar 2026 07:45AM UTC coverage: 15.984% (+0.2%) from 15.811%
23133101585

Pull #402

github

web-flow
Merge bd8288c47 into 39c6ac11c
Pull Request #402: Fix unbounded memory growth and resource exhaustion

717 of 5509 branches covered (13.02%)

Branch coverage included in aggregate %.

1809 of 10294 relevant lines covered (17.57%)

2.39 hits per line

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

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

3
import com.google.gson.Gson;
4
import com.google.gson.reflect.TypeToken;
5
import com.knowledgepixels.nanodash.connector.*;
6
import com.knowledgepixels.nanodash.connector.ios.DsNanopubPage;
7
import com.knowledgepixels.nanodash.connector.ios.DsOverviewPage;
8
import com.knowledgepixels.nanodash.connector.pensoft.BdjNanopubPage;
9
import com.knowledgepixels.nanodash.connector.pensoft.BdjOverviewPage;
10
import com.knowledgepixels.nanodash.connector.pensoft.RioNanopubPage;
11
import com.knowledgepixels.nanodash.connector.pensoft.RioOverviewPage;
12
import com.knowledgepixels.nanodash.domain.AbstractResourceWithProfile;
13
import com.knowledgepixels.nanodash.events.NanopubPublishedListener;
14
import com.knowledgepixels.nanodash.events.NanopubPublishedPublisher;
15
import com.knowledgepixels.nanodash.page.*;
16
import com.knowledgepixels.nanodash.repository.MaintainedResourceRepository;
17
import com.knowledgepixels.nanodash.repository.SpaceRepository;
18
import de.agilecoders.wicket.webjars.WicketWebjars;
19
import org.apache.http.HttpResponse;
20
import org.apache.http.client.methods.HttpGet;
21
import org.apache.http.impl.client.CloseableHttpClient;
22
import org.apache.http.impl.client.HttpClientBuilder;
23
import org.apache.wicket.RuntimeConfigurationType;
24
import org.apache.wicket.Session;
25
import org.apache.wicket.protocol.http.WebApplication;
26
import org.apache.wicket.request.Request;
27
import org.apache.wicket.request.Response;
28
import org.apache.wicket.settings.ExceptionSettings;
29
import org.apache.wicket.util.lang.Bytes;
30
import org.nanopub.Nanopub;
31
import org.nanopub.extra.services.QueryRef;
32
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
34

35
import java.awt.*;
36
import java.io.IOException;
37
import java.io.InputStreamReader;
38
import java.lang.reflect.Type;
39
import java.net.URI;
40
import java.net.URISyntaxException;
41
import java.util.ArrayList;
42
import java.util.Collections;
43
import java.util.List;
44
import java.util.Properties;
45

46
/**
47
 * WicketApplication is the main application class for the Nanodash web application.
48
 * It initializes the application, mounts pages, and provides version information.
49
 */
50
public class WicketApplication extends WebApplication implements NanopubPublishedPublisher {
51

52
    /**
53
     * URL to fetch the latest release information from GitHub.
54
     * This URL points to the releases of the Nanodash repository.
55
     */
56
    public static final String LATEST_RELEASE_URL = "https://api.github.com/repos/knowledgepixels/nanodash/releases";
57
    private static final Logger logger = LoggerFactory.getLogger(WicketApplication.class);
9✔
58

59
    private final List<NanopubPublishedListener> publishListeners = Collections.synchronizedList(new ArrayList<>());
18✔
60

61
    private static String latestVersion = null;
6✔
62

63
    @Override
64
    public void registerListener(NanopubPublishedListener listener) {
65
        logger.info("Registering listener {} for nanopub published events", listener.getClass().getName());
18✔
66
        publishListeners.add(listener);
15✔
67
    }
3✔
68

69
    @Override
70
    public void notifyNanopubPublished(Nanopub nanopub, String target, long waitMs) {
71
        for (NanopubPublishedListener listener : publishListeners) {
×
72
            listener.onNanopubPublished(nanopub, target, waitMs);
×
73
            logger.info("Notifying listener {} with toRefresh target <{}>", listener.getClass().getName(), target);
×
74
        }
×
75
    }
×
76

77
    /**
78
     * Static method to get the current instance of the WicketApplication.
79
     *
80
     * @return The current instance of WicketApplication.
81
     */
82
    public static WicketApplication get() {
83
        return (WicketApplication) WebApplication.get();
×
84
    }
85

86
    /**
87
     * Constructor for the WicketApplication.
88
     * Displays version information and provides instructions for accessing the application.
89
     */
90
    public WicketApplication() {
6✔
91
        if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
6!
92
            try {
93
                Desktop.getDesktop().browse(new URI("http://localhost:37373"));
×
94
            } catch (IOException | URISyntaxException ex) {
×
95
                logger.error("Error in opening browser", ex);
×
96
            }
×
97
        }
98
        String v = getThisVersion();
6✔
99
        String lv = getLatestVersion();
6✔
100
        System.err.println("");
9✔
101
        System.err.println("----------------------------------------");
9✔
102
        System.err.println("               Nanodash");
9✔
103
        System.err.println("----------------------------------------");
9✔
104
        System.err.println(" You are using version: " + v);
12✔
105
        System.err.println(" Latest public version: " + lv);
12✔
106
        System.err.println("----------------------------------------");
9✔
107
        System.err.println(" Your browser should show the Nanodash");
9✔
108
        System.err.println(" interface in a few seconds.");
9✔
109
        System.err.println("");
9✔
110
        System.err.println(" If not, point your browser to:");
9✔
111
        System.err.println(" http://localhost:37373");
9✔
112
        System.err.println("----------------------------------------");
9✔
113
        System.err.println("");
9✔
114
    }
3✔
115

116
    /**
117
     * Returns the home page class for the application.
118
     *
119
     * @return The HomePage class.
120
     */
121
    public Class<HomePage> getHomePage() {
122
        return HomePage.class;
6✔
123
    }
124

125
    /**
126
     * {@inheritDoc}
127
     * <p>
128
     * Initializes the application settings and mounts pages.
129
     */
130
    @Override
131
    protected void init() {
132
        super.init();
6✔
133
        WicketWebjars.install(this);
6✔
134

135
        getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
15✔
136

137
        getExceptionSettings().setUnexpectedExceptionDisplay(ExceptionSettings.SHOW_NO_EXCEPTION_PAGE);
15✔
138

139
        mountPage(ErrorPage.MOUNT_PATH, ErrorPage.class);
15✔
140
        mountPage("/error/404", ErrorPage.class);
15✔
141
        mountPage("/error/500", ErrorPage.class);
15✔
142

143
        mountPage(UserPage.MOUNT_PATH, UserPage.class);
15✔
144
        mountPage(ChannelPage.MOUNT_PATH, ChannelPage.class);
15✔
145
        mountPage(SearchPage.MOUNT_PATH, SearchPage.class);
15✔
146
        mountPage(ExplorePage.MOUNT_PATH, ExplorePage.class);
15✔
147
        mountPage(PublishPage.MOUNT_PATH, PublishPage.class);
15✔
148
        mountPage(PreviewPage.MOUNT_PATH, PreviewPage.class);
15✔
149
        mountPage(ProfilePage.MOUNT_PATH, ProfilePage.class);
15✔
150
        mountPage(UserListPage.MOUNT_PATH, UserListPage.class);
15✔
151
        mountPage(GroupDemoPage.MOUNT_PATH, GroupDemoPage.class);
15✔
152
        mountPage(GroupDemoPageSoc.MOUNT_PATH, GroupDemoPageSoc.class);
15✔
153
        mountPage(OrcidLinkingPage.MOUNT_PATH, OrcidLinkingPage.class);
15✔
154
        mountPage(OrcidLoginPage.MOUNT_PATH, OrcidLoginPage.class);
15✔
155
        mountPage(SpaceListPage.MOUNT_PATH, SpaceListPage.class);
15✔
156
        mountPage(MyChannelPage.MOUNT_PATH, MyChannelPage.class);
15✔
157
        mountPage(TermForwarder.MOUNT_PATH, TermForwarder.class);
15✔
158
        mountPage(ViewPage.MOUNT_PATH, ViewPage.class);
15✔
159
        mountPage(GetViewPage.MOUNT_PATH, GetViewPage.class);
15✔
160
        mountPage(DsOverviewPage.MOUNT_PATH, DsOverviewPage.class);
15✔
161
        mountPage(DsNanopubPage.MOUNT_PATH, DsNanopubPage.class);
15✔
162
        mountPage(RioOverviewPage.MOUNT_PATH, RioOverviewPage.class);
15✔
163
        mountPage(RioNanopubPage.MOUNT_PATH, RioNanopubPage.class);
15✔
164
        mountPage(BdjOverviewPage.MOUNT_PATH, BdjOverviewPage.class);
15✔
165
        mountPage(BdjNanopubPage.MOUNT_PATH, BdjNanopubPage.class);
15✔
166
        mountPage(FdoForwarder.MOUNT_PATH, FdoForwarder.class);
15✔
167
        mountPage(GetNamePage.MOUNT_PATH, GetNamePage.class);
15✔
168
        mountPage(TestPage.MOUNT_PATH, TestPage.class);
15✔
169
        mountPage(ResultTablePage.MOUNT_PATH, ResultTablePage.class);
15✔
170
        mountPage(GenOverviewPage.MOUNT_PATH, GenOverviewPage.class);
15✔
171
        mountPage(GenSelectPage.MOUNT_PATH, GenSelectPage.class);
15✔
172
        mountPage(GenPublishPage.MOUNT_PATH, GenPublishPage.class);
15✔
173
        mountPage(GenConnectPage.MOUNT_PATH, GenConnectPage.class);
15✔
174
        mountPage(GenNanopubPage.MOUNT_PATH, GenNanopubPage.class);
15✔
175
        mountPage(ProjectPage.MOUNT_PATH, ProjectPage.class);
15✔
176
        mountPage(SpacePage.MOUNT_PATH, SpacePage.class);
15✔
177
        mountPage(QueryPage.MOUNT_PATH, QueryPage.class);
15✔
178
        mountPage(QueryListPage.MOUNT_PATH, QueryListPage.class);
15✔
179
        mountPage(ListPage.MOUNT_PATH, ListPage.class);
15✔
180
        mountPage(MaintainedResourcePage.MOUNT_PATH, MaintainedResourcePage.class);
15✔
181
        mountPage(ResourcePartPage.MOUNT_PATH, ResourcePartPage.class);
15✔
182

183
        getCspSettings().blocking().disabled();
15✔
184
        getStoreSettings().setMaxSizePerSession(Bytes.MAX);
15✔
185

186
        registerListeners();
6✔
187

188
        String umamiScriptUrl = NanodashPreferences.get().getUmamiScriptUrl();
9✔
189
        if (umamiScriptUrl != null && !umamiScriptUrl.isBlank()) {
6!
190
            logger.info("Umami analytics configured: {}", umamiScriptUrl);
×
191
        } else {
192
            logger.info("Umami analytics not configured (set NANODASH_UMAMI_SCRIPT_URL and NANODASH_UMAMI_WEBSITE_ID)");
9✔
193
        }
194
    }
3✔
195

196
    /**
197
     * {@inheritDoc}
198
     * <p>
199
     * Returns the runtime configuration type for the application.
200
     */
201
    @Override
202
    public RuntimeConfigurationType getConfigurationType() {
203
        return RuntimeConfigurationType.DEPLOYMENT;
6✔
204
    }
205

206
    /**
207
     * Retrieves the latest version of the application from the GitHub API.
208
     *
209
     * @return The latest version as a string.
210
     */
211
    public static String getLatestVersion() {
212
        if (latestVersion != null) return latestVersion;
12✔
213
        try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
9✔
214
            HttpResponse resp = client.execute(new HttpGet(LATEST_RELEASE_URL));
21✔
215
            int c = resp.getStatusLine().getStatusCode();
12✔
216
            if (c < 200 || c >= 300) {
18!
217
                throw new HttpStatusException(c);
×
218
            }
219

220
            Gson gson = new Gson();
12✔
221
            Type nanopubReleasesType = new TypeToken<List<NanodashRelease>>() {
18✔
222
            }.getType();
6✔
223

224
            try (InputStreamReader reader = new InputStreamReader(resp.getEntity().getContent())) {
21✔
225
                List<NanodashRelease> releases = gson.fromJson(reader, nanopubReleasesType);
18✔
226
                if (!releases.isEmpty()) {
9!
227
                    latestVersion = releases.getFirst().getVersionNumber();
15✔
228
                }
229
            }
230
        } catch (Exception ex) {
×
231
            logger.error("Error in fetching latest version", ex);
×
232
        }
3✔
233
        return latestVersion;
6✔
234
    }
235

236
    /**
237
     * Properties object to hold application properties.
238
     */
239
    public final static Properties properties = new Properties();
12✔
240

241
    static {
242
        try {
243
            properties.load(WicketApplication.class.getClassLoader().getResourceAsStream("nanodash.properties"));
18✔
244
        } catch (IOException ex) {
×
245
            logger.error("Error in loading properties", ex);
×
246
        }
3✔
247
    }
3✔
248

249
    /**
250
     * Retrieves the current version of the application.
251
     *
252
     * @return The current version as a string.
253
     */
254
    public static String getThisVersion() {
255
        return properties.getProperty("nanodash.version");
12✔
256
    }
257

258
    /**
259
     * {@inheritDoc}
260
     */
261
    @Override
262
    public Session newSession(Request request, Response response) {
263
        return new NanodashSession(request);
15✔
264
    }
265

266
    private void registerListeners() {
267
        logger.info("Registering nanopub published event listeners for spaces, maintained resources, resource with profile and query ref refresh");
9✔
268
        registerListener((nanopub, target, waitMs) -> {
9✔
269
            logger.info("Received nanopub published event with target <{}> and waitMs {}", target, waitMs);
×
270
            if (target.equals("spaces")) {
×
271
                SpaceRepository.get().forceRootRefresh(waitMs);
×
272
            } else if (target.equals("maintainedResources")) {
×
273
                MaintainedResourceRepository.get().forceRootRefresh(waitMs);
×
274
            } else if (AbstractResourceWithProfile.isResourceWithProfile(target)) {
×
275
                AbstractResourceWithProfile.get(target).forceRefresh(waitMs);
×
276
            } else {
277
                QueryRef queryRef = QueryRef.parseString(target);
×
278
                ApiCache.clearCache(queryRef, waitMs);
×
279
            }
280
        });
×
281
    }
3✔
282

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