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

knowledgepixels / nanodash / 27739803358

18 Jun 2026 05:55AM UTC coverage: 26.658% (-0.3%) from 26.963%
27739803358

Pull #484

github

web-flow
Merge 9d6502630 into 0f6281554
Pull Request #484: Space-ref disambiguation: conflict notice, claimants overview, ref-pinned pages

1545 of 6821 branches covered (22.65%)

Branch coverage included in aggregate %.

3414 of 11781 relevant lines covered (28.98%)

4.26 hits per line

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

62.3
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.IRequestHandler;
31
import org.apache.wicket.request.cycle.IRequestCycleListener;
32
import org.apache.wicket.request.cycle.RequestCycle;
33
import org.apache.wicket.request.http.WebResponse;
34
import org.apache.wicket.settings.ExceptionSettings;
35
import org.apache.wicket.util.lang.Bytes;
36
import org.nanopub.Nanopub;
37
import org.nanopub.extra.services.QueryRef;
38
import org.slf4j.Logger;
39
import org.slf4j.LoggerFactory;
40

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

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

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

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

67
    private static String latestVersion = null;
6✔
68

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

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

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

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

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

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

141
        Utils.initMainUrls();
3✔
142

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

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

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

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

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

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

205
            @Override
206
            public IRequestHandler onException(RequestCycle cycle, Exception ex) {
207
                logger.error("Unhandled exception during request [{}]", cycle.getRequest().getUrl(), ex);
×
208
                Throwable cause = ex.getCause();
×
209
                int depth = 1;
×
210
                while (cause != null) {
×
211
                    logger.error("  Caused by (depth {}): {}", depth++, cause.getMessage(), cause);
×
212
                    cause = cause.getCause();
×
213
                }
214
                return null;
×
215
            }
216
        });
217

218
        registerListeners();
6✔
219

220
        String umamiScriptUrl = NanodashPreferences.get().getUmamiScriptUrl();
9✔
221
        if (umamiScriptUrl != null && !umamiScriptUrl.isBlank()) {
6!
222
            logger.info("Umami analytics configured: {}", umamiScriptUrl);
×
223
        } else {
224
            logger.info("Umami analytics not configured (set NANODASH_UMAMI_SCRIPT_URL and NANODASH_UMAMI_WEBSITE_ID)");
9✔
225
        }
226
    }
3✔
227

228
    /**
229
     * {@inheritDoc}
230
     * <p>
231
     * Returns the runtime configuration type for the application.
232
     */
233
    @Override
234
    public RuntimeConfigurationType getConfigurationType() {
235
        return RuntimeConfigurationType.DEPLOYMENT;
6✔
236
    }
237

238
    /**
239
     * Retrieves the latest version of the application from the GitHub API.
240
     *
241
     * @return The latest version as a string.
242
     */
243
    public static String getLatestVersion() {
244
        if (latestVersion != null) return latestVersion;
12✔
245
        try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
9✔
246
            HttpResponse resp = client.execute(new HttpGet(LATEST_RELEASE_URL));
21✔
247
            int c = resp.getStatusLine().getStatusCode();
12✔
248
            if (c < 200 || c >= 300) {
18!
249
                throw new HttpStatusException(c);
×
250
            }
251

252
            Gson gson = new Gson();
12✔
253
            Type nanopubReleasesType = new TypeToken<List<NanodashRelease>>() {
18✔
254
            }.getType();
6✔
255

256
            try (InputStreamReader reader = new InputStreamReader(resp.getEntity().getContent())) {
21✔
257
                List<NanodashRelease> releases = gson.fromJson(reader, nanopubReleasesType);
18✔
258
                if (!releases.isEmpty()) {
9!
259
                    latestVersion = releases.getFirst().getVersionNumber();
15✔
260
                }
261
            }
262
        } catch (Exception ex) {
×
263
            logger.error("Error in fetching latest version", ex);
×
264
        }
3✔
265
        return latestVersion;
6✔
266
    }
267

268
    /**
269
     * Properties object to hold application properties.
270
     */
271
    public final static Properties properties = new Properties();
12✔
272

273
    static {
274
        try {
275
            properties.load(WicketApplication.class.getClassLoader().getResourceAsStream("nanodash.properties"));
18✔
276
        } catch (IOException ex) {
×
277
            logger.error("Error in loading properties", ex);
×
278
        }
3✔
279
    }
3✔
280

281
    /**
282
     * Retrieves the current version of the application.
283
     *
284
     * @return The current version as a string.
285
     */
286
    public static String getThisVersion() {
287
        return properties.getProperty("nanodash.version");
12✔
288
    }
289

290
    /**
291
     * {@inheritDoc}
292
     */
293
    @Override
294
    public Session newSession(Request request, Response response) {
295
        return new NanodashSession(request);
15✔
296
    }
297

298
    private void registerListeners() {
299
        logger.info("Registering nanopub published event listeners for spaces, maintained resources, resource with profile and query ref refresh");
9✔
300
        registerListener((nanopub, target, waitMs) -> {
9✔
301
            logger.info("Received nanopub published event with target <{}> and waitMs {}", target, waitMs);
×
302
            if (target.equals("spaces")) {
×
303
                SpaceRepository.get().forceRootRefresh(waitMs);
×
304
            } else if (target.equals("maintainedResources")) {
×
305
                MaintainedResourceRepository.get().forceRootRefresh(waitMs);
×
306
            } else if (AbstractResourceWithProfile.isResourceWithProfile(target)) {
×
307
                AbstractResourceWithProfile resource = AbstractResourceWithProfile.get(target);
×
308
                resource.forceRefresh(waitMs);
×
309
                if (resource instanceof Space) {
×
310
                    SpaceRepository.get().forceRootRefresh(waitMs);
×
311
                    MaintainedResourceRepository.get().forceRootRefresh(waitMs);
×
312
                } else if (resource instanceof MaintainedResource) {
×
313
                    MaintainedResourceRepository.get().forceRootRefresh(waitMs);
×
314
                }
315
            } else {
×
316
                QueryRef queryRef = QueryRef.parseString(target);
×
317
                ApiCache.clearCache(queryRef, waitMs);
×
318
            }
319
        });
×
320
    }
3✔
321

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