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

knowledgepixels / nanodash / 25725007728

12 May 2026 09:12AM UTC coverage: 20.478% (-0.03%) from 20.512%
25725007728

push

github

web-flow
Merge pull request #457 from knowledgepixels/fix-f5-form-state-singleton-ldm

fix: restore F5 form-state preservation via singleton LDMs (#456)

1013 of 6240 branches covered (16.23%)

Branch coverage included in aggregate %.

2591 of 11359 relevant lines covered (22.81%)

3.28 hits per line

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

67.47
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
        getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
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
        mountPage(DownloadRdfPage.MOUNT_PATH, DownloadRdfPage.class);
15✔
186

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

190
        registerListeners();
6✔
191

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

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

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

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

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

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

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

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

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

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

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