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

knowledgepixels / nanodash / 22632853099

03 Mar 2026 04:35PM UTC coverage: 16.04% (+0.01%) from 16.03%
22632853099

Pull #368

github

web-flow
Merge dfe62f501 into 85e0af2dc
Pull Request #368: Add Umami analytics support

701 of 5317 branches covered (13.18%)

Branch coverage included in aggregate %.

1727 of 9820 relevant lines covered (17.59%)

2.38 hits per line

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

86.79
src/main/java/com/knowledgepixels/nanodash/NanodashPreferences.java
1
package com.knowledgepixels.nanodash;
2

3
import com.fasterxml.jackson.databind.ObjectMapper;
4
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
5
import org.slf4j.Logger;
6
import org.slf4j.LoggerFactory;
7

8
import java.io.File;
9
import java.io.IOException;
10
import java.io.Serializable;
11
import java.util.ArrayList;
12
import java.util.Arrays;
13
import java.util.List;
14

15
/**
16
 * Class to manage Nanodash preferences.
17
 */
18
public class NanodashPreferences implements Serializable {
6✔
19

20
    private static NanodashPreferences obj;
21
    private static final Logger logger = LoggerFactory.getLogger(NanodashPreferences.class);
12✔
22

23
    /**
24
     * Get the singleton instance of NanodashPreferences.
25
     *
26
     * @return the NanodashPreferences instance
27
     */
28
    public static NanodashPreferences get() {
29
        if (obj == null) {
6✔
30
            File prefFile = new File(System.getProperty("user.home") + DEFAULT_SETTING_PATH);
21✔
31
            if (!prefFile.exists()) {
9✔
32
                return new NanodashPreferences();
12✔
33
            }
34
            ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
21✔
35
            try {
36
                obj = mapper.readValue(prefFile, NanodashPreferences.class);
18✔
37
            } catch (IOException ex) {
3✔
38
                obj = new NanodashPreferences();
12✔
39
                logger.error("Could not read preferences file at '{}' using defaults", DEFAULT_SETTING_PATH, ex);
15✔
40
            }
3✔
41
        }
42
        return obj;
6✔
43
    }
44

45
    private List<String> nanopubActions = new ArrayList<>();
15✔
46
    private boolean readOnlyMode = false;
9✔
47
    private String websiteUrl = "http://localhost:37373/";
9✔
48
    private boolean orcidLoginMode = false;
12✔
49
    private String orcidClientId;
50
    private String orcidClientSecret;
51
    private String settingUri;
52
    private String umamiScriptUrl;
53
    private String umamiWebsiteId;
54
    public static final String DEFAULT_SETTING_PATH = "/.nanopub/nanodash-preferences.yml";
55

56
    /**
57
     * Return the list of nanopub actions.
58
     *
59
     * @return list of nanopub actions
60
     */
61
    public List<String> getNanopubActions() {
62
        String s = System.getenv("NANODASH_NANOPUB_ACTIONS");
9✔
63
        if (s != null && !s.isBlank()) {
15✔
64
            return Arrays.asList(s.split(" "));
15✔
65
        }
66
        return nanopubActions;
9✔
67
    }
68

69
    /**
70
     * Set the list of nanopub actions.
71
     *
72
     * @param nanopubActions the list of nanopub actions
73
     */
74
    public void setNanopubActions(List<String> nanopubActions) {
75
        this.nanopubActions = nanopubActions;
9✔
76
    }
3✔
77

78
    /**
79
     * Check if the application is in read-only mode.
80
     *
81
     * @return true if in read-only mode, false otherwise
82
     */
83
    public boolean isReadOnlyMode() {
84
        if ("true".equals(System.getenv("NANODASH_READ_ONLY_MODE"))) {
15✔
85
            logger.info("Found environment variable NANODASH_READ_ONLY_MODE with value: {}", true);
15✔
86
            return true;
6✔
87
        }
88
        logger.info("Environment variable NANODASH_READ_ONLY_MODE not set, using default: {}", readOnlyMode);
18✔
89
        return readOnlyMode;
9✔
90
    }
91

92
    /**
93
     * Set the read-only mode.
94
     *
95
     * @param readOnlyMode true to enable read-only mode, false to disable
96
     */
97
    public void setReadOnlyMode(boolean readOnlyMode) {
98
        this.readOnlyMode = readOnlyMode;
9✔
99
    }
3✔
100

101
    /**
102
     * Get the website URL.
103
     *
104
     * @return the website URL
105
     */
106
    public String getWebsiteUrl() {
107
        String s = System.getenv("NANODASH_WEBSITE_URL");
9✔
108
        if (s != null && !s.isBlank()) {
15✔
109
            logger.info("Found environment variable NANODASH_WEBSITE_URL with value: {}", s);
12✔
110
            return s;
6✔
111
        }
112
        logger.info("Environment variable NANODASH_WEBSITE_URL not set, using default: {}", websiteUrl);
15✔
113
        return websiteUrl;
9✔
114
    }
115

116
    /**
117
     * Set the website URL.
118
     *
119
     * @param websiteUrl the website URL to set
120
     */
121
    public void setWebsiteUrl(String websiteUrl) {
122
        this.websiteUrl = websiteUrl;
9✔
123
    }
3✔
124

125
    /**
126
     * Check if the application is in ORCID login mode.
127
     *
128
     * @return true if in ORCID login mode, false otherwise
129
     */
130
    public boolean isOrcidLoginMode() {
131
        if ("true".equals(System.getenv("NANODASH_ORCID_LOGIN_MODE"))) {
15✔
132
            logger.info("Found environment variable NANODASH_ORCID_LOGIN_MODE with value: {}", true);
15✔
133
            return true;
6✔
134
        }
135
        logger.info("Environment variable NANODASH_ORCID_LOGIN_MODE not set, using default: {}", orcidLoginMode);
18✔
136
        return orcidLoginMode;
9✔
137
    }
138

139
    /**
140
     * Set the ORCID login mode.
141
     *
142
     * @param orcidLoginMode true to enable ORCID login mode, false to disable
143
     */
144
    public void setOrcidLoginMode(boolean orcidLoginMode) {
145
        this.orcidLoginMode = orcidLoginMode;
9✔
146
    }
3✔
147

148
    /**
149
     * Get the ORCID client ID.
150
     *
151
     * @return the ORCID client ID
152
     */
153
    public String getOrcidClientId() {
154
        String s = System.getenv("NANOPUB_ORCID_CLIENT_ID");
9✔
155
        if (s != null && !s.isBlank()) {
15✔
156
            logger.info("Found environment variable NANOPUB_ORCID_CLIENT_ID with value: {}", s);
12✔
157
            return s;
6✔
158
        }
159
        logger.info("Environment variable NANOPUB_ORCID_CLIENT_ID not set, using default: {}", orcidClientId);
15✔
160
        return orcidClientId;
9✔
161
    }
162

163
    /**
164
     * Set the ORCID client ID.
165
     *
166
     * @param orcidClientId the ORCID client ID to set
167
     */
168
    public void setOrcidClientId(String orcidClientId) {
169
        this.orcidClientId = orcidClientId;
9✔
170
    }
3✔
171

172
    /**
173
     * Get the ORCID client secret.
174
     * .
175
     *
176
     * @return the ORCID client secret
177
     */
178
    public String getOrcidClientSecret() {
179
        String s = System.getenv("NANOPUB_ORCID_CLIENT_SECRET");
9✔
180
        if (s != null && !s.isBlank()) {
15✔
181
            logger.info("Found environment variable NANOPUB_ORCID_CLIENT_SECRET");
9✔
182
            return s;
6✔
183
        }
184
        logger.info("Environment variable NANOPUB_ORCID_CLIENT_SECRET not set, using default");
9✔
185
        return orcidClientSecret;
9✔
186
    }
187

188
    /**
189
     * Set the ORCID client secret.
190
     *
191
     * @param orcidClientSecret the ORCID client secret to set
192
     */
193
    public void setOrcidClientSecret(String orcidClientSecret) {
194
        this.orcidClientSecret = orcidClientSecret;
9✔
195
    }
3✔
196

197
    /**
198
     * Get the setting URI.
199
     *
200
     * @return the setting URI
201
     */
202
    public String getSettingUri() {
203
        return settingUri;
9✔
204
    }
205

206
    /**
207
     * Set the setting URI.
208
     *
209
     * @param settingUri the setting URI to set
210
     */
211
    public void setSettingUri(String settingUri) {
212
        this.settingUri = settingUri;
9✔
213
    }
3✔
214

215
    /**
216
     * Get the Umami analytics script URL.
217
     *
218
     * @return the Umami script URL, or null if not configured
219
     */
220
    public String getUmamiScriptUrl() {
221
        String s = System.getenv("NANODASH_UMAMI_SCRIPT_URL");
9✔
222
        if (s != null && !s.isBlank()) return s;
6!
223
        return umamiScriptUrl;
9✔
224
    }
225

226
    /**
227
     * Set the Umami analytics script URL.
228
     *
229
     * @param umamiScriptUrl the Umami script URL to set
230
     */
231
    public void setUmamiScriptUrl(String umamiScriptUrl) {
232
        this.umamiScriptUrl = umamiScriptUrl;
×
233
    }
×
234

235
    /**
236
     * Get the Umami analytics website ID.
237
     *
238
     * @return the Umami website ID, or null if not configured
239
     */
240
    public String getUmamiWebsiteId() {
241
        String s = System.getenv("NANODASH_UMAMI_WEBSITE_ID");
×
242
        if (s != null && !s.isBlank()) return s;
×
243
        return umamiWebsiteId;
×
244
    }
245

246
    /**
247
     * Set the Umami analytics website ID.
248
     *
249
     * @param umamiWebsiteId the Umami website ID to set
250
     */
251
    public void setUmamiWebsiteId(String umamiWebsiteId) {
252
        this.umamiWebsiteId = umamiWebsiteId;
×
253
    }
×
254

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