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

knowledgepixels / nanodash / 22760576088

06 Mar 2026 11:01AM UTC coverage: 15.877% (+0.009%) from 15.868%
22760576088

Pull #379

github

web-flow
Merge 0a1e075b8 into 68d77318d
Pull Request #379: Users can set a profile picture

705 of 5393 branches covered (13.07%)

Branch coverage included in aggregate %.

1741 of 10013 relevant lines covered (17.39%)

2.37 hits per line

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

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

3
import org.eclipse.rdf4j.model.IRI;
4
import org.nanopub.Nanopub;
5
import org.nanopub.extra.setting.IntroNanopub;
6
import org.slf4j.Logger;
7
import org.slf4j.LoggerFactory;
8

9
import java.util.List;
10
import java.util.Map;
11

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

18
    private User() {
19
    }  // no instances allowed
20

21
    private static final Logger logger = LoggerFactory.getLogger(User.class);
9✔
22
    private static volatile UserData userData;
23
    private static final long REFRESH_INTERVAL = 60 * 1000; // 1 minute
24
    private static transient long lastRefresh = 0L;
9✔
25

26
    /**
27
     * Refreshes the user data by creating a new UserData instance.
28
     */
29
    public static void refreshUsers() {
30
        logger.info("Refreshing user data...");
9✔
31
        synchronized (User.class) {
12✔
32
            if (userData == null || System.currentTimeMillis() - lastRefresh > REFRESH_INTERVAL) {
6!
33
                lastRefresh = System.currentTimeMillis();
6✔
34
                userData = new UserData();
12✔
35
            }
36
        }
9✔
37
    }
3✔
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) {
6!
44
            refreshUsers();
×
45
        }
46
    }
3✔
47

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

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

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

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

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

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

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

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

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

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

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

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

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

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

191
    public static IRI getProfilePicture(IRI userIri) {
192
        return getUserData().getProfilePicture(userIri);
×
193
    }
194

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