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

knowledgepixels / nanodash / 17852532121

19 Sep 2025 08:10AM UTC coverage: 13.568% (-0.3%) from 13.87%
17852532121

push

github

tkuhn
feat: Switch to QueryRef provided by nanopub, using multimap

428 of 4008 branches covered (10.68%)

Branch coverage included in aggregate %.

1104 of 7283 relevant lines covered (15.16%)

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 java.io.IOException;
4
import java.io.Serializable;
5
import java.util.ArrayList;
6
import java.util.Calendar;
7
import java.util.Comparator;
8
import java.util.HashMap;
9
import java.util.HashSet;
10
import java.util.List;
11
import java.util.Map;
12
import java.util.Set;
13

14
import org.eclipse.rdf4j.common.exception.RDF4JException;
15
import org.eclipse.rdf4j.model.IRI;
16
import org.eclipse.rdf4j.model.ValueFactory;
17
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
18
import org.nanopub.MalformedNanopubException;
19
import org.nanopub.Nanopub;
20
import org.nanopub.SimpleTimestampPattern;
21
import org.nanopub.extra.security.MalformedCryptoElementException;
22
import org.nanopub.extra.security.NanopubSignatureElement;
23
import org.nanopub.extra.security.SignatureUtils;
24
import org.nanopub.extra.server.GetNanopub;
25
import org.nanopub.extra.services.ApiResponseEntry;
26
import org.nanopub.extra.services.QueryRef;
27
import org.nanopub.extra.setting.IntroNanopub;
28
import org.nanopub.extra.setting.NanopubSetting;
29
import org.nanopub.vocabulary.NPX;
30
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32

33
/**
34
 * UserData class manages user-related data.
35
 */
36
public class UserData implements Serializable {
37

38
    private static ValueFactory vf = SimpleValueFactory.getInstance();
2✔
39
    private static final Logger logger = LoggerFactory.getLogger(UserData.class);
4✔
40

41
    private HashMap<IRI, Set<String>> approvedIdPubkeyhashMap = new HashMap<>();
5✔
42
    private HashMap<String, Set<IRI>> approvedPubkeyhashIdMap = new HashMap<>();
5✔
43
    private HashMap<String, Set<IRI>> approvedPubkeyhashLocationMap = new HashMap<>();
5✔
44
    private HashMap<IRI, Set<String>> unapprovedIdPubkeyhashMap = new HashMap<>();
5✔
45
    private HashMap<String, Set<IRI>> unapprovedPubkeyhashIdMap = new HashMap<>();
5✔
46
    private HashMap<String, Set<IRI>> unapprovedPubkeyhashLocationMap = new HashMap<>();
5✔
47
    private HashMap<String, Set<IRI>> pubkeyhashIntroMap = new HashMap<>();
5✔
48
    private HashMap<IRI, IntroNanopub> introMap = new HashMap<>();
5✔
49
    private Set<IRI> approvedIntros = new HashSet<>();
5✔
50
    private HashMap<IRI, String> idNameMap = new HashMap<>();
5✔
51
    private HashMap<IRI, List<IntroNanopub>> introNanopubLists = new HashMap<>();
5✔
52

53
    /**
54
     * Default constructor for UserData.
55
     * Initializes the user data by fetching nanopublications settings.
56
     */
57
    UserData() {
2✔
58
        final NanodashPreferences pref = NanodashPreferences.get();
2✔
59

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

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

110
        logger.info("Loading approved users...");
3✔
111
        try {
112
            for (RegistryAccountInfo rai : RegistryAccountInfo.fromUrl(Utils.getMainRegistryUrl() + "list.json")) {
12✔
113
                registerApproved(rai);
3✔
114
            }
1✔
115
        } catch (Exception ex) {
×
116
            throw new RuntimeException(ex);
×
117
        }
1✔
118

119
        logger.info("Loading user details...");
3✔
120
        // Get latest introductions for all users, including unapproved ones:
121
        for (ApiResponseEntry entry : QueryApiAccess.forcedGet(new QueryRef("get-all-user-intros")).getData()) {
15✔
122
            register(entry);
3✔
123
        }
1✔
124
    }
1✔
125

126
    private IntroNanopub toIntroNanopub(IRI iri) {
127
        if (iri == null) return null;
×
128
        if (introMap.containsKey(iri)) return introMap.get(iri);
×
129
        Nanopub np = Utils.getNanopub(iri.stringValue());
×
130
        if (np == null) return null;
×
131
        IntroNanopub introNp = new IntroNanopub(np);
×
132
        introMap.put(np.getUri(), introNp);
×
133
        return introNp;
×
134
    }
135

136
    private void registerApproved(RegistryAccountInfo rai) {
137
        if (rai.getAgent().equals("$")) return;
6✔
138
        addValue(approvedIdPubkeyhashMap, rai.getAgentIri(), rai.getPubkey());
8✔
139
        addValue(approvedPubkeyhashIdMap, rai.getPubkey(), rai.getAgentIri());
8✔
140
    }
1✔
141

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

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

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

242
    private void addValue(Map<String, Set<IRI>> map, String key, IRI value) {
243
        Set<IRI> values = map.get(key);
5✔
244
        if (values == null) {
2✔
245
            values = new HashSet<>();
4✔
246
            map.put(key, values);
5✔
247
        }
248
        values.add(value);
4✔
249
    }
1✔
250

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

257
//        private static boolean hasValue(Map<String,Set<IRI>> map, String key, IRI value) {
258
//                Set<IRI> values = map.get(key);
259
//                if (values == null) return false;
260
//                return values.contains(value);
261
//        }
262

263
    /**
264
     * Checks if the given IRI is a user identifier.
265
     *
266
     * @param userIri the IRI to check
267
     * @return true if the IRI is a user identifier, false otherwise
268
     */
269
    public boolean isUser(IRI userIri) {
270
        return approvedIdPubkeyhashMap.containsKey(userIri) || unapprovedIdPubkeyhashMap.containsKey(userIri);
×
271
    }
272

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

289
    /**
290
     * Checks if the given public key is approved for the specified user.
291
     *
292
     * @param pubkeyhash the public key to check
293
     * @param user       the IRI of the user to check against
294
     * @return true if the key is approved for the user, false otherwise
295
     */
296
    public boolean isApprovedPubkeyhashForUser(String pubkeyhash, IRI user) {
297
        return hasValue(approvedIdPubkeyhashMap, user, pubkeyhash);
×
298
    }
299

300
    private String getShortName(IRI userIri) {
301
        if (userIri == null) return "(unknown)";
×
302
        String n = userIri.stringValue();
×
303
        n = n.replaceFirst("^https://orcid.org/", "");
×
304
        if (n.length() > 40) return n.substring(0, 30) + "...";
×
305
        return n;
×
306
    }
307

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

325
    public IRI getSignatureOwnerIri(Nanopub np) {
326
        try {
327
            if (np != null) {
2!
328
                NanopubSignatureElement se = SignatureUtils.getSignatureElement(np);
3✔
329
                if (se != null) {
2!
330
                    String pubkeyhash = Utils.createSha256HexHash(se.getPublicKeyString());
×
331
                    return getUserIriForPubkeyhash(pubkeyhash, true);
×
332
                }
333
            }
334
        } catch (MalformedCryptoElementException ex) {
×
335
            logger.error("Error getting signature element", ex);
×
336
        }
1✔
337
        return null;
2✔
338
    }
339

340
    /**
341
     * Retrieves the name of a user based on their IRI.
342
     *
343
     * @param userIri the IRI of the user
344
     * @return the name of the user if found, or null if not found
345
     */
346
    public String getName(IRI userIri) {
347
        return idNameMap.get(userIri);
6✔
348
    }
349

350
    /**
351
     * Retrieves the display name of a user based on their IRI.
352
     *
353
     * @param userIri the IRI of the user
354
     * @return the display name of the user, which includes their name and short name
355
     */
356
    public String getDisplayName(IRI userIri) {
357
        String name = getName(userIri);
×
358
        if (name != null && !name.isEmpty()) {
×
359
            return name + " (" + getShortName(userIri) + ")";
×
360
        }
361
        return getShortName(userIri);
×
362
    }
363

364
    /**
365
     * Retrieves a short display name for a user based on their IRI.
366
     *
367
     * @param userIri the IRI of the user
368
     * @return the short display name of the user, which is either their name or their short name
369
     */
370
    public String getShortDisplayName(IRI userIri) {
371
        String name = getName(userIri);
×
372
        if (name != null && !name.isEmpty()) {
×
373
            return name;
×
374
        }
375
        return getShortName(userIri);
×
376
    }
377

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

403
    /**
404
     * Finds a single user ID for a given public key.
405
     *
406
     * @param pubkeyhash the public key to search for
407
     * @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
408
     */
409
    public IRI findSingleIdForPubkeyhash(String pubkeyhash) {
410
        if (approvedPubkeyhashIdMap.containsKey(pubkeyhash) && !approvedPubkeyhashIdMap.get(pubkeyhash).isEmpty()) {
×
411
            if (approvedPubkeyhashIdMap.get(pubkeyhash).size() == 1) {
×
412
                return approvedPubkeyhashIdMap.get(pubkeyhash).iterator().next();
×
413
            } else {
414
                return null;
×
415
            }
416
        }
417
        if (unapprovedPubkeyhashIdMap.containsKey(pubkeyhash) && !unapprovedPubkeyhashIdMap.get(pubkeyhash).isEmpty()) {
×
418
            if (unapprovedPubkeyhashIdMap.get(pubkeyhash).size() == 1) {
×
419
                return unapprovedPubkeyhashIdMap.get(pubkeyhash).iterator().next();
×
420
            } else {
421
                return null;
×
422
            }
423
        }
424
        return null;
×
425
    }
426

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

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

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

470
    /**
471
     * Retrieves a list of introduction nanopublications for a given user.
472
     *
473
     * @param user the IRI of the user whose introduction nanopublications are to be retrieved
474
     * @return a list of introduction nanopublications associated with the user, sorted by creation time
475
     */
476
    public List<IntroNanopub> getIntroNanopubs(IRI user) {
477
        if (introNanopubLists.containsKey(user)) return introNanopubLists.get(user);
×
478

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

503
    /**
504
     * Retrieves a map of introduction nanopublications for a given public key.
505
     *
506
     * @param pubkey the public key for which introduction nanopublications are to be retrieved
507
     * @return a map where the keys are IRI identifiers of introduction nanopublications and the values are the corresponding IntroNanopub objects
508
     */
509
    public Map<IRI, IntroNanopub> getIntroNanopubs(String pubkey) {
510
        Map<IRI, IntroNanopub> introNps = new HashMap<>();
×
511
        getIntroNanopubs(pubkey, introNps);
×
512
        return introNps;
×
513
    }
514

515
    private void getIntroNanopubs(String pubkeyhash, Map<IRI, IntroNanopub> introNps) {
516
        if (pubkeyhashIntroMap.containsKey(pubkeyhash)) {
×
517
            for (IRI iri : pubkeyhashIntroMap.get(pubkeyhash)) {
×
518
                IntroNanopub introNp = toIntroNanopub(iri);
×
519
                if (introNp != null) {
×
520
                    introNps.put(iri, introNp);
×
521
                }
522
            }
×
523
        }
524
    }
×
525

526
    /**
527
     * Checks if the given introduction nanopublication is approved.
528
     *
529
     * @param in the introduction nanopublication to check
530
     * @return true if the introduction nanopublication is approved, false otherwise
531
     */
532
    public boolean isApproved(IntroNanopub in) {
533
        return approvedIntros.contains(in.getNanopub().getUri());
×
534
    }
535

536
    /**
537
     * Retrieves the location of a public key.
538
     *
539
     * @param pubkeyhash the public key for which the location is to be retrieved
540
     * @return the IRI of the key location if found, or null if not found or if multiple locations are associated with the key
541
     */
542
    public IRI getKeyLocationForPubkeyhash(String pubkeyhash) {
543
        if (approvedPubkeyhashLocationMap.containsKey(pubkeyhash) && !approvedPubkeyhashLocationMap.get(pubkeyhash).isEmpty()) {
×
544
            if (approvedPubkeyhashLocationMap.get(pubkeyhash).size() == 1)
×
545
                return approvedPubkeyhashLocationMap.get(pubkeyhash).iterator().next();
×
546
            return null;
×
547
        }
548
        if (unapprovedPubkeyhashLocationMap.containsKey(pubkeyhash) && unapprovedPubkeyhashLocationMap.get(pubkeyhash).size() == 1) {
×
549
            return unapprovedPubkeyhashLocationMap.get(pubkeyhash).iterator().next();
×
550
        }
551
        return null;
×
552
    }
553

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