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

knowledgepixels / nanodash / 19233335143

10 Nov 2025 01:31PM UTC coverage: 14.373% (+0.2%) from 14.137%
19233335143

push

github

tkuhn
feat(ViewDisplay): Allow pageSize to be overridden; refactoring

537 of 4678 branches covered (11.48%)

Branch coverage included in aggregate %.

1377 of 8639 relevant lines covered (15.94%)

0.72 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 java.io.Serializable;
4
import java.util.HashMap;
5
import java.util.HashSet;
6
import java.util.Map;
7
import java.util.Set;
8

9
import org.eclipse.rdf4j.model.IRI;
10
import org.eclipse.rdf4j.model.Literal;
11
import org.eclipse.rdf4j.model.Statement;
12
import org.eclipse.rdf4j.model.vocabulary.DCTERMS;
13
import org.eclipse.rdf4j.model.vocabulary.RDF;
14
import org.nanopub.Nanopub;
15
import org.slf4j.Logger;
16
import org.slf4j.LoggerFactory;
17

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

23
    private static final Logger logger = LoggerFactory.getLogger(ResourceView.class);
×
24

25
    private String id;
26
    private Nanopub nanopub;
27
    private ResourceView view;
28
    private String title;
29
    private Integer pageSize;
30
    private Set<IRI> types = new HashSet<>();
×
31
    private IRI resource;
32

33
    private static Map<String, ViewDisplay> viewDisplays = new HashMap<>();
×
34

35
    /**
36
     * Get a ResourceView by its ID.
37
     *
38
     * @param id the ID of the ResourceView
39
     * @return the ResourceView object
40
     */
41
    public static ViewDisplay get(String id) {
42
        if (!viewDisplays.containsKey(id)) {
×
43
            try {
44
                Nanopub np = Utils.getAsNanopub(id.replaceFirst("^(.*[^A-Za-z0-9-_])?(RA[A-Za-z0-9-_]{43})[^A-Za-z0-9-_].*$", "$2"));
×
45
                viewDisplays.put(id, new ViewDisplay(id, np));
×
46
            } catch (Exception ex) {
×
47
                logger.error("Couldn't load nanopub for resource: " + id, ex);
×
48
            }
×
49
        }
50
        return viewDisplays.get(id);
×
51
    }
52

53
    /**
54
     * Constructor for ViewDisplay.
55
     *
56
     * @param entry an ApiResponseEntry containing the view and nanopub ID.
57
     */
58
    private ViewDisplay(String id, Nanopub nanopub) {
×
59
        this.id = id;
×
60
        this.nanopub = nanopub;
×
61

62
        boolean viewDisplayTypeFound = false;
×
63
        for (Statement st : nanopub.getAssertion()) {
×
64
            if (st.getSubject().stringValue().equals(id)) {
×
65
                if (st.getPredicate().equals(RDF.TYPE)) {
×
66
                    if (st.getObject().equals(ResourceView.VIEW_DISPLAY)) {
×
67
                        viewDisplayTypeFound = true;
×
68
                    } else if (st.getObject() instanceof IRI objIri) {
×
69
                        types.add(objIri);
×
70
                    }
71
                } else if (st.getPredicate().equals(DCTERMS.TITLE)) {
×
72
                    title = st.getObject().stringValue();
×
73
                } else if (st.getPredicate().equals(ResourceView.IS_DISPLAY_OF_VIEW) && st.getObject() instanceof IRI objIri) {
×
74
                    if (view != null) {
×
75
                        throw new IllegalArgumentException("View already set: " + objIri);
×
76
                    }
77
                    view = ResourceView.get(objIri.stringValue());
×
78
                } else if (st.getPredicate().equals(ResourceView.IS_DISPLAY_FOR) && st.getObject() instanceof IRI objIri) {
×
79
                    if (resource != null) {
×
80
                        throw new IllegalArgumentException("Resource already set: " + objIri);
×
81
                    }
82
                    resource = objIri;
×
83
                } else if (st.getPredicate().equals(ResourceView.HAS_PAGE_SIZE) && st.getObject() instanceof Literal objL) {
×
84
                    try {
85
                        pageSize = Integer.parseInt(objL.stringValue());
×
86
                    } catch (NumberFormatException ex) {
×
87
                        logger.error("Invalid page size value: " + objL.stringValue(), ex);
×
88
                    }
×
89
                }
90
            }
91
        }
×
92
        if (!viewDisplayTypeFound) throw new IllegalArgumentException("Not a proper view display nanopub: " + id);
×
93
        if (view == null) throw new IllegalArgumentException("View not found: " + id);
×
94
    }
×
95

96
    public String getId() {
97
        return id;
×
98
    }
99

100
    /**
101
     * Creates a plain minimal view display without attached view object.
102
     *
103
     * @param pageSize the page size of the view display
104
     */
105
    public ViewDisplay(Integer pageSize) {
×
106
        this.pageSize = pageSize;
×
107
    }
×
108

109
    /**
110
     * Gets the ResourceView associated with this ViewDisplay.
111
     *
112
     * @return the ResourceView
113
     */
114
    public ResourceView getView() {
115
        return view;
×
116
    }
117

118
    /**
119
     * Gets the nanopub ID associated with this ViewDisplay.
120
     *
121
     * @return the nanopub ID
122
     */
123
    public String getNanopubId() {
124
        return nanopub.getUri().stringValue();
×
125
    }
126

127
    public Integer getPageSize() {
128
        if (pageSize != null) return pageSize;
×
129
        if (view.getPageSize() != null) return view.getPageSize();
×
130
        return 10;
×
131
    }
132

133
    public String getTitle() {
134
        if (title != null) return title;
×
135
        if (view != null) return view.getTitle();
×
136
        return null;
×
137
    }
138

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