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

knowledgepixels / nanodash / 22618039211

03 Mar 2026 10:05AM UTC coverage: 16.058% (+0.2%) from 15.884%
22618039211

Pull #365

github

web-flow
Merge 1e7e700f0 into a8c4b4a77
Pull Request #365: Refactor of `ResourceWithProfile` and related classes

699 of 5287 branches covered (13.22%)

Branch coverage included in aggregate %.

1721 of 9783 relevant lines covered (17.59%)

2.41 hits per line

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

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

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

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

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

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

61
    private static String latestVersion = null;
6✔
62

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

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

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

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

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

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

135
        getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
15✔
136

137
        getExceptionSettings().setUnexpectedExceptionDisplay(ExceptionSettings.SHOW_NO_EXCEPTION_PAGE);
15✔
138

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

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

183
        getCspSettings().blocking().disabled();
15✔
184
        getStoreSettings().setMaxSizePerSession(Bytes.MAX);
15✔
185

186
        registerListeners();
6✔
187
    }
3✔
188

189
    /**
190
     * {@inheritDoc}
191
     * <p>
192
     * Returns the runtime configuration type for the application.
193
     */
194
    @Override
195
    public RuntimeConfigurationType getConfigurationType() {
196
        return RuntimeConfigurationType.DEPLOYMENT;
6✔
197
    }
198

199
    /**
200
     * Retrieves the latest version of the application from the GitHub API.
201
     *
202
     * @return The latest version as a string.
203
     */
204
    public static String getLatestVersion() {
205
        if (latestVersion != null) return latestVersion;
12✔
206
        try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
9✔
207
            HttpResponse resp = client.execute(new HttpGet(LATEST_RELEASE_URL));
21✔
208
            int c = resp.getStatusLine().getStatusCode();
12✔
209
            if (c < 200 || c >= 300) {
18!
210
                throw new HttpStatusException(c);
×
211
            }
212

213
            Gson gson = new Gson();
12✔
214
            Type nanopubReleasesType = new TypeToken<List<NanodashRelease>>() {
18✔
215
            }.getType();
6✔
216

217
            List<NanodashRelease> releases = gson.fromJson(new InputStreamReader(resp.getEntity().getContent()), nanopubReleasesType);
33✔
218
            if (!releases.isEmpty()) {
9!
219
                latestVersion = releases.getFirst().getVersionNumber();
15✔
220
            }
221
        } catch (Exception ex) {
×
222
            logger.error("Error in fetching latest version", ex);
×
223
        }
3✔
224
        return latestVersion;
6✔
225
    }
226

227
    /**
228
     * Properties object to hold application properties.
229
     */
230
    public final static Properties properties = new Properties();
12✔
231

232
    static {
233
        try {
234
            properties.load(WicketApplication.class.getClassLoader().getResourceAsStream("nanodash.properties"));
18✔
235
        } catch (IOException ex) {
×
236
            logger.error("Error in loading properties", ex);
×
237
        }
3✔
238
    }
3✔
239

240
    /**
241
     * Retrieves the current version of the application.
242
     *
243
     * @return The current version as a string.
244
     */
245
    public static String getThisVersion() {
246
        return properties.getProperty("nanodash.version");
12✔
247
    }
248

249
    /**
250
     * {@inheritDoc}
251
     */
252
    @Override
253
    public Session newSession(Request request, Response response) {
254
        return new NanodashSession(request);
15✔
255
    }
256

257
    private void registerListeners() {
258
        logger.info("Registering nanopub published event listeners for spaces, maintained resources, resource with profile and query ref refresh");
9✔
259
        registerListener((nanopub, target, waitMs) -> {
9✔
260
            logger.info("Received nanopub published event with target <{}> and waitMs {}", target, waitMs);
×
261
            if (target.equals("spaces")) {
×
262
                SpaceRepository.get().forceRootRefresh(waitMs);
×
263
            } else if (target.equals("maintainedResources")) {
×
264
                MaintainedResourceRepository.get().forceRootRefresh(waitMs);
×
265
            } else if (AbstractResourceWithProfile.isResourceWithProfile(target)) {
×
266
                AbstractResourceWithProfile.get(target).forceRefresh(waitMs);
×
267
            } else {
268
                QueryRef queryRef = QueryRef.parseString(target);
×
269
                ApiCache.clearCache(queryRef, waitMs);
×
270
            }
271
        });
×
272
    }
3✔
273

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