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

knowledgepixels / nanodash / 25791103212

13 May 2026 09:40AM UTC coverage: 20.6% (+0.1%) from 20.478%
25791103212

push

github

web-flow
Merge pull request #461 from knowledgepixels/validate-main-urls-against-library

Validate main registry/query URLs against library instance list

1022 of 6264 branches covered (16.32%)

Branch coverage included in aggregate %.

2618 of 11406 relevant lines covered (22.95%)

3.28 hits per line

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

67.66
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.settings.ExceptionSettings;
31
import org.apache.wicket.util.lang.Bytes;
32
import org.nanopub.Nanopub;
33
import org.nanopub.extra.services.QueryRef;
34
import org.slf4j.Logger;
35
import org.slf4j.LoggerFactory;
36

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

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

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

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

63
    private static String latestVersion = null;
6✔
64

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

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

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

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

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

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

137
        Utils.initMainUrls();
3✔
138

139
        getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
15✔
140

141
        getExceptionSettings().setUnexpectedExceptionDisplay(ExceptionSettings.SHOW_NO_EXCEPTION_PAGE);
15✔
142

143
        mountPage(ErrorPage.MOUNT_PATH, ErrorPage.class);
15✔
144
        mountPage("/error/404", ErrorPage.class);
15✔
145
        mountPage("/error/500", ErrorPage.class);
15✔
146

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

189
        getCspSettings().blocking().disabled();
15✔
190
        getStoreSettings().setMaxSizePerSession(Bytes.megabytes(100));
18✔
191

192
        registerListeners();
6✔
193

194
        String umamiScriptUrl = NanodashPreferences.get().getUmamiScriptUrl();
9✔
195
        if (umamiScriptUrl != null && !umamiScriptUrl.isBlank()) {
6!
196
            logger.info("Umami analytics configured: {}", umamiScriptUrl);
×
197
        } else {
198
            logger.info("Umami analytics not configured (set NANODASH_UMAMI_SCRIPT_URL and NANODASH_UMAMI_WEBSITE_ID)");
9✔
199
        }
200
    }
3✔
201

202
    /**
203
     * {@inheritDoc}
204
     * <p>
205
     * Returns the runtime configuration type for the application.
206
     */
207
    @Override
208
    public RuntimeConfigurationType getConfigurationType() {
209
        return RuntimeConfigurationType.DEPLOYMENT;
6✔
210
    }
211

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

226
            Gson gson = new Gson();
12✔
227
            Type nanopubReleasesType = new TypeToken<List<NanodashRelease>>() {
18✔
228
            }.getType();
6✔
229

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

242
    /**
243
     * Properties object to hold application properties.
244
     */
245
    public final static Properties properties = new Properties();
12✔
246

247
    static {
248
        try {
249
            properties.load(WicketApplication.class.getClassLoader().getResourceAsStream("nanodash.properties"));
18✔
250
        } catch (IOException ex) {
×
251
            logger.error("Error in loading properties", ex);
×
252
        }
3✔
253
    }
3✔
254

255
    /**
256
     * Retrieves the current version of the application.
257
     *
258
     * @return The current version as a string.
259
     */
260
    public static String getThisVersion() {
261
        return properties.getProperty("nanodash.version");
12✔
262
    }
263

264
    /**
265
     * {@inheritDoc}
266
     */
267
    @Override
268
    public Session newSession(Request request, Response response) {
269
        return new NanodashSession(request);
15✔
270
    }
271

272
    private void registerListeners() {
273
        logger.info("Registering nanopub published event listeners for spaces, maintained resources, resource with profile and query ref refresh");
9✔
274
        registerListener((nanopub, target, waitMs) -> {
9✔
275
            logger.info("Received nanopub published event with target <{}> and waitMs {}", target, waitMs);
×
276
            if (target.equals("spaces")) {
×
277
                SpaceRepository.get().forceRootRefresh(waitMs);
×
278
            } else if (target.equals("maintainedResources")) {
×
279
                MaintainedResourceRepository.get().forceRootRefresh(waitMs);
×
280
            } else if (AbstractResourceWithProfile.isResourceWithProfile(target)) {
×
281
                AbstractResourceWithProfile resource = AbstractResourceWithProfile.get(target);
×
282
                resource.forceRefresh(waitMs);
×
283
                if (resource instanceof Space) {
×
284
                    SpaceRepository.get().forceRootRefresh(waitMs);
×
285
                    MaintainedResourceRepository.get().forceRootRefresh(waitMs);
×
286
                } else if (resource instanceof MaintainedResource) {
×
287
                    MaintainedResourceRepository.get().forceRootRefresh(waitMs);
×
288
                }
289
            } else {
×
290
                QueryRef queryRef = QueryRef.parseString(target);
×
291
                ApiCache.clearCache(queryRef, waitMs);
×
292
            }
293
        });
×
294
    }
3✔
295

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