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

knowledgepixels / nanodash / 23046278881

13 Mar 2026 10:15AM UTC coverage: 15.676% (-0.06%) from 15.734%
23046278881

push

github

web-flow
Merge pull request #388 from knowledgepixels/387-improve-user-page-buttons

Improve user page buttons (#387)

710 of 5489 branches covered (12.93%)

Branch coverage included in aggregate %.

1751 of 10210 relevant lines covered (17.15%)

2.35 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 View view;
27
    private IRI viewIri;
28
    private String title;
29
    private Integer pageSize;
30
    private Integer displayWidth;
31
    private String structuralPosition;
32
    private Set<IRI> types = new HashSet<>();
×
33
    private Set<String> appliesTo = new HashSet<>();
×
34
    private Set<IRI> appliesToClasses = new HashSet<>();
×
35
    private Set<IRI> appliesToNamespaces = new HashSet<>();
×
36
    private IRI resource;
37

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

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

65
    /**
66
     * Constructor for ViewDisplay.
67
     *
68
     * @param id      the ID of the ViewDisplay
69
     * @param nanopub the Nanopub containing the data for this ViewDisplay
70
     */
71
    private ViewDisplay(String id, Nanopub nanopub) {
×
72
        this.id = id;
×
73
        this.nanopub = nanopub;
×
74

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

121
    public String getId() {
122
        return id;
×
123
    }
124

125
    public boolean hasType(IRI type) {
126
        return types.contains(type);
×
127
    }
128

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

138
    /**
139
     * Gets the View associated with this ViewDisplay.
140
     *
141
     * @return the View
142
     */
143
    public View getView() {
144
        return view;
×
145
    }
146

147
    public IRI getViewIri() {
148
        return viewIri;
×
149
    }
150

151
    public IRI getViewKindIri() {
152
        IRI kind = view.getViewKindIri();
×
153
        if (kind != null) return kind;
×
154
        return viewIri;
×
155
    }
156

157
    public boolean appliesTo(String resourceId, Set<IRI> classes) {
158
        if (appliesTo.contains(resourceId)) return true;
×
159
        if (!appliesTo.isEmpty()) return false;
×
160
        if (appliesToNamespaces.isEmpty() && appliesToClasses.isEmpty()) {
×
161
            return view.appliesTo(resourceId, classes);
×
162
        } else {
163
            for (IRI namespace : appliesToNamespaces) {
×
164
                if (resourceId.startsWith(namespace.stringValue())) return true;
×
165
            }
×
166
            if (classes != null) {
×
167
                for (IRI c : classes) {
×
168
                    if (appliesToClasses.contains(c)) return true;
×
169
                }
×
170
            }
171
        }
172
        return false;
×
173
    }
174

175
    public boolean appliesToClasses() {
176
        if (appliesToClasses.isEmpty()) {
×
177
            return view.appliesToClasses();
×
178
        } else {
179
            return true;
×
180
        }
181
    }
182

183
    public boolean appliesToClass(IRI targetClass) {
184
        if (appliesToClasses.isEmpty()) {
×
185
            return view.appliesToClasses();
×
186
        } else {
187
            return appliesToClasses.contains(targetClass);
×
188
        }
189
    }
190

191
    /**
192
     * Gets the nanopub ID associated with this ViewDisplay
193
     *
194
     * @return the nanopub ID
195
     */
196
    public IRI getNanopubId() {
197
        if (nanopub == null) {
×
198
            return null;
×
199
        }
200
        return nanopub.getUri();
×
201
    }
202

203
    /**
204
     * Gets the nanopub associated with this ViewDisplay
205
     *
206
     * @return the nanopub, or null if not available
207
     */
208
    public Nanopub getNanopub() {
209
        return nanopub;
×
210
    }
211

212
    public Integer getPageSize() {
213
        if (pageSize != null) return pageSize;
×
214
        if (view == null) return 10;
×
215
        if (view.getPageSize() != null) return view.getPageSize();
×
216
        return 10;
×
217
    }
218

219
    public Integer getDisplayWidth() {
220
        if (displayWidth != null) return displayWidth;
×
221
        if (view == null) return 12;
×
222
        if (view.getDisplayWidth() != null) return view.getDisplayWidth();
×
223
        return 12;
×
224
    }
225

226
    public String getStructuralPosition() {
227
        if (structuralPosition != null) return structuralPosition;
×
228
        if (view == null) return "5.5.default";
×
229
        if (view.getStructuralPosition() != null) return view.getStructuralPosition();
×
230
        return "5.5.default";
×
231
    }
232

233
    public String getTitle() {
234
        if (title != null) return title;
×
235
        if (view != null) return view.getTitle();
×
236
        return null;
×
237
    }
238

239
    @Override
240
    public int compareTo(ViewDisplay other) {
241
        return this.getStructuralPosition().compareTo(other.getStructuralPosition());
×
242
    }
243

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