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

knowledgepixels / nanodash / 19232563835

10 Nov 2025 01:03PM UTC coverage: 14.137% (+0.2%) from 13.973%
19232563835

push

github

tkuhn
feat(ResourceView): Support for hasPageSize

519 of 4646 branches covered (11.17%)

Branch coverage included in aggregate %.

1354 of 8603 relevant lines covered (15.74%)

0.7 hits per line

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

0.0
src/main/java/com/knowledgepixels/nanodash/ResourceView.java
1
package com.knowledgepixels.nanodash;
2

3
import com.knowledgepixels.nanodash.template.Template;
4
import com.knowledgepixels.nanodash.template.TemplateData;
5
import org.eclipse.rdf4j.model.IRI;
6
import org.eclipse.rdf4j.model.Literal;
7
import org.eclipse.rdf4j.model.Statement;
8
import org.eclipse.rdf4j.model.vocabulary.DCTERMS;
9
import org.eclipse.rdf4j.model.vocabulary.RDF;
10
import org.eclipse.rdf4j.model.vocabulary.RDFS;
11
import org.nanopub.Nanopub;
12
import org.slf4j.Logger;
13
import org.slf4j.LoggerFactory;
14

15
import java.io.Serializable;
16
import java.util.*;
17

18
/**
19
 * A class representing a Resource View.
20
 */
21
public class ResourceView implements Serializable {
22

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

25
    // TODO Move these to some "vocab" location:
26
    public static final IRI RESOURCE_VIEW = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/ResourceView");
×
27

28
    public static final IRI TOP_LEVEL_VIEW_DISPLAY = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/TopLevelViewDisplay");
×
29
    public static final IRI PART_LEVEL_VIEW_DISPLAY = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/PartLevelViewDisplay");
×
30
    public static final IRI HAS_VIEW_QUERY = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/hasViewQuery");
×
31
    public static final IRI HAS_VIEW_QUERY_TARGET_FIELD = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/hasViewQueryTargetField");
×
32
    public static final IRI HAS_VIEW_TARGET_CLASS = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/hasViewTargetClass");
×
33
    public static final IRI HAS_ELEMENT_NAMESPACE = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/hasElementNamespace");
×
34
    public static final IRI HAS_VIEW_ACTION = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/hasViewAction");
×
35
    public static final IRI HAS_ACTION_TEMPLATE = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/hasActionTemplate");
×
36
    public static final IRI HAS_ACTION_TEMPLATE_TARGET_FIELD = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/hasActionTemplateTargetField");
×
37
    public static final IRI TABULAR_VIEW = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/TabularView");
×
38
    public static final IRI LIST_VIEW = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/ListView");
×
39
    public static final IRI HAS_ACTION_TEMPLATE_PART_FIELD = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/hasActionTemplatePartField");
×
40

41
    public static final IRI HAS_PAGE_SIZE = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/hasPageSize");
×
42

43
    public static final IRI VIEW_DISPLAY = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/ViewDisplay");
×
44
    public static final IRI IS_DISPLAY_OF_VIEW = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/isDisplayOfView");
×
45
    public static final IRI IS_DISPLAY_FOR = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/isDisplayFor");
×
46

47
    private static Map<String, ResourceView> resourceViews = new HashMap<>();
×
48

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

67
    private String id;
68
    private Nanopub nanopub;
69
    private String label;
70
    private String title = "View";
×
71
    private GrlcQuery query;
72
    private String queryField = "resource";
×
73
    private Integer pageSize;
74
    private List<IRI> actionList = new ArrayList<>();
×
75
    private Set<IRI> targetClasses = new HashSet<>();
×
76
    private Set<IRI> elementNamespaces = new HashSet<>();
×
77
    private Map<IRI, Template> actionTemplateMap = new HashMap<>();
×
78
    private Map<IRI, String> actionTemplateTargetFieldMap = new HashMap<>();
×
79
    private Map<IRI, String> actionTemplatePartFieldMap = new HashMap<>();
×
80
    private Map<IRI, String> labelMap = new HashMap<>();
×
81
    private IRI viewType;
82

83
    private ResourceView(String id, Nanopub nanopub) {
×
84
        this.id = id;
×
85
        this.nanopub = nanopub;
×
86
        boolean resourceViewTypeFound = false;
×
87
        for (Statement st : nanopub.getAssertion()) {
×
88
            if (st.getSubject().stringValue().equals(id)) {
×
89
                if (st.getPredicate().equals(RDF.TYPE)) {
×
90
                    if (st.getObject().equals(RESOURCE_VIEW)) {
×
91
                        resourceViewTypeFound = true;
×
92
                    }
93
                    if (st.getObject().equals(TABULAR_VIEW) || st.getObject().equals(LIST_VIEW)) {
×
94
                        viewType = (IRI) st.getObject();
×
95
                    }
96
                } else if (st.getPredicate().equals(RDFS.LABEL)) {
×
97
                    label = st.getObject().stringValue();
×
98
                } else if (st.getPredicate().equals(DCTERMS.TITLE)) {
×
99
                    title = st.getObject().stringValue();
×
100
                } else if (st.getPredicate().equals(HAS_VIEW_QUERY)) {
×
101
                    query = GrlcQuery.get(st.getObject().stringValue());
×
102
                } else if (st.getPredicate().equals(HAS_VIEW_QUERY_TARGET_FIELD)) {
×
103
                    queryField = st.getObject().stringValue();
×
104
                } else if (st.getPredicate().equals(HAS_VIEW_ACTION) && st.getObject() instanceof IRI objIri) {
×
105
                    actionList.add(objIri);
×
106
                } else if (st.getPredicate().equals(HAS_ELEMENT_NAMESPACE) && st.getObject() instanceof IRI objIri) {
×
107
                    elementNamespaces.add(objIri);
×
108
                } else if (st.getPredicate().equals(HAS_VIEW_TARGET_CLASS) && st.getObject() instanceof IRI objIri) {
×
109
                    targetClasses.add(objIri);
×
110
                } else if (st.getPredicate().equals(HAS_PAGE_SIZE) && st.getObject() instanceof Literal objL) {
×
111
                    try {
112
                        pageSize = Integer.parseInt(objL.stringValue());
×
113
                    } catch (NumberFormatException ex) {
×
114
                        logger.error("Invalid page size value: " + objL.stringValue(), ex);
×
115
                    }
×
116
                }
117
            } else if (st.getPredicate().equals(HAS_ACTION_TEMPLATE)) {
×
118
                Template template = TemplateData.get().getTemplate(st.getObject().stringValue());
×
119
                actionTemplateMap.put((IRI) st.getSubject(), template);
×
120
            } else if (st.getPredicate().equals(HAS_ACTION_TEMPLATE_TARGET_FIELD)) {
×
121
                actionTemplateTargetFieldMap.put((IRI) st.getSubject(), st.getObject().stringValue());
×
122
            } else if (st.getPredicate().equals(HAS_ACTION_TEMPLATE_PART_FIELD)) {
×
123
                actionTemplatePartFieldMap.put((IRI) st.getSubject(), st.getObject().stringValue());
×
124
            } else if (st.getPredicate().equals(RDFS.LABEL)) {
×
125
                labelMap.put((IRI) st.getSubject(), st.getObject().stringValue());
×
126
            }
127
        }
×
128
        if (!resourceViewTypeFound) throw new IllegalArgumentException("Not a proper resource view nanopub: " + id);
×
129
        if (query == null) throw new IllegalArgumentException("Query not found: " + id);
×
130
    }
×
131

132
    /**
133
     * Gets the ID of the ResourceView.
134
     *
135
     * @return the ID of the ResourceView
136
     */
137
    public String getId() {
138
        return id;
×
139
    }
140

141
    /**
142
     * Gets the Nanopub defining this ResourceView.
143
     *
144
     * @return the Nanopub defining this ResourceView
145
     */
146
    public Nanopub getNanopub() {
147
        return nanopub;
×
148
    }
149

150
    /**
151
     * Gets the label of the ResourceView.
152
     *
153
     * @return the label of the ResourceView
154
     */
155
    public String getLabel() {
156
        return label;
×
157
    }
158

159
    /**
160
     * Gets the title of the ResourceView.
161
     *
162
     * @return the title of the ResourceView
163
     */
164
    public String getTitle() {
165
        return title;
×
166
    }
167

168
    /**
169
     * Gets the GrlcQuery associated with the ResourceView.
170
     *
171
     * @return the GrlcQuery associated with the ResourceView
172
     */
173
    public GrlcQuery getQuery() {
174
        return query;
×
175
    }
176

177
    /**
178
     * Gets the query field of the ResourceView.
179
     *
180
     * @return the query field
181
     */
182
    public String getQueryField() {
183
        return queryField;
×
184
    }
185

186
    /**
187
     * Returns the preferred page size.
188
     *
189
     * @return page size (0 = everything on first page)
190
     */
191
    public Integer getPageSize() {
192
        return pageSize;
×
193
    }
194

195
    /**
196
     * Gets the list of action IRIs associated with the ResourceView.
197
     *
198
     * @return the list of action IRIs
199
     */
200
    public List<IRI> getActionList() {
201
        return actionList;
×
202
    }
203

204
    /**
205
     * Gets the Template for a given action IRI.
206
     *
207
     * @param actionIri the action IRI
208
     * @return the Template for the action IRI
209
     */
210
    public Template getTemplateForAction(IRI actionIri) {
211
        return actionTemplateMap.get(actionIri);
×
212
    }
213

214
    /**
215
     * Gets the template field for a given action IRI.
216
     *
217
     * @param actionIri the action IRI
218
     * @return the template field for the action IRI
219
     */
220
    public String getTemplateTargetFieldForAction(IRI actionIri) {
221
        return actionTemplateTargetFieldMap.get(actionIri);
×
222
    }
223

224
    public String getTemplatePartFieldForAction(IRI actionIri) {
225
        return actionTemplatePartFieldMap.get(actionIri);
×
226
    }
227

228
    /**
229
     * Gets the label for a given action IRI.
230
     *
231
     * @param actionIri the action IRI
232
     * @return the label for the action IRI
233
     */
234
    public String getLabelForAction(IRI actionIri) {
235
        return labelMap.get(actionIri);
×
236
    }
237

238
    public boolean coversElement(String elementId) {
239
        for (IRI namespace : elementNamespaces) {
×
240
            if (elementId.startsWith(namespace.stringValue())) return true;
×
241
        }
×
242
        return false;
×
243
    }
244

245
    /**
246
     * Checks if the ResourceView has target classes.
247
     *
248
     * @return true if the ResourceView has target classes, false otherwise
249
     */
250
    public boolean hasTargetClasses() {
251
        return !targetClasses.isEmpty();
×
252
    }
253

254
    /**
255
     * Checks if the ResourceView has a specific target class.
256
     *
257
     * @param targetClass the target class IRI
258
     * @return true if the ResourceView has the target class, false otherwise
259
     */
260
    public boolean hasTargetClass(IRI targetClass) {
261
        return targetClasses.contains(targetClass);
×
262
    }
263

264
    @Override
265
    public String toString() {
266
        return id;
×
267
    }
268

269
    /**
270
     * Gets the view type of the ResourceView.
271
     *
272
     * @return the view type mode IRI
273
     */
274
    public IRI getViewType() {
275
        return viewType;
×
276
    }
277

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