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

knowledgepixels / nanodash / 17211438187

25 Aug 2025 02:13PM UTC coverage: 12.474% (+0.03%) from 12.446%
17211438187

push

github

ashleycaselli
build(deps): update org.apache.maven.plugins:maven-compiler-plugin to v3.14.0

330 of 3766 branches covered (8.76%)

Branch coverage included in aggregate %.

982 of 6752 relevant lines covered (14.54%)

0.64 hits per line

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

31.3
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.slf4j.Logger;
18
import org.slf4j.LoggerFactory;
19

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

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

29
    private static final long serialVersionUID = 1L;
30

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

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

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

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

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

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

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

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

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

135
    private void register(ApiResponseEntry entry) {
136
        IRI userIri;
137
        try {
138
            userIri = vf.createIRI(entry.get("user"));
6✔
139
        } catch (IllegalArgumentException 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
        }
1✔
150
        IRI keyLocation = null;
2✔
151
        try {
152
            keyLocation = vf.createIRI(entry.get("keyLocation"));
6✔
153
        } catch (IllegalArgumentException ex) {
1✔
154
        }
1✔
155
        if (approved) {
2✔
156
            if (authoritative) {
2✔
157
                if (introNpIri != null) approvedIntros.add(introNpIri);
7!
158
                if (keyLocation != null) addValue(approvedPubkeyhashLocationMap, pubkeyhash, keyLocation);
9✔
159
            }
160
        } else {
161
            addValue(unapprovedIdPubkeyhashMap, userIri, entry.get("pubkeyHash"));
8✔
162
            addValue(unapprovedPubkeyhashIdMap, entry.get("pubkeyHash"), userIri);
8✔
163
            if (keyLocation != null) addValue(unapprovedPubkeyhashLocationMap, pubkeyhash, keyLocation);
8✔
164
        }
165
        if (introNpIri != null) {
2!
166
            addValue(pubkeyhashIntroMap, entry.get("pubkeyHash"), introNpIri);
8✔
167
        }
168
        String name = entry.get("name");
4✔
169
        if (!"".equals(name) && !idNameMap.containsKey(userIri)) {
9✔
170
            idNameMap.put(userIri, name);
6✔
171
        }
172
    }
1✔
173

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

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

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

239
    private boolean hasValue(Map<IRI, Set<String>> map, IRI key, String value) {
240
        Set<String> values = map.get(key);
×
241
        if (values == null) return false;
×
242
        return values.contains(value);
×
243
    }
244

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

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

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

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

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

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

313
    public IRI getSignatureOwnerIri(Nanopub np) {
314
        try {
315
            if (np != null) {
2!
316
                NanopubSignatureElement se = SignatureUtils.getSignatureElement(np);
3✔
317
                if (se != null) {
2!
318
                    String pubkeyhash = Utils.createSha256HexHash(se.getPublicKeyString());
×
319
                    return getUserIriForPubkeyhash(pubkeyhash, true);
×
320
                }
321
            }
322
        } catch (MalformedCryptoElementException ex) {
×
323
            ex.printStackTrace();
×
324
        }
1✔
325
        return null;
2✔
326
    }
327

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

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

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

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

391
    /**
392
     * Finds a single user ID for a given public key.
393
     *
394
     * @param pubkeyhash the public key to search for
395
     * @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
396
     */
397
    public IRI findSingleIdForPubkeyhash(String pubkeyhash) {
398
        if (approvedPubkeyhashIdMap.containsKey(pubkeyhash) && !approvedPubkeyhashIdMap.get(pubkeyhash).isEmpty()) {
×
399
            if (approvedPubkeyhashIdMap.get(pubkeyhash).size() == 1) {
×
400
                return approvedPubkeyhashIdMap.get(pubkeyhash).iterator().next();
×
401
            } else {
402
                return null;
×
403
            }
404
        }
405
        if (unapprovedPubkeyhashIdMap.containsKey(pubkeyhash) && !unapprovedPubkeyhashIdMap.get(pubkeyhash).isEmpty()) {
×
406
            if (unapprovedPubkeyhashIdMap.get(pubkeyhash).size() == 1) {
×
407
                return unapprovedPubkeyhashIdMap.get(pubkeyhash).iterator().next();
×
408
            } else {
409
                return null;
×
410
            }
411
        }
412
        return null;
×
413
    }
414

415
    private transient Comparator<IRI> comparator = new Comparator<IRI>() {
12✔
416

417
        @Override
418
        public int compare(IRI iri1, IRI iri2) {
419
            return getDisplayName(iri1).toLowerCase().compareTo(getDisplayName(iri2).toLowerCase());
×
420
        }
421

422
    };
423

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

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

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

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

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

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

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

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

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