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

knowledgepixels / nanodash / 21518138890

30 Jan 2026 01:52PM UTC coverage: 14.072% (-0.2%) from 14.235%
21518138890

push

github

tkuhn
fix: Only local default values in repeated statements get numbers

543 of 5100 branches covered (10.65%)

Branch coverage included in aggregate %.

1489 of 9340 relevant lines covered (15.94%)

2.11 hits per line

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

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

3
import java.io.Serializable;
4
import java.util.ArrayList;
5
import java.util.Collections;
6
import java.util.HashMap;
7
import java.util.HashSet;
8
import java.util.List;
9
import java.util.Map;
10
import java.util.Set;
11

12
import org.eclipse.rdf4j.model.IRI;
13
import org.nanopub.Nanopub;
14
import org.nanopub.extra.services.ApiResponseEntry;
15
import org.nanopub.extra.services.QueryRef;
16
import org.slf4j.Logger;
17
import org.slf4j.LoggerFactory;
18

19
import com.knowledgepixels.nanodash.vocabulary.KPXL_TERMS;
20

21
public abstract class ProfiledResource implements Serializable {
22

23
    private static final Logger logger = LoggerFactory.getLogger(ProfiledResource.class);
9✔
24

25
    protected static class ResourceData implements Serializable {
6✔
26
        List<ViewDisplay> viewDisplays = new ArrayList<>();
18✔
27
    }
28

29
    private static Map<String,ProfiledResource> instances = new HashMap<>();
15✔
30

31
    public static void refresh() {
32
        for (ProfiledResource r : instances.values()) {
×
33
            r.setDataNeedsUpdate();
×
34
        }
×
35
    }
×
36

37
    public static void forceRefresh(String id, long waitMillis) {
38
        if (isProfiledResource(id)) {
×
39
            instances.get(id).forceRefresh(waitMillis);
×
40
        }
41
    }
×
42

43
    public static boolean isProfiledResource(String id) {
44
        return instances.containsKey(id);
×
45
    }
46

47
    public static ProfiledResource get(String id) {
48
        return instances.get(id);
×
49
    }
50

51
    private String id;
52
    private Space space;
53
    private ResourceData data = new ResourceData();
15✔
54
    private boolean dataInitialized = false;
9✔
55
    private boolean dataNeedsUpdate = true;
9✔
56
    private Long runUpdateAfter = null;
9✔
57

58
    protected ProfiledResource(String id) {
6✔
59
        this.id = id;
9✔
60
        instances.put(id, this);
15✔
61
    }
3✔
62

63
    protected void initSpace(Space space) {
64
        this.space = space;
9✔
65
    }
3✔
66

67
    public String getId() {
68
        return id;
9✔
69
    }
70

71
    public synchronized Thread triggerDataUpdate() {
72
        if (dataNeedsUpdate) {
×
73
            Thread thread = new Thread(() -> {
×
74
                try {
75
                    if (runUpdateAfter != null) {
×
76
                        while (System.currentTimeMillis() < runUpdateAfter) {
×
77
                            Thread.sleep(100);
×
78
                        }
79
                        runUpdateAfter = null;
×
80
                    }
81

82
                    ResourceData newData = new ResourceData();
×
83

84
                    for (ApiResponseEntry r : ApiCache.retrieveResponseSync(new QueryRef("get-view-displays", "resource", id), true).getData()) {
×
85
                        if (space != null && !space.isAdminPubkey(r.get("pubkey"))) continue;
×
86
                        try {
87
                            newData.viewDisplays.add(ViewDisplay.get(r.get("display")));
×
88
                        } catch (IllegalArgumentException ex) {
×
89
                            logger.error("Couldn't generate view display object", ex);
×
90
                        }
×
91
                    }
×
92
                    data = newData;
×
93
                    dataInitialized = true;
×
94
                } catch (Exception ex) {
×
95
                    logger.error("Error while trying to update space data: {}", ex);
×
96
                    dataNeedsUpdate = true;
×
97
                }
×
98
            });
×
99
            thread.start();
×
100
            dataNeedsUpdate = false;
×
101
            return thread;
×
102
        }
103
        return null;
×
104
    }
105

106
    public void forceRefresh(long waitMillis) {
107
        dataNeedsUpdate = true;
×
108
        dataInitialized = false;
×
109
        runUpdateAfter = System.currentTimeMillis() + waitMillis;
×
110
    }
×
111

112
    public Long getRunUpdateAfter() {
113
        return runUpdateAfter;
×
114
    }
115

116
    public Space getSpace() {
117
        return space;
×
118
    }
119

120
    public String getNanopubId() {
121
        return null;
×
122
    }
123

124
    public Nanopub getNanopub() {
125
        return null;
×
126
    }
127

128
    public String getNamespace() {
129
        return null;
×
130
    }
131

132
    public void setDataNeedsUpdate() {
133
        dataNeedsUpdate = true;
9✔
134
    }
3✔
135

136
    public boolean isDataInitialized() {
137
        triggerDataUpdate();
×
138
        return dataInitialized;
×
139
    }
140

141
    public List<ViewDisplay> getViewDisplays() {
142
        return data.viewDisplays;
×
143
    }
144

145
    public List<ViewDisplay> getTopLevelViewDisplays() {
146
        return getViewDisplays(true, getId(), null);
×
147
    }
148

149
    public List<ViewDisplay> getPartLevelViewDisplays(String resourceId, Set<IRI> classes) {
150
        return getViewDisplays(false, resourceId, classes);
×
151
    }
152

153
    private List<ViewDisplay> getViewDisplays(boolean toplevel, String resourceId, Set<IRI> classes) {
154
        triggerDataUpdate();
×
155
        List<ViewDisplay> viewDisplays = new ArrayList<>();
×
156
        Set<IRI> viewKinds = new HashSet<>();
×
157

158
        for (ViewDisplay vd : getViewDisplays()) {
×
159
            IRI kind = vd.getViewKindIri();
×
160
            if (kind != null) {
×
161
                if (viewKinds.contains(kind)) continue;
×
162
                viewKinds.add(vd.getViewKindIri());
×
163
            }
164
            if (vd.hasType(KPXL_TERMS.DEACTIVATED_VIEW_DISPLAY)) continue;
×
165

166
            if (!toplevel && vd.hasType(KPXL_TERMS.TOP_LEVEL_VIEW_DISPLAY)) {
×
167
                // Deprecated
168
                // do nothing
169
            } else if (vd.appliesTo(resourceId, classes)) {
×
170
                viewDisplays.add(vd);
×
171
            } else if (toplevel && vd.hasType(KPXL_TERMS.TOP_LEVEL_VIEW_DISPLAY)) {
×
172
                // Deprecated
173
                viewDisplays.add(vd);
×
174
            }
175
        }
×
176

177
        Collections.sort(viewDisplays);
×
178
        return viewDisplays;
×
179
    }
180

181
    public abstract String getLabel();
182

183
    @Override
184
    public String toString() {
185
        return id;
×
186
    }
187

188
    /**
189
     * Gets the chain of superspaces from the current space up to the root space.
190
     *
191
     * @return the list of superspaces from the given space to the root space
192
     */
193
    public List<ProfiledResource> getAllSuperSpacesUntilRoot() {
194
        List<ProfiledResource> chain = new ArrayList<>();
×
195
        Set<String> visited = new HashSet<>();
×
196
        collectAncestors(space, chain, visited);
×
197
        Collections.reverse(chain);
×
198
        return chain;
×
199
    }
200

201
    private void collectAncestors(Space current, List<ProfiledResource> chain, Set<String> visited) {
202
        if (current == null) {
×
203
            return;
×
204
        }
205
        List<Space> parents = current.getSuperspaces();
×
206
        if (parents == null || parents.isEmpty()) {
×
207
            return;
×
208
        }
209
        Space parent = parents.getFirst();
×
210
        if (parent == null) {
×
211
            return;
×
212
        }
213
        String pid = parent.getId();
×
214
        if (pid == null || !visited.add(pid)) {
×
215
            return;
×
216
        }
217
        chain.add(parent);
×
218
        collectAncestors(parent, chain, visited);
×
219
    }
×
220

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