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

knowledgepixels / nanodash / 19235243637

10 Nov 2025 02:36PM UTC coverage: 13.754% (-0.6%) from 14.373%
19235243637

push

github

tkuhn
feat(ViewDisplay): Support for specifying width and structural position

514 of 4708 branches covered (10.92%)

Branch coverage included in aggregate %.

1329 of 8692 relevant lines covered (15.29%)

0.68 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, Comparable<ViewDisplay> {
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 Integer displayWidth;
31
    private String structuralPosition;
32
    private Set<IRI> types = new HashSet<>();
×
33
    private IRI resource;
34

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

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

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

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

102
    public String getId() {
103
        return id;
×
104
    }
105

106
    /**
107
     * Creates a plain minimal view display without attached view object.
108
     *
109
     * @param pageSize the page size of the view display
110
     */
111
    public ViewDisplay(Integer pageSize) {
×
112
        this.pageSize = pageSize;
×
113
    }
×
114

115
    /**
116
     * Gets the ResourceView associated with this ViewDisplay.
117
     *
118
     * @return the ResourceView
119
     */
120
    public ResourceView getView() {
121
        return view;
×
122
    }
123

124
    /**
125
     * Gets the nanopub ID associated with this ViewDisplay.
126
     *
127
     * @return the nanopub ID
128
     */
129
    public String getNanopubId() {
130
        return nanopub.getUri().stringValue();
×
131
    }
132

133
    public Integer getPageSize() {
134
        if (pageSize != null) return pageSize;
×
135
        if (view == null) return 10;
×
136
        if (view.getPageSize() != null) return view.getPageSize();
×
137
        return 10;
×
138
    }
139

140
    public Integer getDisplayWidth() {
141
        if (displayWidth != null) return displayWidth;
×
142
        if (view == null) return 12;
×
143
        if (view.getDisplayWidth() != null) return view.getDisplayWidth();
×
144
        return 12;
×
145
    }
146

147
    public String getStructuralPosition() {
148
        if (structuralPosition != null) return structuralPosition;
×
149
        if (view == null) return "5.5.default";
×
150
        if (view.getStructuralPosition() != null) return view.getStructuralPosition();
×
151
        return "5.5.default";
×
152
    }
153

154
    public String getTitle() {
155
        if (title != null) return title;
×
156
        if (view != null) return view.getTitle();
×
157
        return null;
×
158
    }
159

160
    @Override
161
    public int compareTo(ViewDisplay other) {
162
        return this.getStructuralPosition().compareTo(other.getStructuralPosition());
×
163
    }
164

165
    
166

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