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

knowledgepixels / nanodash / 21595339141

02 Feb 2026 03:05PM UTC coverage: 13.882% (+0.1%) from 13.774%
21595339141

Pull #348

github

web-flow
Merge 65237e603 into 749c79335
Pull Request #348: Implement Nanopubs list/grid as `ResourceView`

551 of 5258 branches covered (10.48%)

Branch coverage included in aggregate %.

1510 of 9589 relevant lines covered (15.75%)

2.06 hits per line

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

0.0
src/main/java/com/knowledgepixels/nanodash/ViewDisplay.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.eclipse.rdf4j.model.Literal;
6
import org.eclipse.rdf4j.model.Statement;
7
import org.eclipse.rdf4j.model.vocabulary.DCTERMS;
8
import org.eclipse.rdf4j.model.vocabulary.RDF;
9
import org.nanopub.Nanopub;
10
import org.slf4j.Logger;
11
import org.slf4j.LoggerFactory;
12

13
import java.io.Serializable;
14
import java.util.HashSet;
15
import java.util.Set;
16

17
/**
18
 * A class representing the display of a resource view associated with a Space.
19
 */
20
public class ViewDisplay implements Serializable, Comparable<ViewDisplay> {
21

22
    private static final Logger logger = LoggerFactory.getLogger(ViewDisplay.class);
×
23

24
    private String id;
25
    private Nanopub nanopub;
26
    private ResourceView view;
27
    private String title;
28
    private Integer pageSize;
29
    private Integer displayWidth;
30
    private String structuralPosition;
31
    private Set<IRI> types = new HashSet<>();
×
32
    private Set<String> appliesTo = new HashSet<>();
×
33
    private Set<IRI> appliesToClasses = new HashSet<>();
×
34
    private Set<IRI> appliesToNamespaces = new HashSet<>();
×
35
    private IRI resource;
36

37
    /**
38
     * Constructor for ViewDisplay with only a ResourceView. This is used for temporary view displays used in profiles as defaults.
39
     *
40
     * @param view the ResourceView associated with this ViewDisplay
41
     */
42
    public ViewDisplay(ResourceView view) {
×
43
        this.id = null;
×
44
        this.nanopub = null;
×
45
        this.view = view;
×
46
    }
×
47

48
    /**
49
     * Get a ResourceView by its ID.
50
     *
51
     * @param id the ID of the ResourceView
52
     * @return the ResourceView object
53
     */
54
    public static ViewDisplay get(String id) throws IllegalArgumentException {
55
        try {
56
            Nanopub np = Utils.getAsNanopub(id.replaceFirst("^(.*[^A-Za-z0-9-_])?(RA[A-Za-z0-9-_]{43})[^A-Za-z0-9-_].*$", "$2"));
×
57
            return new ViewDisplay(id, np);
×
58
        } catch (Exception ex) {
×
59
            logger.error("Couldn't load nanopub for resource: " + id, ex);
×
60
            throw new IllegalArgumentException("invalid view value " + id);
×
61
        }
62
    }
63

64
    /**
65
     * Constructor for ViewDisplay.
66
     *
67
     * @param entry an ApiResponseEntry containing the view and nanopub ID.
68
     */
69
    private ViewDisplay(String id, Nanopub nanopub) {
×
70
        this.id = id;
×
71
        this.nanopub = nanopub;
×
72

73
        boolean viewDisplayTypeFound = false;
×
74
        for (Statement st : nanopub.getAssertion()) {
×
75
            if (st.getSubject().stringValue().equals(id)) {
×
76
                if (st.getPredicate().equals(RDF.TYPE)) {
×
77
                    if (st.getObject().equals(KPXL_TERMS.VIEW_DISPLAY)) {
×
78
                        viewDisplayTypeFound = true;
×
79
                    } else if (st.getObject() instanceof IRI objIri) {
×
80
                        types.add(objIri);
×
81
                    }
82
                } else if (st.getPredicate().equals(DCTERMS.TITLE)) {
×
83
                    title = st.getObject().stringValue();
×
84
                } else if (st.getPredicate().equals(KPXL_TERMS.IS_DISPLAY_OF_VIEW) && st.getObject() instanceof IRI objIri) {
×
85
                    if (view != null) {
×
86
                        throw new IllegalArgumentException("View already set: " + objIri);
×
87
                    }
88
                    view = ResourceView.get(objIri.stringValue());
×
89
                } else if (st.getPredicate().equals(KPXL_TERMS.IS_DISPLAY_FOR) && st.getObject() instanceof IRI objIri) {
×
90
                    if (resource != null) {
×
91
                        throw new IllegalArgumentException("Resource already set: " + objIri);
×
92
                    }
93
                    resource = objIri;
×
94
                } else if (st.getPredicate().equals(KPXL_TERMS.HAS_PAGE_SIZE) && st.getObject() instanceof Literal objL) {
×
95
                    try {
96
                        pageSize = Integer.parseInt(objL.stringValue());
×
97
                    } catch (NumberFormatException ex) {
×
98
                        logger.error("Invalid page size value: " + objL.stringValue(), ex);
×
99
                    }
×
100
                } else if (st.getPredicate().equals(KPXL_TERMS.HAS_DISPLAY_WIDTH) && st.getObject() instanceof IRI objIri) {
×
101
                    displayWidth = ResourceView.columnWidths.get(objIri);
×
102
                } else if (st.getPredicate().equals(KPXL_TERMS.HAS_DISPLAY_WIDTH) && st.getObject() instanceof Literal objL) {
×
103
                    structuralPosition = objL.stringValue();
×
104
                } else if (st.getPredicate().equals(KPXL_TERMS.APPLIES_TO_NAMESPACE) && st.getObject() instanceof IRI objIri) {
×
105
                    appliesToNamespaces.add(objIri);
×
106
                } else if (st.getPredicate().equals(KPXL_TERMS.APPLIES_TO_INSTANCES_OF) && st.getObject() instanceof IRI objIri) {
×
107
                    appliesToClasses.add(objIri);
×
108
                } else if (st.getPredicate().equals(KPXL_TERMS.APPLIES_TO) && st.getObject() instanceof IRI objIri) {
×
109
                    appliesTo.add(objIri.stringValue());
×
110
                }
111
            }
112
        }
×
113
        if (!viewDisplayTypeFound) throw new IllegalArgumentException("Not a proper view display nanopub: " + id);
×
114
        if (view == null) throw new IllegalArgumentException("View not found: " + id);
×
115
    }
×
116

117
    public String getId() {
118
        return id;
×
119
    }
120

121
    public boolean hasType(IRI type) {
122
        return types.contains(type);
×
123
    }
124

125
    /**
126
     * Creates a plain minimal view display without attached view object.
127
     *
128
     * @param pageSize the page size of the view display
129
     */
130
    public ViewDisplay(Integer pageSize) {
×
131
        this.pageSize = pageSize;
×
132
    }
×
133

134
    /**
135
     * Gets the ResourceView associated with this ViewDisplay.
136
     *
137
     * @return the ResourceView
138
     */
139
    public ResourceView getView() {
140
        return view;
×
141
    }
142

143
    public IRI getViewKindIri() {
144
        return view.getViewKindIri();
×
145
    }
146

147
    public boolean appliesTo(String resourceId, Set<IRI> classes) {
148
        if (appliesTo.contains(resourceId)) return true;
×
149
        if (!appliesTo.isEmpty()) return false;
×
150
        if (appliesToNamespaces.isEmpty() && appliesToClasses.isEmpty()) {
×
151
            return view.appliesTo(resourceId, classes);
×
152
        } else {
153
            for (IRI namespace : appliesToNamespaces) {
×
154
                if (resourceId.startsWith(namespace.stringValue())) return true;
×
155
            }
×
156
            if (classes != null) {
×
157
                for (IRI c : classes) {
×
158
                    if (appliesToClasses.contains(c)) return true;
×
159
                }
×
160
            }
161
        }
162
        return false;
×
163
    }
164

165
    public boolean appliesToClasses() {
166
        if (appliesToClasses.isEmpty()) {
×
167
            return view.appliesToClasses();
×
168
        } else {
169
            return true;
×
170
        }
171
    }
172

173
    public boolean appliesToClass(IRI targetClass) {
174
        if (appliesToClasses.isEmpty()) {
×
175
            return view.appliesToClasses();
×
176
        } else {
177
            return appliesToClasses.contains(targetClass);
×
178
        }
179
    }
180

181
    /**
182
     * Gets the nanopub ID associated with this ViewDisplay.
183
     *
184
     * @return the nanopub ID
185
     */
186
    public String getNanopubId() {
187
        if (nanopub == null) return null;
×
188
        return nanopub.getUri().stringValue();
×
189
    }
190

191
    public Integer getPageSize() {
192
        if (pageSize != null) return pageSize;
×
193
        if (view == null) return 10;
×
194
        if (view.getPageSize() != null) return view.getPageSize();
×
195
        return 10;
×
196
    }
197

198
    public Integer getDisplayWidth() {
199
        if (displayWidth != null) return displayWidth;
×
200
        if (view == null) return 12;
×
201
        if (view.getDisplayWidth() != null) return view.getDisplayWidth();
×
202
        return 12;
×
203
    }
204

205
    public String getStructuralPosition() {
206
        if (structuralPosition != null) return structuralPosition;
×
207
        if (view == null) return "5.5.default";
×
208
        if (view.getStructuralPosition() != null) return view.getStructuralPosition();
×
209
        return "5.5.default";
×
210
    }
211

212
    public String getTitle() {
213
        if (title != null) return title;
×
214
        if (view != null) return view.getTitle();
×
215
        return null;
×
216
    }
217

218
    @Override
219
    public int compareTo(ViewDisplay other) {
220
        return this.getStructuralPosition().compareTo(other.getStructuralPosition());
×
221
    }
222

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