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

knowledgepixels / nanodash / 19818701198

01 Dec 2025 10:02AM UTC coverage: 13.36% (-0.5%) from 13.901%
19818701198

push

github

tkuhn
feat(ResourceView): Automatically apply latest version of views

503 of 4898 branches covered (10.27%)

Branch coverage included in aggregate %.

1347 of 8949 relevant lines covered (15.05%)

0.67 hits per line

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

13.68
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.HashSet;
7
import java.util.List;
8
import java.util.Set;
9

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

17
import com.knowledgepixels.nanodash.vocabulary.KPXL_TERMS;
18

19
public class ProfiledResource implements Serializable {
20

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

23
    protected static class ResourceData implements Serializable {
2✔
24
        List<ViewDisplay> viewDisplays = new ArrayList<>();
6✔
25
    }
26

27
    private String id;
28
    private Space space;
29
    private ResourceData data = new ResourceData();
5✔
30
    private boolean dataInitialized = false;
3✔
31
    private boolean dataNeedsUpdate = true;
3✔
32
    private Long runUpdateAfter = null;
3✔
33

34
    protected ProfiledResource(String id) {
2✔
35
        this.id = id;
3✔
36
    }
1✔
37

38
    protected void initSpace(Space space) {
39
        this.space = space;
3✔
40
    }
1✔
41

42
    public String getId() {
43
        return id;
3✔
44
    }
45

46
    protected synchronized Thread triggerDataUpdate() {
47
        if (dataNeedsUpdate) {
×
48
            Thread thread = new Thread(() -> {
×
49
                try {
50
                    if (runUpdateAfter != null) {
×
51
                        while (System.currentTimeMillis() < runUpdateAfter) {
×
52
                            Thread.sleep(100);
×
53
                        }
54
                        runUpdateAfter = null;
×
55
                    }
56

57
                    ResourceData newData = new ResourceData();
×
58

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

81
    public void forceRefresh(long waitMillis) {
82
        dataNeedsUpdate = true;
×
83
        dataInitialized = false;
×
84
        runUpdateAfter = System.currentTimeMillis() + waitMillis;
×
85
    }
×
86

87
    public Long getRunUpdateAfter() {
88
        return runUpdateAfter;
×
89
    }
90

91
    public Space getSpace() {
92
        return space;
×
93
    }
94

95
    public String getNanopubId() {
96
        return null;
×
97
    }
98

99
    public Nanopub getNanopub() {
100
        return null;
×
101
    }
102
    public String getNamespace() {
103
        return null;
×
104
    }
105

106
    public void setDataNeedsUpdate() {
107
        dataNeedsUpdate = true;
×
108
    }
×
109

110
    public boolean isDataInitialized() {
111
        triggerDataUpdate();
×
112
        return dataInitialized;
×
113
    }
114

115
    public List<ViewDisplay> getViewDisplays() {
116
        return data.viewDisplays;
×
117
    }
118

119
    public List<ViewDisplay> getViewDisplays(boolean toplevel, Set<IRI> classes) {
120
        triggerDataUpdate();
×
121
        List<ViewDisplay> viewDisplays = new ArrayList<>();
×
122
        Set<IRI> viewKinds = new HashSet<>();
×
123

124
        for (ViewDisplay vd : getViewDisplays()) {
×
125
            IRI kind = vd.getViewKindIri();
×
126
            if (kind != null) {
×
127
                if (viewKinds.contains(kind)) continue;
×
128
                viewKinds.add(vd.getViewKindIri());
×
129
            }
130
            if (vd.hasType(KPXL_TERMS.DEACTIVATED_VIEW_DISPLAY)) continue;
×
131

132
            if (vd.appliesTo(getId(), null)) {
×
133
                viewDisplays.add(vd);
×
134
            } else if (toplevel && vd.hasType(KPXL_TERMS.TOP_LEVEL_VIEW_DISPLAY)) {
×
135
                // Deprecated
136
                viewDisplays.add(vd);
×
137
            }
138
        }
×
139

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

144
    @Override
145
    public String toString() {
146
        return id;
×
147
    }
148

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