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

knowledgepixels / nanodash / 19473636483

18 Nov 2025 04:35PM UTC coverage: 14.513% (+0.2%) from 14.288%
19473636483

push

github

ashleycaselli
ci(deps): update action actions/setup-java to v5.0.0

542 of 4792 branches covered (11.31%)

Branch coverage included in aggregate %.

1437 of 8844 relevant lines covered (16.25%)

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 com.knowledgepixels.nanodash.vocabulary.KPXL_TERMS;
10
import org.eclipse.rdf4j.model.IRI;
11
import org.eclipse.rdf4j.model.Literal;
12
import org.eclipse.rdf4j.model.Statement;
13
import org.eclipse.rdf4j.model.vocabulary.DCTERMS;
14
import org.eclipse.rdf4j.model.vocabulary.RDF;
15
import org.nanopub.Nanopub;
16
import org.slf4j.Logger;
17
import org.slf4j.LoggerFactory;
18

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

24
    private static final Logger logger = LoggerFactory.getLogger(ViewDisplay.class);
×
25

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

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

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

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

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

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

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

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

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

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

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

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

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

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

167
    
168

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