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

knowledgepixels / nanodash / 23265765136

18 Mar 2026 08:34PM UTC coverage: 16.251% (-0.02%) from 16.273%
23265765136

Pull #406

github

web-flow
Merge 50e7060f4 into 399d749bf
Pull Request #406: Redesign Explore page layout and extract References page

728 of 5521 branches covered (13.19%)

Branch coverage included in aggregate %.

1850 of 10343 relevant lines covered (17.89%)

2.44 hits per line

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

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

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

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

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

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

62
    private static String latestVersion = null;
6✔
63

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

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

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

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

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

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

136
        getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
15✔
137
        getRequestCycleSettings().setRenderStrategy(RequestCycleSettings.RenderStrategy.ONE_PASS_RENDER);
15✔
138

139
        getExceptionSettings().setUnexpectedExceptionDisplay(ExceptionSettings.SHOW_NO_EXCEPTION_PAGE);
15✔
140

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

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

186
        getCspSettings().blocking().disabled();
15✔
187
        getStoreSettings().setMaxSizePerSession(Bytes.MAX);
15✔
188

189
        registerListeners();
6✔
190

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

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

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

223
            Gson gson = new Gson();
12✔
224
            Type nanopubReleasesType = new TypeToken<List<NanodashRelease>>() {
18✔
225
            }.getType();
6✔
226

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

239
    /**
240
     * Properties object to hold application properties.
241
     */
242
    public final static Properties properties = new Properties();
12✔
243

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

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

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

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

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