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

knowledgepixels / nanodash / 17837235071

18 Sep 2025 05:58PM UTC coverage: 13.87%. Remained the same
17837235071

push

github

tkuhn
chore: Remove serialVersionUIDs

443 of 4022 branches covered (11.01%)

Branch coverage included in aggregate %.

1133 of 7341 relevant lines covered (15.43%)

0.68 hits per line

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

31.42
src/main/java/com/knowledgepixels/nanodash/UserData.java
1
package com.knowledgepixels.nanodash;
2

3
import org.eclipse.rdf4j.common.exception.RDF4JException;
4
import org.eclipse.rdf4j.model.IRI;
5
import org.eclipse.rdf4j.model.ValueFactory;
6
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
7
import org.nanopub.MalformedNanopubException;
8
import org.nanopub.Nanopub;
9
import org.nanopub.SimpleTimestampPattern;
10
import org.nanopub.extra.security.MalformedCryptoElementException;
11
import org.nanopub.extra.security.NanopubSignatureElement;
12
import org.nanopub.extra.security.SignatureUtils;
13
import org.nanopub.extra.server.GetNanopub;
14
import org.nanopub.extra.services.ApiResponseEntry;
15
import org.nanopub.extra.setting.IntroNanopub;
16
import org.nanopub.extra.setting.NanopubSetting;
17
import org.nanopub.vocabulary.NPX;
18
import org.slf4j.Logger;
19
import org.slf4j.LoggerFactory;
20

21
import java.io.IOException;
22
import java.io.Serializable;
23
import java.util.*;
24

25
/**
26
 * UserData class manages user-related data.
27
 */
28
public class UserData implements Serializable {
29

30
    private static ValueFactory vf = SimpleValueFactory.getInstance();
2✔
31
    private static final Logger logger = LoggerFactory.getLogger(UserData.class);
4✔
32

33
    private HashMap<IRI, Set<String>> approvedIdPubkeyhashMap = new HashMap<>();
5✔
34
    private HashMap<String, Set<IRI>> approvedPubkeyhashIdMap = new HashMap<>();
5✔
35
    private HashMap<String, Set<IRI>> approvedPubkeyhashLocationMap = new HashMap<>();
5✔
36
    private HashMap<IRI, Set<String>> unapprovedIdPubkeyhashMap = new HashMap<>();
5✔
37
    private HashMap<String, Set<IRI>> unapprovedPubkeyhashIdMap = new HashMap<>();
5✔
38
    private HashMap<String, Set<IRI>> unapprovedPubkeyhashLocationMap = new HashMap<>();
5✔
39
    private HashMap<String, Set<IRI>> pubkeyhashIntroMap = new HashMap<>();
5✔
40
    private HashMap<IRI, IntroNanopub> introMap = new HashMap<>();
5✔
41
    private Set<IRI> approvedIntros = new HashSet<>();
5✔
42
    private HashMap<IRI, String> idNameMap = new HashMap<>();
5✔
43
    private HashMap<IRI, List<IntroNanopub>> introNanopubLists = new HashMap<>();
5✔
44

45
    /**
46
     * Default constructor for UserData.
47
     * Initializes the user data by fetching nanopublications settings.
48
     */
49
    UserData() {
2✔
50
        final NanodashPreferences pref = NanodashPreferences.get();
2✔
51

52
        // TODO Make nanopublication setting configurable:
53
        NanopubSetting setting;
54
        if (pref.getSettingUri() != null) {
3!
55
            setting = new NanopubSetting(GetNanopub.get(pref.getSettingUri()));
×
56
        } else {
57
            try {
58
                setting = NanopubSetting.getLocalSetting();
2✔
59
            } catch (RDF4JException | MalformedNanopubException | IOException ex) {
×
60
                throw new RuntimeException(ex);
×
61
            }
1✔
62
        }
63
        String settingId = setting.getNanopub().getUri().stringValue();
5✔
64
        if (setting.getUpdateStrategy().equals(NPX.UPDATES_BY_CREATOR)) {
5!
65
            settingId = QueryApiAccess.getLatestVersionId(settingId);
3✔
66
            setting = new NanopubSetting(GetNanopub.get(settingId));
6✔
67
        }
68
        logger.info("Using nanopublication setting: {}", settingId);
4✔
69

70
//                // Get users that are listed directly in the authority index, and consider them approved:
71
//                ByteArrayOutputStream out = new ByteArrayOutputStream(); // TODO use piped out-in stream here
72
//                new FetchIndex(setting.getAgentIntroCollection().stringValue(), out, RDFFormat.TRIG, false, true, null).run();
73
//                InputStream in = new ByteArrayInputStream(out.toByteArray());
74
//                try {
75
//                        MultiNanopubRdfHandler.process(RDFFormat.TRIG, in, new MultiNanopubRdfHandler.NanopubHandler() {
76
//                                @Override
77
//                                public void handleNanopub(Nanopub np) {
78
//                                        // TODO: Check that latest version talks about same user
79
//                                        register(QueryApiAccess.getLatestVersionId(np.getUri().stringValue()), true);
80
//                                }
81
//                        });
82
//                } catch (RDFParseException | RDFHandlerException | IOException | MalformedNanopubException ex) {
83
//                        logger.error();
84
//                }
85
///
86
//                if (setting.getTrustRangeAlgorithm().equals(NPX.TRANSITIVE_TRUST)) {
87
//                        ApiResponse resp = QueryApiAccess.forcedGet("get-approved-nanopubs");
88
//                        List<ApiResponseEntry> results = new ArrayList<>(resp.getData());
89
//                        while (true) {
90
//                                boolean keepLooping = false;
91
//                                for (ApiResponseEntry entry : new ArrayList<>(results)) {
92
//                                        if (hasValue(approvedPubkeyIdMap, entry.get("pubkey"), Utils.vf.createIRI(entry.get("approver")))) {
93
//                                                register(entry.get("approved_np"), true);
94
//                                                results.remove(entry);
95
//                                                keepLooping = true;
96
//                                        }
97
//                                }
98
//                                if (!keepLooping) break;
99
//                        }
100
//                }
101

102
        logger.info("Loading approved users...");
3✔
103
        try {
104
            for (RegistryAccountInfo rai : RegistryAccountInfo.fromUrl(Utils.getMainRegistryUrl() + "list.json")) {
12✔
105
                registerApproved(rai);
3✔
106
            }
1✔
107
        } catch (Exception ex) {
×
108
            throw new RuntimeException(ex);
×
109
        }
1✔
110

111
        logger.info("Loading user details...");
3✔
112
        // Get latest introductions for all users, including unapproved ones:
113
        for (ApiResponseEntry entry : QueryApiAccess.forcedGet("get-all-user-intros").getData()) {
12✔
114
            register(entry);
3✔
115
        }
1✔
116
    }
1✔
117

118
    private IntroNanopub toIntroNanopub(IRI iri) {
119
        if (iri == null) return null;
×
120
        if (introMap.containsKey(iri)) return introMap.get(iri);
×
121
        Nanopub np = Utils.getNanopub(iri.stringValue());
×
122
        if (np == null) return null;
×
123
        IntroNanopub introNp = new IntroNanopub(np);
×
124
        introMap.put(np.getUri(), introNp);
×
125
        return introNp;
×
126
    }
127

128
    private void registerApproved(RegistryAccountInfo rai) {
129
        if (rai.getAgent().equals("$")) return;
6✔
130
        addValue(approvedIdPubkeyhashMap, rai.getAgentIri(), rai.getPubkey());
8✔
131
        addValue(approvedPubkeyhashIdMap, rai.getPubkey(), rai.getAgentIri());
8✔
132
    }
1✔
133

134
    private void register(ApiResponseEntry entry) {
135
        IRI userIri;
136
        try {
137
            userIri = vf.createIRI(entry.get("user"));
6✔
138
        } catch (IllegalArgumentException ex) {
×
139
            logger.error("Error creating IRI from user string: {}", entry.get("user"), ex);
×
140
            return;
×
141
        }
1✔
142
        String pubkeyhash = entry.get("pubkeyHash");
4✔
143
        boolean approved = approvedIdPubkeyhashMap.containsKey(userIri) && approvedIdPubkeyhashMap.get(userIri).contains(pubkeyhash);
17✔
144
        boolean authoritative = "true".equals(entry.get("authoritative"));
6✔
145
        IRI introNpIri = null;
2✔
146
        try {
147
            introNpIri = vf.createIRI(entry.get("intronp"));
6✔
148
        } catch (IllegalArgumentException ex) {
×
149
            logger.error("Error creating IRI from intronp string: {}", entry.get("intronp"), ex);
×
150
        }
1✔
151
        IRI keyLocation = null;
2✔
152
        try {
153
            if (!entry.get("keyLocation").isEmpty()) {
5✔
154
                keyLocation = vf.createIRI(entry.get("keyLocation"));
6✔
155
            }
156
        } catch (IllegalArgumentException ex) {
×
157
            logger.error("Error creating IRI from keyLocation string: {}", entry.get("keyLocation"), ex);
×
158
        }
1✔
159
        if (approved) {
2✔
160
            if (authoritative) {
2✔
161
                if (introNpIri != null) approvedIntros.add(introNpIri);
7!
162
                if (keyLocation != null) addValue(approvedPubkeyhashLocationMap, pubkeyhash, keyLocation);
9✔
163
            }
164
        } else {
165
            addValue(unapprovedIdPubkeyhashMap, userIri, entry.get("pubkeyHash"));
8✔
166
            addValue(unapprovedPubkeyhashIdMap, entry.get("pubkeyHash"), userIri);
8✔
167
            if (keyLocation != null) addValue(unapprovedPubkeyhashLocationMap, pubkeyhash, keyLocation);
8✔
168
        }
169
        if (introNpIri != null) {
2!
170
            addValue(pubkeyhashIntroMap, entry.get("pubkeyHash"), introNpIri);
8✔
171
        }
172
        String name = entry.get("name");
4✔
173
        if (!name.isEmpty() && !idNameMap.containsKey(userIri)) {
8✔
174
            idNameMap.put(userIri, name);
6✔
175
        }
176
    }
1✔
177

178
/*
179
    private void register(String npId, boolean approved) {
180
        if (!TrustyUriUtils.isPotentialTrustyUri(npId)) return;
181
        IntroNanopub introNp = toIntroNanopub(npId);
182
        if (introNp == null) {
183
            //logger.error("No latest version of introduction found");
184
            return;
185
        }
186
        if (introNp.getUser() == null) {
187
            //logger.error("No identifier found in introduction");
188
            return;
189
        }
190
        if (introNp.getKeyDeclarations().isEmpty()) {
191
            //logger.error("No key declarations found in introduction");
192
            return;
193
        }
194
        if (approved) {
195
            approvedIntroMap.put(introNp.getNanopub().getUri(), introNp);
196
        }
197
        String userId = introNp.getUser().stringValue();
198
        IRI userIri = Utils.vf.createIRI(userId);
199
        if (userId.startsWith("https://orcid.org/")) {
200
            // Some simple ORCID ID wellformedness check:
201
            if (!userId.matches("https://orcid.org/[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{3}[0-9X]")) return;
202
        }
203
        for (KeyDeclaration kd : introNp.getKeyDeclarations()) {
204
            String pubkey = kd.getPublicKeyString();
205
            IRI keyLocation = kd.getKeyLocation();
206
            if (approved) {
207
                addValue(approvedIdPubkeyMap, userIri, pubkey);
208
                addValue(approvedPubkeyIdMap, pubkey, userIri);
209
                if (keyLocation != null) addValue(approvedPubkeyLocationMap, pubkey, keyLocation);
210
            } else {
211
                if (!hasValue(approvedIdPubkeyMap, userIri, pubkey)) {
212
                    addValue(unapprovedIdPubkeyMap, userIri, pubkey);
213
                    addValue(unapprovedPubkeyIdMap, pubkey, userIri);
214
                    if (keyLocation != null) addValue(unapprovedPubkeyLocationMap, pubkey, keyLocation);
215
                }
216
                addValue(pubkeyIntroMap, pubkey, introNp.getNanopub().getUri());
217
            }
218
        }
219
        if (!idNameMap.containsKey(userIri)) {
220
            idNameMap.put(userIri, introNp.getName());
221
        }
222
    }
223
    */
224

225
    private void addValue(Map<IRI, Set<String>> map, IRI key, String value) {
226
        Set<String> values = map.get(key);
5✔
227
        if (values == null) {
2✔
228
            values = new HashSet<>();
4✔
229
            map.put(key, values);
5✔
230
        }
231
        values.add(value);
4✔
232
    }
1✔
233

234
    private void addValue(Map<String, Set<IRI>> map, String key, IRI value) {
235
        Set<IRI> values = map.get(key);
5✔
236
        if (values == null) {
2✔
237
            values = new HashSet<>();
4✔
238
            map.put(key, values);
5✔
239
        }
240
        values.add(value);
4✔
241
    }
1✔
242

243
    private boolean hasValue(Map<IRI, Set<String>> map, IRI key, String value) {
244
        Set<String> values = map.get(key);
×
245
        if (values == null) return false;
×
246
        return values.contains(value);
×
247
    }
248

249
//        private static boolean hasValue(Map<String,Set<IRI>> map, String key, IRI value) {
250
//                Set<IRI> values = map.get(key);
251
//                if (values == null) return false;
252
//                return values.contains(value);
253
//        }
254

255
    /**
256
     * Checks if the given IRI is a user identifier.
257
     *
258
     * @param userIri the IRI to check
259
     * @return true if the IRI is a user identifier, false otherwise
260
     */
261
    public boolean isUser(IRI userIri) {
262
        return approvedIdPubkeyhashMap.containsKey(userIri) || unapprovedIdPubkeyhashMap.containsKey(userIri);
×
263
    }
264

265
    /**
266
     * Checks if the given userId is a valid user identifier.
267
     *
268
     * @param userId the user identifier to check, must start with "https://" or "http://"
269
     * @return true if the userId is a valid user identifier, false otherwise
270
     */
271
    public boolean isUser(String userId) {
272
        if (!userId.startsWith("https://") && !userId.startsWith("http://")) return false;
×
273
        try {
274
            IRI userIri = Utils.vf.createIRI(userId);
×
275
            return approvedIdPubkeyhashMap.containsKey(userIri) || unapprovedIdPubkeyhashMap.containsKey(userIri);
×
276
        } catch (IllegalArgumentException ex) {
×
277
            return false;
×
278
        }
279
    }
280

281
    /**
282
     * Checks if the given public key is approved for the specified user.
283
     *
284
     * @param pubkeyhash the public key to check
285
     * @param user       the IRI of the user to check against
286
     * @return true if the key is approved for the user, false otherwise
287
     */
288
    public boolean isApprovedPubkeyhashForUser(String pubkeyhash, IRI user) {
289
        return hasValue(approvedIdPubkeyhashMap, user, pubkeyhash);
×
290
    }
291

292
    private String getShortName(IRI userIri) {
293
        if (userIri == null) return "(unknown)";
×
294
        String n = userIri.stringValue();
×
295
        n = n.replaceFirst("^https://orcid.org/", "");
×
296
        if (n.length() > 40) return n.substring(0, 30) + "...";
×
297
        return n;
×
298
    }
299

300
    /**
301
     * Retrieves the IRI of a user based on their public key.
302
     *
303
     * @param pubkeyHash   the public key of the user
304
     * @param approvedOnly if true, only approved users are considered; if false, unapproved users are also considered
305
     * @return the IRI of the user if found, or null if not found
306
     */
307
    public IRI getUserIriForPubkeyhash(String pubkeyHash, boolean approvedOnly) {
308
        Set<IRI> userIris = approvedPubkeyhashIdMap.get(pubkeyHash);
×
309
        if (userIris != null && userIris.size() == 1) return userIris.iterator().next();
×
310
        if (!approvedOnly) {
×
311
            userIris = unapprovedPubkeyhashIdMap.get(pubkeyHash);
×
312
            if (userIris != null && userIris.size() == 1) return userIris.iterator().next();
×
313
        }
314
        return null;
×
315
    }
316

317
    public IRI getSignatureOwnerIri(Nanopub np) {
318
        try {
319
            if (np != null) {
2!
320
                NanopubSignatureElement se = SignatureUtils.getSignatureElement(np);
3✔
321
                if (se != null) {
2!
322
                    String pubkeyhash = Utils.createSha256HexHash(se.getPublicKeyString());
×
323
                    return getUserIriForPubkeyhash(pubkeyhash, true);
×
324
                }
325
            }
326
        } catch (MalformedCryptoElementException ex) {
×
327
            logger.error("Error getting signature element", ex);
×
328
        }
1✔
329
        return null;
2✔
330
    }
331

332
    /**
333
     * Retrieves the name of a user based on their IRI.
334
     *
335
     * @param userIri the IRI of the user
336
     * @return the name of the user if found, or null if not found
337
     */
338
    public String getName(IRI userIri) {
339
        return idNameMap.get(userIri);
6✔
340
    }
341

342
    /**
343
     * Retrieves the display name of a user based on their IRI.
344
     *
345
     * @param userIri the IRI of the user
346
     * @return the display name of the user, which includes their name and short name
347
     */
348
    public String getDisplayName(IRI userIri) {
349
        String name = getName(userIri);
×
350
        if (name != null && !name.isEmpty()) {
×
351
            return name + " (" + getShortName(userIri) + ")";
×
352
        }
353
        return getShortName(userIri);
×
354
    }
355

356
    /**
357
     * Retrieves a short display name for a user based on their IRI.
358
     *
359
     * @param userIri the IRI of the user
360
     * @return the short display name of the user, which is either their name or their short name
361
     */
362
    public String getShortDisplayName(IRI userIri) {
363
        String name = getName(userIri);
×
364
        if (name != null && !name.isEmpty()) {
×
365
            return name;
×
366
        }
367
        return getShortName(userIri);
×
368
    }
369

370
    /**
371
     * Retrieves a short display name for a user based on their IRI and public key.
372
     *
373
     * @param userIri    the IRI of the user
374
     * @param pubkeyhash the public key of the user
375
     * @return the short display name of the user, which may include a contested identity note if multiple identities are associated with the public key
376
     */
377
    public String getShortDisplayNameForPubkeyhash(IRI userIri, String pubkeyhash) {
378
        Set<IRI> ids = approvedPubkeyhashIdMap.get(pubkeyhash);
×
379
        if (ids == null || ids.isEmpty()) {
×
380
            ids = unapprovedPubkeyhashIdMap.get(pubkeyhash);
×
381
            if (ids == null || ids.isEmpty()) {
×
382
                return getShortName(userIri);
×
383
            } else if (ids.size() == 1) {
×
384
                return getShortDisplayName(ids.iterator().next());
×
385
            } else {
386
                return getShortName(userIri) + " (contested identity)";
×
387
            }
388
        } else if (ids.size() == 1) {
×
389
            return getShortDisplayName(ids.iterator().next());
×
390
        } else {
391
            return "(contested identity)";
×
392
        }
393
    }
394

395
    /**
396
     * Finds a single user ID for a given public key.
397
     *
398
     * @param pubkeyhash the public key to search for
399
     * @return the IRI of the user if exactly one ID is found for the public key, or null if no ID or multiple IDs are found
400
     */
401
    public IRI findSingleIdForPubkeyhash(String pubkeyhash) {
402
        if (approvedPubkeyhashIdMap.containsKey(pubkeyhash) && !approvedPubkeyhashIdMap.get(pubkeyhash).isEmpty()) {
×
403
            if (approvedPubkeyhashIdMap.get(pubkeyhash).size() == 1) {
×
404
                return approvedPubkeyhashIdMap.get(pubkeyhash).iterator().next();
×
405
            } else {
406
                return null;
×
407
            }
408
        }
409
        if (unapprovedPubkeyhashIdMap.containsKey(pubkeyhash) && !unapprovedPubkeyhashIdMap.get(pubkeyhash).isEmpty()) {
×
410
            if (unapprovedPubkeyhashIdMap.get(pubkeyhash).size() == 1) {
×
411
                return unapprovedPubkeyhashIdMap.get(pubkeyhash).iterator().next();
×
412
            } else {
413
                return null;
×
414
            }
415
        }
416
        return null;
×
417
    }
418

419
    public final transient Comparator<IRI> userComparator = (iri1, iri2) -> getDisplayName(iri1).toLowerCase().compareTo(getDisplayName(iri2).toLowerCase());
4✔
420

421
    /**
422
     * Retrieves a list of users, either approved or unapproved.
423
     *
424
     * @param approved if true, retrieves approved users; if false, retrieves unapproved users
425
     * @return a sorted list of user IRIs
426
     */
427
    public List<IRI> getUsers(boolean approved) {
428
        List<IRI> list;
429
        if (approved) {
×
430
            list = new ArrayList<IRI>(approvedIdPubkeyhashMap.keySet());
×
431
        } else {
432
            list = new ArrayList<IRI>();
×
433
            for (IRI u : unapprovedIdPubkeyhashMap.keySet()) {
×
434
                if (!approvedIdPubkeyhashMap.containsKey(u)) list.add(u);
×
435
            }
×
436
        }
437
        // TODO Cache the sorted list to not sort from scratch each time:
438
        list.sort(userComparator);
×
439
        return list;
×
440
    }
441

442
    /**
443
     * Retrieves a list of public keys for a given user.
444
     *
445
     * @param user     the IRI of the user whose public keys are to be retrieved
446
     * @param approved if true, retrieves approved public keys; if false, retrieves unapproved public keys
447
     * @return a list of public keys associated with the user, either approved or unapproved
448
     */
449
    public List<String> getPubkeyhashes(IRI user, Boolean approved) {
450
        List<String> pubkeys = new ArrayList<>();
×
451
        if (user != null) {
×
452
            if (approved == null || approved) {
×
453
                if (approvedIdPubkeyhashMap.containsKey(user)) pubkeys.addAll(approvedIdPubkeyhashMap.get(user));
×
454
            }
455
            if (approved == null || !approved) {
×
456
                if (unapprovedIdPubkeyhashMap.containsKey(user)) pubkeys.addAll(unapprovedIdPubkeyhashMap.get(user));
×
457
            }
458
        }
459
        return pubkeys;
×
460
    }
461

462
    /**
463
     * Retrieves a list of introduction nanopublications for a given user.
464
     *
465
     * @param user the IRI of the user whose introduction nanopublications are to be retrieved
466
     * @return a list of introduction nanopublications associated with the user, sorted by creation time
467
     */
468
    public List<IntroNanopub> getIntroNanopubs(IRI user) {
469
        if (introNanopubLists.containsKey(user)) return introNanopubLists.get(user);
×
470

471
        Map<IRI, IntroNanopub> introNps = new HashMap<>();
×
472
        if (approvedIdPubkeyhashMap.containsKey(user)) {
×
473
            for (String pk : approvedIdPubkeyhashMap.get(user)) {
×
474
                getIntroNanopubs(pk, introNps);
×
475
            }
×
476
        }
477
        if (unapprovedIdPubkeyhashMap.containsKey(user)) {
×
478
            for (String pk : unapprovedIdPubkeyhashMap.get(user)) {
×
479
                getIntroNanopubs(pk, introNps);
×
480
            }
×
481
        }
482
        List<IntroNanopub> list = new ArrayList<>(introNps.values());
×
483
        list.sort((i0, i1) -> {
×
484
            Calendar c0 = SimpleTimestampPattern.getCreationTime(i0.getNanopub());
×
485
            Calendar c1 = SimpleTimestampPattern.getCreationTime(i1.getNanopub());
×
486
            if (c0 == null && c1 == null) return 0;
×
487
            if (c0 == null) return 1;
×
488
            if (c1 == null) return -1;
×
489
            return -c0.compareTo(c1);
×
490
        });
491
        introNanopubLists.put(user, list);
×
492
        return list;
×
493
    }
494

495
    /**
496
     * Retrieves a map of introduction nanopublications for a given public key.
497
     *
498
     * @param pubkey the public key for which introduction nanopublications are to be retrieved
499
     * @return a map where the keys are IRI identifiers of introduction nanopublications and the values are the corresponding IntroNanopub objects
500
     */
501
    public Map<IRI, IntroNanopub> getIntroNanopubs(String pubkey) {
502
        Map<IRI, IntroNanopub> introNps = new HashMap<>();
×
503
        getIntroNanopubs(pubkey, introNps);
×
504
        return introNps;
×
505
    }
506

507
    private void getIntroNanopubs(String pubkeyhash, Map<IRI, IntroNanopub> introNps) {
508
        if (pubkeyhashIntroMap.containsKey(pubkeyhash)) {
×
509
            for (IRI iri : pubkeyhashIntroMap.get(pubkeyhash)) {
×
510
                IntroNanopub introNp = toIntroNanopub(iri);
×
511
                if (introNp != null) {
×
512
                    introNps.put(iri, introNp);
×
513
                }
514
            }
×
515
        }
516
    }
×
517

518
    /**
519
     * Checks if the given introduction nanopublication is approved.
520
     *
521
     * @param in the introduction nanopublication to check
522
     * @return true if the introduction nanopublication is approved, false otherwise
523
     */
524
    public boolean isApproved(IntroNanopub in) {
525
        return approvedIntros.contains(in.getNanopub().getUri());
×
526
    }
527

528
    /**
529
     * Retrieves the location of a public key.
530
     *
531
     * @param pubkeyhash the public key for which the location is to be retrieved
532
     * @return the IRI of the key location if found, or null if not found or if multiple locations are associated with the key
533
     */
534
    public IRI getKeyLocationForPubkeyhash(String pubkeyhash) {
535
        if (approvedPubkeyhashLocationMap.containsKey(pubkeyhash) && !approvedPubkeyhashLocationMap.get(pubkeyhash).isEmpty()) {
×
536
            if (approvedPubkeyhashLocationMap.get(pubkeyhash).size() == 1)
×
537
                return approvedPubkeyhashLocationMap.get(pubkeyhash).iterator().next();
×
538
            return null;
×
539
        }
540
        if (unapprovedPubkeyhashLocationMap.containsKey(pubkeyhash) && unapprovedPubkeyhashLocationMap.get(pubkeyhash).size() == 1) {
×
541
            return unapprovedPubkeyhashLocationMap.get(pubkeyhash).iterator().next();
×
542
        }
543
        return null;
×
544
    }
545

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