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

knowledgepixels / nanodash / 19894325826

03 Dec 2025 12:46PM UTC coverage: 14.953% (+0.3%) from 14.631%
19894325826

push

github

tkuhn
fix(ProfiledResource): Fix showing of views for resource parts

570 of 4980 branches covered (11.45%)

Branch coverage included in aggregate %.

1533 of 9084 relevant lines covered (16.88%)

0.75 hits per line

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

11.36
src/main/java/com/knowledgepixels/nanodash/ProfiledResource.java
1
package com.knowledgepixels.nanodash;
2

3
import com.knowledgepixels.nanodash.vocabulary.KPXL_TERMS;
4
import org.eclipse.rdf4j.model.IRI;
5
import org.nanopub.Nanopub;
6
import org.nanopub.extra.services.ApiResponseEntry;
7
import org.nanopub.extra.services.QueryRef;
8
import org.slf4j.Logger;
9
import org.slf4j.LoggerFactory;
10

11
import java.io.Serializable;
12
import java.util.*;
13

14
public class ProfiledResource implements Serializable {
15

16
    private static final Logger logger = LoggerFactory.getLogger(ProfiledResource.class);
4✔
17

18
    protected static class ResourceData implements Serializable {
2✔
19
        List<ViewDisplay> viewDisplays = new ArrayList<>();
6✔
20
    }
21

22
    private String id;
23
    private Space space;
24
    private ResourceData data = new ResourceData();
5✔
25
    private boolean dataInitialized = false;
3✔
26
    private boolean dataNeedsUpdate = true;
3✔
27
    private Long runUpdateAfter = null;
3✔
28

29
    protected ProfiledResource(String id) {
2✔
30
        this.id = id;
3✔
31
    }
1✔
32

33
    protected void initSpace(Space space) {
34
        this.space = space;
3✔
35
    }
1✔
36

37
    public String getId() {
38
        return id;
3✔
39
    }
40

41
    protected synchronized Thread triggerDataUpdate() {
42
        if (dataNeedsUpdate) {
×
43
            Thread thread = new Thread(() -> {
×
44
                try {
45
                    if (runUpdateAfter != null) {
×
46
                        while (System.currentTimeMillis() < runUpdateAfter) {
×
47
                            Thread.sleep(100);
×
48
                        }
49
                        runUpdateAfter = null;
×
50
                    }
51

52
                    ResourceData newData = new ResourceData();
×
53

54
                    for (ApiResponseEntry r : QueryApiAccess.get(new QueryRef("get-view-displays", "resource", id)).getData()) {
×
55
                        if (space != null && !space.isAdminPubkey(r.get("pubkey"))) continue;
×
56
                        try {
57
                            newData.viewDisplays.add(ViewDisplay.get(r.get("display")));
×
58
                        } catch (IllegalArgumentException ex) {
×
59
                            logger.error("Couldn't generate view display object", ex);
×
60
                        }
×
61
                    }
×
62
                    data = newData;
×
63
                    dataInitialized = true;
×
64
                } catch (Exception ex) {
×
65
                    logger.error("Error while trying to update space data: {}", ex);
×
66
                    dataNeedsUpdate = true;
×
67
                }
×
68
            });
×
69
            thread.start();
×
70
            dataNeedsUpdate = false;
×
71
            return thread;
×
72
        }
73
        return null;
×
74
    }
75

76
    public void forceRefresh(long waitMillis) {
77
        dataNeedsUpdate = true;
×
78
        dataInitialized = false;
×
79
        runUpdateAfter = System.currentTimeMillis() + waitMillis;
×
80
    }
×
81

82
    public Long getRunUpdateAfter() {
83
        return runUpdateAfter;
×
84
    }
85

86
    public Space getSpace() {
87
        return space;
×
88
    }
89

90
    public String getNanopubId() {
91
        return null;
×
92
    }
93

94
    public Nanopub getNanopub() {
95
        return null;
×
96
    }
97

98
    public String getNamespace() {
99
        return null;
×
100
    }
101

102
    public void setDataNeedsUpdate() {
103
        dataNeedsUpdate = true;
3✔
104
    }
1✔
105

106
    public boolean isDataInitialized() {
107
        triggerDataUpdate();
×
108
        return dataInitialized;
×
109
    }
110

111
    public List<ViewDisplay> getViewDisplays() {
112
        return data.viewDisplays;
×
113
    }
114

115
    public List<ViewDisplay> getViewDisplays(boolean toplevel, Set<IRI> classes) {
116
        triggerDataUpdate();
×
117
        List<ViewDisplay> viewDisplays = new ArrayList<>();
×
118
        Set<IRI> viewKinds = new HashSet<>();
×
119

120
        for (ViewDisplay vd : getViewDisplays()) {
×
121
            IRI kind = vd.getViewKindIri();
×
122
            if (kind != null) {
×
123
                if (viewKinds.contains(kind)) continue;
×
124
                viewKinds.add(vd.getViewKindIri());
×
125
            }
126
            if (vd.hasType(KPXL_TERMS.DEACTIVATED_VIEW_DISPLAY)) continue;
×
127

128
            if (!toplevel && vd.hasType(KPXL_TERMS.TOP_LEVEL_VIEW_DISPLAY)) {
×
129
                // Deprecated
130
                // do nothing
131
            } else if (vd.appliesTo(getId(), classes)) {
×
132
                viewDisplays.add(vd);
×
133
            } else if (toplevel && vd.hasType(KPXL_TERMS.TOP_LEVEL_VIEW_DISPLAY)) {
×
134
                // Deprecated
135
                viewDisplays.add(vd);
×
136
            }
137
        }
×
138

139
        Collections.sort(viewDisplays);
×
140
        return viewDisplays;
×
141
    }
142

143
    public String getLabel() {
144
        return space.getLabel();
×
145
    }
146

147
    @Override
148
    public String toString() {
149
        return id;
×
150
    }
151

152
    /**
153
     * Gets the chain of superspaces from the current space up to the root space.
154
     *
155
     * @return the list of superspaces from the given space to the root space
156
     */
157
    public List<ProfiledResource> getAllSuperSpacesUntilRoot() {
158
        List<ProfiledResource> chain = new ArrayList<>();
×
159
        Set<String> visited = new HashSet<>();
×
160
        collectAncestors(space, chain, visited);
×
161
        Collections.reverse(chain);
×
162
        return chain;
×
163
    }
164

165
    private void collectAncestors(Space current, List<ProfiledResource> chain, Set<String> visited) {
166
        if (current == null) {
×
167
            return;
×
168
        }
169
        List<Space> parents = current.getSuperspaces();
×
170
        if (parents == null || parents.isEmpty()) {
×
171
            return;
×
172
        }
173
        Space parent = parents.getFirst();
×
174
        if (parent == null) {
×
175
            return;
×
176
        }
177
        String pid = parent.getId();
×
178
        if (pid == null || !visited.add(pid)) {
×
179
            return;
×
180
        }
181
        chain.add(parent);
×
182
        collectAncestors(parent, chain, visited);
×
183
    }
×
184

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