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

knowledgepixels / nanodash / 19473636483

18 Nov 2025 04:35PM UTC coverage: 14.513% (+0.2%) from 14.288%
19473636483

push

github

ashleycaselli
ci(deps): update action actions/setup-java to v5.0.0

542 of 4792 branches covered (11.31%)

Branch coverage included in aggregate %.

1437 of 8844 relevant lines covered (16.25%)

0.72 hits per line

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

31.18
src/main/java/com/knowledgepixels/nanodash/Space.java
1
package com.knowledgepixels.nanodash;
2

3
import com.github.jsonldjava.shaded.com.google.common.collect.Ordering;
4
import com.google.common.collect.ArrayListMultimap;
5
import com.google.common.collect.Multimap;
6
import com.knowledgepixels.nanodash.template.Template;
7
import com.knowledgepixels.nanodash.template.TemplateData;
8
import com.knowledgepixels.nanodash.vocabulary.KPXL_TERMS;
9
import jakarta.xml.bind.DatatypeConverter;
10
import org.apache.commons.lang3.tuple.Pair;
11
import org.eclipse.rdf4j.model.IRI;
12
import org.eclipse.rdf4j.model.Literal;
13
import org.eclipse.rdf4j.model.Statement;
14
import org.eclipse.rdf4j.model.vocabulary.DCTERMS;
15
import org.eclipse.rdf4j.model.vocabulary.OWL;
16
import org.nanopub.Nanopub;
17
import org.nanopub.extra.services.ApiResponse;
18
import org.nanopub.extra.services.ApiResponseEntry;
19
import org.nanopub.extra.services.QueryRef;
20
import org.nanopub.vocabulary.NTEMPLATE;
21
import org.slf4j.Logger;
22
import org.slf4j.LoggerFactory;
23

24
import java.io.Serializable;
25
import java.util.*;
26

27
/**
28
 * Class representing a "Space", which can be any kind of collaborative unit, like a project, group, or event.
29
 */
30
public class Space implements Serializable {
31

32
    private static final Logger logger = LoggerFactory.getLogger(Space.class);
3✔
33

34
    private static List<Space> spaceList;
35
    private static Map<String, List<Space>> spaceListByType;
36
    private static Map<String, Space> spacesByCoreInfo = new HashMap<>();
4✔
37
    private static Map<String, Space> spacesById;
38
    private static Map<Space, Set<Space>> subspaceMap;
39
    private static Map<Space, Set<Space>> superspaceMap;
40
    private static boolean loaded = false;
2✔
41
    private static Long runRootUpdateAfter = null;
3✔
42

43
    /**
44
     * Refresh the list of spaces from the API response.
45
     *
46
     * @param resp The API response containing space data.
47
     */
48
    public static synchronized void refresh(ApiResponse resp) {
49
        spaceList = new ArrayList<>();
4✔
50
        spaceListByType = new HashMap<>();
4✔
51
        Map<String, Space> prevSpacesByCoreInfoPrev = spacesByCoreInfo;
2✔
52
        spacesByCoreInfo = new HashMap<>();
4✔
53
        spacesById = new HashMap<>();
4✔
54
        subspaceMap = new HashMap<>();
4✔
55
        superspaceMap = new HashMap<>();
4✔
56
        for (ApiResponseEntry entry : resp.getData()) {
11✔
57
            Space space = new Space(entry);
5✔
58
            Space prevSpace = prevSpacesByCoreInfoPrev.get(space.getCoreInfoString());
6✔
59
            if (prevSpace != null) space = prevSpace;
4✔
60
            spaceList.add(space);
4✔
61
            spaceListByType.computeIfAbsent(space.getType(), k -> new ArrayList<>()).add(space);
13✔
62
            spacesByCoreInfo.put(space.getCoreInfoString(), space);
6✔
63
            spacesById.put(space.getId(), space);
6✔
64
        }
1✔
65
        for (Space space : spaceList) {
10✔
66
            Space superSpace = space.getIdSuperspace();
3✔
67
            if (superSpace == null) continue;
3✔
68
            subspaceMap.computeIfAbsent(superSpace, k -> new HashSet<>()).add(space);
12✔
69
            superspaceMap.computeIfAbsent(space, k -> new HashSet<>()).add(superSpace);
12✔
70
        }
1✔
71
        loaded = true;
2✔
72
    }
1✔
73

74
    /**
75
     * Check if the spaces have been loaded.
76
     *
77
     * @return true if loaded, false otherwise.
78
     */
79
    public static boolean isLoaded() {
80
        return loaded;
×
81
    }
82

83
    public static boolean areAllSpacesInitialized() {
84
        for (Space space : spaceList) {
×
85
            if (!space.isDataInitialized()) return false;
×
86
        }
×
87
        return true;
×
88
    }
89

90
    public static void triggerAllDataUpdates() {
91
        for (Space space : spaceList) {
×
92
            space.triggerDataUpdate();
×
93
        }
×
94
    }
×
95

96
    /**
97
     * Ensure that the spaces are loaded, fetching them from the API if necessary.
98
     */
99
    public static void ensureLoaded() {
100
        if (spaceList == null) {
2✔
101
            try {
102
                if (runRootUpdateAfter != null) {
2!
103
                    while (System.currentTimeMillis() < runRootUpdateAfter) {
×
104
                        Thread.sleep(100);
×
105
                    }
106
                    runRootUpdateAfter = null;
×
107
                }
108
            } catch (InterruptedException ex) {
×
109
                logger.error("Interrupted", ex);
×
110
            }
1✔
111
            refresh(QueryApiAccess.forcedGet(new QueryRef("get-spaces")));
6✔
112
        }
113
    }
1✔
114

115
    public static void forceRootRefresh(long waitMillis) {
116
        spaceList = null;
×
117
        runRootUpdateAfter = System.currentTimeMillis() + waitMillis;
×
118
    }
×
119

120
    /**
121
     * Get the list of all spaces.
122
     *
123
     * @return List of spaces.
124
     */
125
    public static List<Space> getSpaceList() {
126
        ensureLoaded();
×
127
        return spaceList;
×
128
    }
129

130
    /**
131
     * Get the list of spaces of a specific type.
132
     *
133
     * @param type The type of spaces to retrieve.
134
     *             System.err.println("REFRESH...");
135
     * @return List of spaces of the specified type.
136
     */
137
    public static List<Space> getSpaceList(String type) {
138
        ensureLoaded();
×
139
        return spaceListByType.computeIfAbsent(type, k -> new ArrayList<>());
×
140
    }
141

142
    /**
143
     * Get a space by its id.
144
     *
145
     * @param id The id of the space.
146
     * @return The corresponding Space object, or null if not found.
147
     */
148
    public static Space get(String id) {
149
        ensureLoaded();
1✔
150
        return spacesById.get(id);
5✔
151
    }
152

153
    /**
154
     * Mark all spaces as needing a data update.
155
     */
156
    public static void refresh() {
157
        refresh(QueryApiAccess.forcedGet(new QueryRef("get-spaces")));
6✔
158
        for (Space space : spaceList) {
10✔
159
            space.dataNeedsUpdate = true;
3✔
160
        }
1✔
161
    }
1✔
162

163
    public void forceRefresh(long waitMillis) {
164
        dataNeedsUpdate = true;
×
165
        dataInitialized = false;
×
166
        runUpdateAfter = System.currentTimeMillis() + waitMillis;
×
167
    }
×
168

169
    private String id, label, rootNanopubId, type;
170
    private Nanopub rootNanopub = null;
3✔
171
    private SpaceData data = new SpaceData();
5✔
172

173
    private static class SpaceData implements Serializable {
2✔
174

175
        List<String> altIds = new ArrayList<>();
5✔
176

177
        String description = null;
3✔
178
        Calendar startDate, endDate;
179
        IRI defaultProvenance = null;
3✔
180

181
        List<IRI> admins = new ArrayList<>();
5✔
182
        // TODO Make Pair<SpaceMemberRole, String> a new class with SpaceMemberRole + nanopub URI
183
        Map<IRI, Set<Pair<SpaceMemberRole, String>>> users = new HashMap<>();
5✔
184
        List<Pair<SpaceMemberRole, String>> roles = new ArrayList<>();
5✔
185
        Map<IRI, SpaceMemberRole> roleMap = new HashMap<>();
5✔
186

187
        Map<String, IRI> adminPubkeyMap = new HashMap<>();
5✔
188
        Set<Serializable> pinnedResources = new HashSet<>();
5✔
189
        List<ViewDisplay> topLevelViews = new ArrayList<>();
5✔
190
        List<ViewDisplay> partLevelViews = new ArrayList<>();
5✔
191
        Set<String> pinGroupTags = new HashSet<>();
5✔
192
        Map<String, Set<Serializable>> pinnedResourceMap = new HashMap<>();
6✔
193

194
        void addAdmin(IRI admin, String npId) {
195
            // TODO This isn't efficient for long owner lists:
196
            if (admins.contains(admin)) return;
5!
197
            admins.add(admin);
5✔
198
            UserData ud = User.getUserData();
2✔
199
            for (String pubkeyhash : ud.getPubkeyhashes(admin, true)) {
14✔
200
                adminPubkeyMap.put(pubkeyhash, admin);
6✔
201
            }
1✔
202
            users.computeIfAbsent(admin, (k) -> new HashSet<>()).add(Pair.of(SpaceMemberRole.ADMIN_ROLE, npId));
15✔
203
        }
1✔
204

205
    }
206

207
    private boolean dataInitialized = false;
3✔
208
    private boolean dataNeedsUpdate = true;
3✔
209
    private Long runUpdateAfter = null;
3✔
210

211
    private Space(ApiResponseEntry resp) {
2✔
212
        this.id = resp.get("space");
5✔
213
        this.label = resp.get("label");
5✔
214
        this.type = resp.get("type");
5✔
215
        this.rootNanopubId = resp.get("np");
5✔
216
        this.rootNanopub = Utils.getAsNanopub(rootNanopubId);
5✔
217
        setCoreData(data);
4✔
218
    }
1✔
219

220
    /**
221
     * Get the ID of the space.
222
     *
223
     * @return The space ID.
224
     */
225
    public String getId() {
226
        return id;
3✔
227
    }
228

229
    /**
230
     * Get the root nanopublication ID of the space.
231
     *
232
     * @return The root nanopub ID.
233
     */
234
    public String getRootNanopubId() {
235
        return rootNanopubId;
×
236
    }
237

238
    /**
239
     * Get a string combining the space ID and root nanopub ID for core identification.
240
     *
241
     * @return The core info string.
242
     */
243
    public String getCoreInfoString() {
244
        return id + " " + rootNanopubId;
6✔
245
    }
246

247
    /**
248
     * Get the root nanopublication of the space.
249
     *
250
     * @return The root Nanopub object.
251
     */
252
    public Nanopub getRootNanopub() {
253
        return rootNanopub;
×
254
    }
255

256
    /**
257
     * Get the label of the space.
258
     *
259
     * @return The space label.
260
     */
261
    public String getLabel() {
262
        return label;
×
263
    }
264

265
    /**
266
     * Get the type of the space.
267
     *
268
     * @return The space type.
269
     */
270
    public String getType() {
271
        return type;
3✔
272
    }
273

274
    /**
275
     * Get the start date of the space.
276
     *
277
     * @return The start date as a Calendar object, or null if not set.
278
     */
279
    public Calendar getStartDate() {
280
        return data.startDate;
×
281
    }
282

283
    /**
284
     * Get the end date of the space.
285
     *
286
     * @return The end date as a Calendar object, or null if not set.
287
     */
288
    public Calendar getEndDate() {
289
        return data.endDate;
×
290
    }
291

292
    /**
293
     * Get a simplified label for the type of space by removing any namespace prefix.
294
     *
295
     * @return The simplified type label.
296
     */
297
    public String getTypeLabel() {
298
        return type.replaceFirst("^.*/", "");
×
299
    }
300

301
    /**
302
     * Get the description of the space.
303
     *
304
     * @return The description string.
305
     */
306
    public String getDescription() {
307
        return data.description;
×
308
    }
309

310
    /**
311
     * Check if the space data has been initialized.
312
     *
313
     * @return true if initialized, false otherwise.
314
     */
315
    public boolean isDataInitialized() {
316
        triggerDataUpdate();
×
317
        return dataInitialized;
×
318
    }
319

320
    /**
321
     * Get the list of admins in this space.
322
     *
323
     * @return List of admin IRIs.
324
     */
325
    public List<IRI> getAdmins() {
326
        ensureInitialized();
×
327
        return data.admins;
×
328
    }
329

330
    /**
331
     * Get the list of members in this space.
332
     *
333
     * @return List of member IRIs.
334
     */
335
    public List<IRI> getUsers() {
336
        ensureInitialized();
×
337
        List<IRI> users = new ArrayList<IRI>(data.users.keySet());
×
338
        users.sort(User.getUserData().userComparator);
×
339
        return users;
×
340
    }
341

342
    /**
343
     * Get the roles of a specific member in this space.
344
     *
345
     * @param userId The IRI of the member.
346
     * @return Set of roles assigned to the member, or null if the member is not part of this space.
347
     */
348
    public Set<Pair<SpaceMemberRole, String>> getMemberRoles(IRI userId) {
349
        ensureInitialized();
×
350
        return data.users.get(userId);
×
351
    }
352

353
    /**
354
     * Check if a user is a member of this space.
355
     *
356
     * @param userId The IRI of the user to check.
357
     * @return true if the user is a member, false otherwise.
358
     */
359
    public boolean isMember(IRI userId) {
360
        ensureInitialized();
×
361
        return data.users.containsKey(userId);
×
362
    }
363

364
    public boolean isAdminPubkey(String pubkey) {
365
        ensureInitialized();
×
366
        return data.adminPubkeyMap.containsKey(pubkey);
×
367
    }
368

369
    /**
370
     * Get the list of pinned resources in this space.
371
     *
372
     * @return List of pinned resources.
373
     */
374
    public Set<Serializable> getPinnedResources() {
375
        ensureInitialized();
×
376
        return data.pinnedResources;
×
377
    }
378

379
    /**
380
     * Get the set of tags used for grouping pinned resources.
381
     *
382
     * @return Set of tags.
383
     */
384
    public Set<String> getPinGroupTags() {
385
        ensureInitialized();
×
386
        return data.pinGroupTags;
×
387
    }
388

389
    /**
390
     * Get a map of pinned resources grouped by their tags.
391
     *
392
     * @return Map where keys are tags and values are lists of pinned resources (Templates or GrlcQueries).
393
     */
394
    public Map<String, Set<Serializable>> getPinnedResourceMap() {
395
        ensureInitialized();
×
396
        return data.pinnedResourceMap;
×
397
    }
398

399
    /**
400
     * Returns the view displays and their associated nanopub IDs.
401
     *
402
     * @return Map of views to nanopub IDs
403
     */
404
    public List<ViewDisplay> getTopLevelViews() {
405
        return data.topLevelViews;
×
406
    }
407

408
    public List<ViewDisplay> getPartLevelViews(Set<IRI> classes) {
409
        triggerDataUpdate();
×
410
        List<ViewDisplay> viewDisplays = new ArrayList<>();
×
411
        for (ViewDisplay v : data.partLevelViews) {
×
412
            if (v.getView().hasTargetClasses()) {
×
413
                for (IRI c : classes) {
×
414
                    if (v.getView().hasTargetClass(c)) {
×
415
                        viewDisplays.add(v);
×
416
                        break;
×
417
                    }
418
                }
×
419
            } else {
420
                viewDisplays.add(v);
×
421
            }
422
        }
×
423
        return viewDisplays;
×
424
    }
425

426
    public boolean coversElement(String elementId) {
427
        triggerDataUpdate();
×
428
        for (ViewDisplay v : data.topLevelViews) {
×
429
            if (v.getView().coversElement(elementId)) return true;
×
430
        }
×
431
        for (ViewDisplay v : data.partLevelViews) {
×
432
            if (v.getView().coversElement(elementId)) return true;
×
433
        }
×
434
        return false;
×
435
    }
436

437
    /**
438
     * Get the default provenance IRI for this space.
439
     *
440
     * @return The default provenance IRI, or null if not set.
441
     */
442
    public IRI getDefaultProvenance() {
443
        return data.defaultProvenance;
×
444
    }
445

446
    /**
447
     * Get the roles defined in this space.
448
     *
449
     * @return List of roles.
450
     */
451
    public List<Pair<SpaceMemberRole, String>> getRoles() {
452
        return data.roles;
×
453
    }
454

455
    /**
456
     * Get the super ID of the space.
457
     *
458
     * @return Always returns null. Use getIdSuperspace() instead.
459
     */
460
    public String getSuperId() {
461
        return null;
×
462
    }
463

464
    /**
465
     * Get the superspace ID.
466
     *
467
     * @return The superspace, or null if not applicable.
468
     */
469
    public Space getIdSuperspace() {
470
        if (!id.matches("https?://[^/]+/.*/[^/]*/?")) return null;
5!
471
        String superId = id.replaceFirst("(https?://[^/]+/.*)/[^/]*/?", "$1");
6✔
472
        if (spacesById.containsKey(superId)) {
4✔
473
            return spacesById.get(superId);
5✔
474
        }
475
        return null;
2✔
476
    }
477

478
    /**
479
     * Get superspaces of this space.
480
     *
481
     * @return List of superspaces.
482
     */
483
    public List<Space> getSuperspaces() {
484
        if (superspaceMap.containsKey(this)) {
×
485
            List<Space> superspaces = new ArrayList<>(superspaceMap.get(this));
×
486
            Collections.sort(superspaces, Ordering.usingToString());
×
487
            return superspaces;
×
488
        }
489
        return new ArrayList<>();
×
490
    }
491

492
    /**
493
     * Get subspaces of this space.
494
     *
495
     * @return List of subspaces.
496
     */
497
    public List<Space> getSubspaces() {
498
        if (subspaceMap.containsKey(this)) {
×
499
            List<Space> subspaces = new ArrayList<>(subspaceMap.get(this));
×
500
            Collections.sort(subspaces, Ordering.usingToString());
×
501
            return subspaces;
×
502
        }
503
        return new ArrayList<>();
×
504
    }
505

506
    /**
507
     * Get subspaces of a specific type.
508
     *
509
     * @param type The type of subspaces to retrieve.
510
     * @return List of subspaces of the specified type.
511
     */
512
    public List<Space> getSubspaces(String type) {
513
        List<Space> l = new ArrayList<>();
×
514
        for (Space s : getSubspaces()) {
×
515
            if (s.getType().equals(type)) l.add(s);
×
516
        }
×
517
        return l;
×
518
    }
519

520
    /**
521
     * Get alternative IDs for the space.
522
     *
523
     * @return List of alternative IDs.
524
     */
525
    public List<String> getAltIDs() {
526
        return data.altIds;
×
527
    }
528

529
    private synchronized void ensureInitialized() {
530
        Thread thread = triggerDataUpdate();
×
531
        if (!dataInitialized && thread != null) {
×
532
            try {
533
                thread.join();
×
534
            } catch (InterruptedException ex) {
×
535
                logger.error("failed to join thread", ex);
×
536
            }
×
537
        }
538
    }
×
539

540
    private synchronized Thread triggerDataUpdate() {
541
        if (dataNeedsUpdate) {
×
542
            Thread thread = new Thread(() -> {
×
543
                try {
544
                    if (runUpdateAfter != null) {
×
545
                        while (System.currentTimeMillis() < runUpdateAfter) {
×
546
                            Thread.sleep(100);
×
547
                        }
548
                        runUpdateAfter = null;
×
549
                    }
550
                    SpaceData newData = new SpaceData();
×
551
                    setCoreData(newData);
×
552

553
                    newData.roles.add(Pair.of(SpaceMemberRole.ADMIN_ROLE, null));
×
554
                    newData.roleMap.put(KPXL_TERMS.HAS_ADMIN_PREDICATE, SpaceMemberRole.ADMIN_ROLE);
×
555

556
                    // TODO Improve this:
557
                    Multimap<String, String> spaceIds = ArrayListMultimap.create();
×
558
                    Multimap<String, String> resourceIds = ArrayListMultimap.create();
×
559
                    spaceIds.put("space", id);
×
560
                    resourceIds.put("resource", id);
×
561
                    for (String id : newData.altIds) {
×
562
                        spaceIds.put("space", id);
×
563
                        resourceIds.put("resource", id);
×
564
                    }
×
565

566
                    ApiResponse getAdminsResponse = QueryApiAccess.get(new QueryRef("get-admins", spaceIds));
×
567
                    boolean continueAddingAdmins = true;
×
568
                    while (continueAddingAdmins) {
×
569
                        continueAddingAdmins = false;
×
570
                        for (ApiResponseEntry r : getAdminsResponse.getData()) {
×
571
                            String pubkeyhash = r.get("pubkey");
×
572
                            if (newData.adminPubkeyMap.containsKey(pubkeyhash)) {
×
573
                                IRI adminId = Utils.vf.createIRI(r.get("admin"));
×
574
                                if (!newData.admins.contains(adminId)) {
×
575
                                    continueAddingAdmins = true;
×
576
                                    newData.addAdmin(adminId, r.get("np"));
×
577
                                }
578
                            }
579
                        }
×
580
                    }
581
                    newData.admins.sort(User.getUserData().userComparator);
×
582

583
                    Multimap<String, String> getSpaceMemberParams = ArrayListMultimap.create(spaceIds);
×
584

585
                    for (ApiResponseEntry r : QueryApiAccess.get(new QueryRef("get-space-member-roles", spaceIds)).getData()) {
×
586
                        if (!newData.adminPubkeyMap.containsKey(r.get("pubkey"))) continue;
×
587
                        SpaceMemberRole role = new SpaceMemberRole(r);
×
588
                        newData.roles.add(Pair.of(role, r.get("np")));
×
589

590
                        // TODO Handle cases of overlapping properties:
591
                        for (IRI p : role.getRegularProperties()) newData.roleMap.put(p, role);
×
592
                        for (IRI p : role.getInverseProperties()) newData.roleMap.put(p, role);
×
593

594
                        role.addRoleParams(getSpaceMemberParams);
×
595
                    }
×
596

597
                    for (ApiResponseEntry r : QueryApiAccess.get(new QueryRef("get-space-members", getSpaceMemberParams)).getData()) {
×
598
                        IRI memberId = Utils.vf.createIRI(r.get("member"));
×
599
                        SpaceMemberRole role = newData.roleMap.get(Utils.vf.createIRI(r.get("role")));
×
600
                        newData.users.computeIfAbsent(memberId, (k) -> new HashSet<>()).add(Pair.of(role, r.get("np")));
×
601
                    }
×
602

603
                    for (ApiResponseEntry r : QueryApiAccess.get(new QueryRef("get-pinned-templates", spaceIds)).getData()) {
×
604
                        if (!newData.adminPubkeyMap.containsKey(r.get("pubkey"))) continue;
×
605
                        Template t = TemplateData.get().getTemplate(r.get("template"));
×
606
                        if (t == null) continue;
×
607
                        newData.pinnedResources.add(t);
×
608
                        String tag = r.get("tag");
×
609
                        if (tag != null && !tag.isEmpty()) {
×
610
                            newData.pinGroupTags.add(r.get("tag"));
×
611
                            newData.pinnedResourceMap.computeIfAbsent(tag, k -> new HashSet<>()).add(TemplateData.get().getTemplate(r.get("template")));
×
612
                        }
613
                    }
×
614
                    for (ApiResponseEntry r : QueryApiAccess.get(new QueryRef("get-pinned-queries", spaceIds)).getData()) {
×
615
                        if (!newData.adminPubkeyMap.containsKey(r.get("pubkey"))) continue;
×
616
                        GrlcQuery query = GrlcQuery.get(r.get("query"));
×
617
                        if (query == null) continue;
×
618
                        newData.pinnedResources.add(query);
×
619
                        String tag = r.get("tag");
×
620
                        if (tag != null && !tag.isEmpty()) {
×
621
                            newData.pinGroupTags.add(r.get("tag"));
×
622
                            newData.pinnedResourceMap.computeIfAbsent(tag, k -> new HashSet<>()).add(query);
×
623
                        }
624
                    }
×
625
                    for (ApiResponseEntry r : QueryApiAccess.get(new QueryRef("get-view-displays", resourceIds)).getData()) {
×
626
                        if (!newData.adminPubkeyMap.containsKey(r.get("pubkey"))) continue;
×
627
                        try {
628
                            ViewDisplay vd = ViewDisplay.get(r.get("display"));
×
629
                            if (KPXL_TERMS.PART_LEVEL_VIEW_DISPLAY.stringValue().equals(r.get("displayType"))) {
×
630
                                newData.partLevelViews.add(vd);
×
631
                            } else {
632
                                newData.topLevelViews.add(vd);
×
633
                            }
634
                        } catch (IllegalArgumentException ex) {
×
635
                            logger.error("Couldn't generate view display object", ex);
×
636
                        }
×
637
                    }
×
638
                    Collections.sort(newData.topLevelViews);
×
639
                    Collections.sort(newData.partLevelViews);
×
640
                    data = newData;
×
641
                    dataInitialized = true;
×
642
                } catch (Exception ex) {
×
643
                    logger.error("Error while trying to update space data: {}", ex);
×
644
                }
×
645
            });
×
646
            thread.start();
×
647
            dataNeedsUpdate = false;
×
648
            return thread;
×
649
        }
650
        return null;
×
651
    }
652

653
    private void setCoreData(SpaceData data) {
654
        for (Statement st : rootNanopub.getAssertion()) {
12✔
655
            if (st.getSubject().stringValue().equals(getId())) {
7!
656
                if (st.getPredicate().equals(OWL.SAMEAS) && st.getObject() instanceof IRI objIri) {
14!
657
                    data.altIds.add(objIri.stringValue());
7✔
658
                } else if (st.getPredicate().equals(DCTERMS.DESCRIPTION)) {
5✔
659
                    data.description = st.getObject().stringValue();
6✔
660
                } else if (st.getPredicate().stringValue().equals("http://schema.org/startDate")) {
6✔
661
                    try {
662
                        data.startDate = DatatypeConverter.parseDateTime(st.getObject().stringValue());
6✔
663
                    } catch (IllegalArgumentException ex) {
×
664
                        logger.error("Failed to parse date {}", st.getObject().stringValue());
×
665
                    }
1✔
666
                } else if (st.getPredicate().stringValue().equals("http://schema.org/endDate")) {
6✔
667
                    try {
668
                        data.endDate = DatatypeConverter.parseDateTime(st.getObject().stringValue());
6✔
669
                    } catch (IllegalArgumentException ex) {
×
670
                        logger.error("Failed to parse date {}", st.getObject().stringValue());
×
671
                    }
1✔
672
                } else if (st.getPredicate().equals(KPXL_TERMS.HAS_ADMIN) && st.getObject() instanceof IRI obj) {
14!
673
                    data.addAdmin(obj, rootNanopub.getUri().stringValue());
8✔
674
                } else if (st.getPredicate().equals(KPXL_TERMS.HAS_PINNED_TEMPLATE) && st.getObject() instanceof IRI obj) {
5!
675
                    data.pinnedResources.add(TemplateData.get().getTemplate(obj.stringValue()));
×
676
                } else if (st.getPredicate().equals(KPXL_TERMS.HAS_PINNED_QUERY) && st.getObject() instanceof IRI obj) {
5!
677
                    data.pinnedResources.add(GrlcQuery.get(obj.stringValue()));
×
678
                } else if (st.getPredicate().equals(NTEMPLATE.HAS_DEFAULT_PROVENANCE) && st.getObject() instanceof IRI obj) {
5!
679
                    data.defaultProvenance = obj;
1✔
680
                }
681
            } else if (st.getPredicate().equals(NTEMPLATE.HAS_TAG) && st.getObject() instanceof Literal l) {
×
682
                data.pinGroupTags.add(l.stringValue());
×
683
                Set<Serializable> list = data.pinnedResourceMap.get(l.stringValue());
×
684
                if (list == null) {
×
685
                    list = new HashSet<>();
×
686
                    data.pinnedResourceMap.put(l.stringValue(), list);
×
687
                }
688
                list.add(TemplateData.get().getTemplate(st.getSubject().stringValue()));
×
689
            }
690
        }
1✔
691
    }
1✔
692

693
    @Override
694
    public String toString() {
695
        return id;
×
696
    }
697

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