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

knowledgepixels / nanodash / 17302137193

28 Aug 2025 04:35PM UTC coverage: 11.965% (-0.4%) from 12.355%
17302137193

Pull #244

github

web-flow
Merge 4e969b0ee into 3323a35f1
Pull Request #244: Use vocabularies with latest version of `nanopub-java`

331 of 3840 branches covered (8.62%)

Branch coverage included in aggregate %.

943 of 6808 relevant lines covered (13.85%)

0.61 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.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 final long serialVersionUID = 1L;
31

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

423
    };
424

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

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

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

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

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

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

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

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

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