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

knowledgepixels / nanodash / 26017712631

18 May 2026 06:39AM UTC coverage: 20.776% (-0.02%) from 20.796%
26017712631

Pull #466

github

web-flow
Merge 5d7f083e9 into d64bcb4ec
Pull Request #466: feat: expose Nanodash-Version response header

1033 of 6280 branches covered (16.45%)

Branch coverage included in aggregate %.

2649 of 11442 relevant lines covered (23.15%)

3.32 hits per line

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

65.52
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.domain.MaintainedResource;
14
import com.knowledgepixels.nanodash.domain.Space;
15
import com.knowledgepixels.nanodash.events.NanopubPublishedListener;
16
import com.knowledgepixels.nanodash.events.NanopubPublishedPublisher;
17
import com.knowledgepixels.nanodash.page.*;
18
import com.knowledgepixels.nanodash.repository.MaintainedResourceRepository;
19
import com.knowledgepixels.nanodash.repository.SpaceRepository;
20
import de.agilecoders.wicket.webjars.WicketWebjars;
21
import org.apache.http.HttpResponse;
22
import org.apache.http.client.methods.HttpGet;
23
import org.apache.http.impl.client.CloseableHttpClient;
24
import org.apache.http.impl.client.HttpClientBuilder;
25
import org.apache.wicket.RuntimeConfigurationType;
26
import org.apache.wicket.Session;
27
import org.apache.wicket.protocol.http.WebApplication;
28
import org.apache.wicket.request.Request;
29
import org.apache.wicket.request.Response;
30
import org.apache.wicket.request.cycle.IRequestCycleListener;
31
import org.apache.wicket.request.cycle.RequestCycle;
32
import org.apache.wicket.request.http.WebResponse;
33
import org.apache.wicket.settings.ExceptionSettings;
34
import org.apache.wicket.util.lang.Bytes;
35
import org.nanopub.Nanopub;
36
import org.nanopub.extra.services.QueryRef;
37
import org.slf4j.Logger;
38
import org.slf4j.LoggerFactory;
39

40
import java.awt.*;
41
import java.io.IOException;
42
import java.io.InputStreamReader;
43
import java.lang.reflect.Type;
44
import java.net.URI;
45
import java.net.URISyntaxException;
46
import java.util.ArrayList;
47
import java.util.Collections;
48
import java.util.List;
49
import java.util.Properties;
50

51
/**
52
 * WicketApplication is the main application class for the Nanodash web application.
53
 * It initializes the application, mounts pages, and provides version information.
54
 */
55
public class WicketApplication extends WebApplication implements NanopubPublishedPublisher {
56

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

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

66
    private static String latestVersion = null;
6✔
67

68
    @Override
69
    public void registerListener(NanopubPublishedListener listener) {
70
        logger.info("Registering listener {} for nanopub published events", listener.getClass().getName());
18✔
71
        publishListeners.add(listener);
15✔
72
    }
3✔
73

74
    @Override
75
    public void notifyNanopubPublished(Nanopub nanopub, String target, long waitMs) {
76
        for (NanopubPublishedListener listener : publishListeners) {
×
77
            listener.onNanopubPublished(nanopub, target, waitMs);
×
78
            logger.info("Notifying listener {} with toRefresh target <{}>", listener.getClass().getName(), target);
×
79
        }
×
80
    }
×
81

82
    /**
83
     * Static method to get the current instance of the WicketApplication.
84
     *
85
     * @return The current instance of WicketApplication.
86
     */
87
    public static WicketApplication get() {
88
        return (WicketApplication) WebApplication.get();
×
89
    }
90

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

121
    /**
122
     * Returns the home page class for the application.
123
     *
124
     * @return The HomePage class.
125
     */
126
    public Class<HomePage> getHomePage() {
127
        return HomePage.class;
6✔
128
    }
129

130
    /**
131
     * {@inheritDoc}
132
     * <p>
133
     * Initializes the application settings and mounts pages.
134
     */
135
    @Override
136
    protected void init() {
137
        super.init();
6✔
138
        WicketWebjars.install(this);
6✔
139

140
        Utils.initMainUrls();
3✔
141

142
        getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
15✔
143

144
        getExceptionSettings().setUnexpectedExceptionDisplay(ExceptionSettings.SHOW_NO_EXCEPTION_PAGE);
15✔
145

146
        mountPage(ErrorPage.MOUNT_PATH, ErrorPage.class);
15✔
147
        mountPage("/error/404", ErrorPage.class);
15✔
148
        mountPage("/error/500", ErrorPage.class);
15✔
149

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

192
        getCspSettings().blocking().disabled();
15✔
193
        getStoreSettings().setMaxSizePerSession(Bytes.megabytes(100));
18✔
194

195
        getRequestCycleListeners().add(new IRequestCycleListener() {
33✔
196
            @Override
197
            public void onBeginRequest(RequestCycle cycle) {
198
                Response response = cycle.getResponse();
×
199
                if (response instanceof WebResponse) {
×
200
                    ((WebResponse) response).setHeader("Nanodash-Version", getThisVersion());
×
201
                }
202
            }
×
203
        });
204

205
        registerListeners();
6✔
206

207
        String umamiScriptUrl = NanodashPreferences.get().getUmamiScriptUrl();
9✔
208
        if (umamiScriptUrl != null && !umamiScriptUrl.isBlank()) {
6!
209
            logger.info("Umami analytics configured: {}", umamiScriptUrl);
×
210
        } else {
211
            logger.info("Umami analytics not configured (set NANODASH_UMAMI_SCRIPT_URL and NANODASH_UMAMI_WEBSITE_ID)");
9✔
212
        }
213
    }
3✔
214

215
    /**
216
     * {@inheritDoc}
217
     * <p>
218
     * Returns the runtime configuration type for the application.
219
     */
220
    @Override
221
    public RuntimeConfigurationType getConfigurationType() {
222
        return RuntimeConfigurationType.DEPLOYMENT;
6✔
223
    }
224

225
    /**
226
     * Retrieves the latest version of the application from the GitHub API.
227
     *
228
     * @return The latest version as a string.
229
     */
230
    public static String getLatestVersion() {
231
        if (latestVersion != null) return latestVersion;
12✔
232
        try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
9✔
233
            HttpResponse resp = client.execute(new HttpGet(LATEST_RELEASE_URL));
21✔
234
            int c = resp.getStatusLine().getStatusCode();
12✔
235
            if (c < 200 || c >= 300) {
18!
236
                throw new HttpStatusException(c);
×
237
            }
238

239
            Gson gson = new Gson();
12✔
240
            Type nanopubReleasesType = new TypeToken<List<NanodashRelease>>() {
18✔
241
            }.getType();
6✔
242

243
            try (InputStreamReader reader = new InputStreamReader(resp.getEntity().getContent())) {
21✔
244
                List<NanodashRelease> releases = gson.fromJson(reader, nanopubReleasesType);
18✔
245
                if (!releases.isEmpty()) {
9!
246
                    latestVersion = releases.getFirst().getVersionNumber();
15✔
247
                }
248
            }
249
        } catch (Exception ex) {
×
250
            logger.error("Error in fetching latest version", ex);
×
251
        }
3✔
252
        return latestVersion;
6✔
253
    }
254

255
    /**
256
     * Properties object to hold application properties.
257
     */
258
    public final static Properties properties = new Properties();
12✔
259

260
    static {
261
        try {
262
            properties.load(WicketApplication.class.getClassLoader().getResourceAsStream("nanodash.properties"));
18✔
263
        } catch (IOException ex) {
×
264
            logger.error("Error in loading properties", ex);
×
265
        }
3✔
266
    }
3✔
267

268
    /**
269
     * Retrieves the current version of the application.
270
     *
271
     * @return The current version as a string.
272
     */
273
    public static String getThisVersion() {
274
        return properties.getProperty("nanodash.version");
12✔
275
    }
276

277
    /**
278
     * {@inheritDoc}
279
     */
280
    @Override
281
    public Session newSession(Request request, Response response) {
282
        return new NanodashSession(request);
15✔
283
    }
284

285
    private void registerListeners() {
286
        logger.info("Registering nanopub published event listeners for spaces, maintained resources, resource with profile and query ref refresh");
9✔
287
        registerListener((nanopub, target, waitMs) -> {
9✔
288
            logger.info("Received nanopub published event with target <{}> and waitMs {}", target, waitMs);
×
289
            if (target.equals("spaces")) {
×
290
                SpaceRepository.get().forceRootRefresh(waitMs);
×
291
            } else if (target.equals("maintainedResources")) {
×
292
                MaintainedResourceRepository.get().forceRootRefresh(waitMs);
×
293
            } else if (AbstractResourceWithProfile.isResourceWithProfile(target)) {
×
294
                AbstractResourceWithProfile resource = AbstractResourceWithProfile.get(target);
×
295
                resource.forceRefresh(waitMs);
×
296
                if (resource instanceof Space) {
×
297
                    SpaceRepository.get().forceRootRefresh(waitMs);
×
298
                    MaintainedResourceRepository.get().forceRootRefresh(waitMs);
×
299
                } else if (resource instanceof MaintainedResource) {
×
300
                    MaintainedResourceRepository.get().forceRootRefresh(waitMs);
×
301
                }
302
            } else {
×
303
                QueryRef queryRef = QueryRef.parseString(target);
×
304
                ApiCache.clearCache(queryRef, waitMs);
×
305
            }
306
        });
×
307
    }
3✔
308

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