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

knowledgepixels / nanodash / 17427371198

03 Sep 2025 08:16AM UTC coverage: 12.119% (+0.06%) from 12.064%
17427371198

push

github

tkuhn
Improve refreshUsers()

335 of 3870 branches covered (8.66%)

Branch coverage included in aggregate %.

972 of 6915 relevant lines covered (14.06%)

0.62 hits per line

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

61.11
src/main/java/com/knowledgepixels/nanodash/User.java
1
package com.knowledgepixels.nanodash;
2

3
import org.eclipse.rdf4j.model.IRI;
4
import org.nanopub.Nanopub;
5
import org.nanopub.extra.setting.IntroNanopub;
6

7
import java.util.List;
8
import java.util.Map;
9

10
/**
11
 * The User class provides utility methods for managing and retrieving user-related data.
12
 * This class is designed to be used statically and does not allow instantiation.
13
 */
14
public class User {
15

16
    private User() {
17
    }  // no instances allowed
18

19
    private static transient UserData userData;
20
    private static final long REFRESH_INTERVAL = 60 * 1000; // 1 minute
21
    private static transient long lastRefresh = 0L;
3✔
22

23
    /**
24
     * Refreshes the user data by creating a new UserData instance.
25
     */
26
    public static void refreshUsers() {
27
        boolean refreshNeeded = (userData == null);
5!
28
        synchronized (User.class) {
4✔
29
            if (System.currentTimeMillis() - lastRefresh > REFRESH_INTERVAL) {
6✔
30
                lastRefresh = System.currentTimeMillis();
2✔
31
                refreshNeeded = true;
2✔
32
            }
33
        }
3✔
34
        if (refreshNeeded) {
2!
35
            userData = new UserData();
4✔
36
        }
37
    }
1✔
38

39
    /**
40
     * Ensures that the user data is loaded. If not, it refreshes the user data.
41
     */
42
    public static void ensureLoaded() {
43
        if (userData == null) refreshUsers();
3✔
44
    }
1✔
45

46
    /**
47
     * Retrieves the current user data instance.
48
     *
49
     * @return The UserData instance.
50
     */
51
    public static UserData getUserData() {
52
        ensureLoaded();
1✔
53
        return userData;
2✔
54
    }
55

56
    /**
57
     * Checks if a given key is approved for a specific user.
58
     *
59
     * @param pubkeyhash The key to check.
60
     * @param user       The IRI of the user.
61
     * @return True if the key is approved, false otherwise.
62
     */
63
    public static boolean isApprovedPubkeyhashForUser(String pubkeyhash, IRI user) {
64
        return getUserData().isApprovedPubkeyhashForUser(pubkeyhash, user);
×
65
    }
66

67
    /**
68
     * Retrieves the signature owner's IRI from a given nanopublication.
69
     *
70
     * @param np The nanopublication.
71
     * @return The IRI of the signature owner.
72
     */
73
    public static IRI getSignatureOwnerIri(Nanopub np) {
74
        return getUserData().getSignatureOwnerIri(np);
4✔
75
    }
76

77
    /**
78
     * Retrieves the name of a user based on their IRI.
79
     *
80
     * @param userIri The IRI of the user.
81
     * @return The name of the user.
82
     */
83
    public static String getName(IRI userIri) {
84
        return getUserData().getName(userIri);
4✔
85
    }
86

87
    /**
88
     * Retrieves the display name of a user based on their IRI.
89
     *
90
     * @param userIri The IRI of the user.
91
     * @return The display name of the user.
92
     */
93
    public static String getDisplayName(IRI userIri) {
94
        return getUserData().getDisplayName(userIri);
×
95
    }
96

97
    /**
98
     * Retrieves the short display name of a user based on their IRI.
99
     *
100
     * @param userIri The IRI of the user.
101
     * @return The short display name of the user.
102
     */
103
    public static String getShortDisplayName(IRI userIri) {
104
        return getUserData().getShortDisplayName(userIri);
×
105
    }
106

107
    /**
108
     * Retrieves the short display name of a user based on their IRI and public key.
109
     *
110
     * @param userIri    The IRI of the user.
111
     * @param pubkeyhash The public key of the user.
112
     * @return The short display name of the user.
113
     */
114
    public static String getShortDisplayNameForPubkeyhash(IRI userIri, String pubkeyhash) {
115
        return getUserData().getShortDisplayNameForPubkeyhash(userIri, pubkeyhash);
×
116
    }
117

118
    /**
119
     * Finds a single user ID for a given public key hash.
120
     *
121
     * @param pubkeyhash The public key.
122
     * @return The IRI of the user.
123
     */
124
    public static IRI findSingleIdForPubkeyhash(String pubkeyhash) {
125
        return getUserData().findSingleIdForPubkeyhash(pubkeyhash);
×
126
    }
127

128
    /**
129
     * Retrieves a list of users, optionally filtering by approval status.
130
     *
131
     * @param approved True to retrieve only approved users, false otherwise.
132
     * @return A list of user IRIs.
133
     */
134
    public static List<IRI> getUsers(boolean approved) {
135
        return getUserData().getUsers(approved);
×
136
    }
137

138
    /**
139
     * Retrieves a list of public keys for a user, optionally filtering by approval status.
140
     *
141
     * @param user     The IRI of the user.
142
     * @param approved True to retrieve only approved keys, false otherwise.
143
     * @return A list of public keys.
144
     */
145
    public static List<String> getPubkeyhashes(IRI user, Boolean approved) {
146
        return getUserData().getPubkeyhashes(user, approved);
×
147
    }
148

149
    /**
150
     * Retrieves a list of introduction nanopublications for a user.
151
     *
152
     * @param user The IRI of the user.
153
     * @return A list of introduction nanopublications.
154
     */
155
    public static List<IntroNanopub> getIntroNanopubs(IRI user) {
156
        return getUserData().getIntroNanopubs(user);
×
157
    }
158

159
    /**
160
     * Retrieves a map of introduction nanopublications for a public key.
161
     *
162
     * @param pubkey The public key.
163
     * @return A map of user IRIs to introduction nanopublications.
164
     */
165
    public static Map<IRI, IntroNanopub> getIntroNanopubs(String pubkey) {
166
        return getUserData().getIntroNanopubs(pubkey);
×
167
    }
168

169
    /**
170
     * Checks if an introduction nanopublication is approved.
171
     *
172
     * @param in The introduction nanopublication.
173
     * @return True if approved, false otherwise.
174
     */
175
    public static boolean isApproved(IntroNanopub in) {
176
        return getUserData().isApproved(in);
×
177
    }
178

179
    /**
180
     * Checks if a given IRI represents a user.
181
     *
182
     * @param userIri The IRI to check.
183
     * @return True if the IRI represents a user, false otherwise.
184
     */
185
    public static boolean isUser(IRI userIri) {
186
        return getUserData().isUser(userIri);
×
187
    }
188

189
    /**
190
     * Checks if a given string represents a user ID.
191
     *
192
     * @param userId The string to check.
193
     * @return True if the string represents a user ID, false otherwise.
194
     */
195
    public static boolean isUser(String userId) {
196
        return getUserData().isUser(userId);
×
197
    }
198

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