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

knowledgepixels / nanodash / 17380144000

01 Sep 2025 02:12PM UTC coverage: 12.03% (+0.05%) from 11.978%
17380144000

push

github

ashleycaselli
refactor: replace printStackTrace with logger.error for better error handling

330 of 3850 branches covered (8.57%)

Branch coverage included in aggregate %.

958 of 6857 relevant lines covered (13.97%)

0.62 hits per line

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

68.06
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 {
2✔
19

20
    private static final long serialVersionUID = 1L;
21
    private static NanodashPreferences obj;
22
    private static final Logger logger = LoggerFactory.getLogger(NanodashPreferences.class);
4✔
23

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

46
    private List<String> nanopubActions = new ArrayList<>();
5✔
47
    private boolean readOnlyMode = false;
3✔
48
    private String websiteUrl = "http://localhost:37373/";
3✔
49
    private boolean orcidLoginMode = false;
4✔
50
    private String orcidClientId;
51
    private String orcidClientSecret;
52
    private String settingUri;
53

54
    /**
55
     * Return the list of nanopub actions.
56
     *
57
     * @return list of nanopub actions
58
     */
59
    public List<String> getNanopubActions() {
60
        String s = System.getenv("NANODASH_NANOPUB_ACTIONS");
3✔
61
        if (!(s == null) && !s.isEmpty()) return Arrays.asList(s.split(" "));
2!
62
        return nanopubActions;
3✔
63
    }
64

65
    /**
66
     * Set the list of nanopub actions.
67
     *
68
     * @param nanopubActions the list of nanopub actions
69
     */
70
    public void setNanopubActions(List<String> nanopubActions) {
71
        this.nanopubActions = nanopubActions;
3✔
72
    }
1✔
73

74
    /**
75
     * Check if the application is in read-only mode.
76
     *
77
     * @return true if in read-only mode, false otherwise
78
     */
79
    public boolean isReadOnlyMode() {
80
        if ("true".equals(System.getenv("NANODASH_READ_ONLY_MODE"))) return true;
5!
81
        return readOnlyMode;
3✔
82
    }
83

84
    /**
85
     * Set the read-only mode.
86
     *
87
     * @param readOnlyMode true to enable read-only mode, false to disable
88
     */
89
    public void setReadOnlyMode(boolean readOnlyMode) {
90
        this.readOnlyMode = readOnlyMode;
3✔
91
    }
1✔
92

93
    /**
94
     * Get the website URL.
95
     *
96
     * @return the website URL
97
     */
98
    public String getWebsiteUrl() {
99
        String s = System.getenv("NANODASH_WEBSITE_URL");
3✔
100
        if (!(s == null) && !s.isEmpty()) return s;
2!
101
        return websiteUrl;
3✔
102
    }
103

104
    /**
105
     * Set the website URL.
106
     *
107
     * @param websiteUrl the website URL to set
108
     */
109
    public void setWebsiteUrl(String websiteUrl) {
110
        this.websiteUrl = websiteUrl;
3✔
111
    }
1✔
112

113
    /**
114
     * Check if the application is in ORCID login mode.
115
     *
116
     * @return true if in ORCID login mode, false otherwise
117
     */
118
    public boolean isOrcidLoginMode() {
119
        if ("true".equals(System.getenv("NANODASH_ORCID_LOGIN_MODE"))) return true;
5!
120
        return orcidLoginMode;
3✔
121
    }
122

123
    /**
124
     * Set the ORCID login mode.
125
     *
126
     * @param orcidLoginMode true to enable ORCID login mode, false to disable
127
     */
128
    public void setOrcidLoginMode(boolean orcidLoginMode) {
129
        this.orcidLoginMode = orcidLoginMode;
3✔
130
    }
1✔
131

132
    /**
133
     * Get the ORCID client ID.
134
     *
135
     * @return the ORCID client ID
136
     */
137
    public String getOrcidClientId() {
138
        String s = System.getenv("NANOPUB_ORCID_CLIENT_ID");
3✔
139
        if (!(s == null) && !s.isEmpty()) return s;
2!
140
        return orcidClientId;
3✔
141
    }
142

143
    /**
144
     * Set the ORCID client ID.
145
     *
146
     * @param orcidClientId the ORCID client ID to set
147
     */
148
    public void setOrcidClientId(String orcidClientId) {
149
        this.orcidClientId = orcidClientId;
3✔
150
    }
1✔
151

152
    /**
153
     * Get the ORCID client secret.
154
     *
155
     * @return the ORCID client secret
156
     */
157
    public String getOrcidClientSecret() {
158
        String s = System.getenv("NANOPUB_ORCID_CLIENT_SECRET");
3✔
159
        if (!(s == null) && !s.isEmpty()) return s;
2!
160
        return orcidClientSecret;
3✔
161
    }
162

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

172
    /**
173
     * Get the setting URI.
174
     *
175
     * @return the setting URI
176
     */
177
    public String getSettingUri() {
178
        return settingUri;
3✔
179
    }
180

181
    /**
182
     * Set the setting URI.
183
     *
184
     * @param settingUri the setting URI to set
185
     */
186
    public void setSettingUri(String settingUri) {
187
        this.settingUri = settingUri;
3✔
188
    }
1✔
189

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