• 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/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
    public static final IRI HAS_STRUCTURAL_POSITION = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/hasStructuralPosition");
×
43

44
    public static final IRI HAS_DISPLAY_WIDTH = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/hasDisplayWidth");
×
45
    public static final IRI COLUMN_WIDTH_1_OF_12 = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/ColumnWidth01of12");
×
46
    public static final IRI COLUMN_WIDTH_2_OF_12 = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/ColumnWidth02of12");
×
47
    public static final IRI COLUMN_WIDTH_3_OF_12 = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/ColumnWidth03of12");
×
48
    public static final IRI COLUMN_WIDTH_4_OF_12 = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/ColumnWidth04of12");
×
49
    public static final IRI COLUMN_WIDTH_5_OF_12 = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/ColumnWidth05of12");
×
50
    public static final IRI COLUMN_WIDTH_6_OF_12 = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/ColumnWidth06of12");
×
51
    public static final IRI COLUMN_WIDTH_7_OF_12 = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/ColumnWidth07of12");
×
52
    public static final IRI COLUMN_WIDTH_8_OF_12 = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/ColumnWidth08of12");
×
53
    public static final IRI COLUMN_WIDTH_9_OF_12 = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/ColumnWidth09of12");
×
54
    public static final IRI COLUMN_WIDTH_10_OF_12 = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/ColumnWidth10of12");
×
55
    public static final IRI COLUMN_WIDTH_11_OF_12 = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/ColumnWidth11of12");
×
56
    public static final IRI COLUMN_WIDTH_12_OF_12 = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/ColumnWidth12of12");
×
57
    static Map<IRI,Integer> columnWidths = new HashMap<>();
×
58
    static {
59
        columnWidths.put(COLUMN_WIDTH_1_OF_12, 1);
×
60
        columnWidths.put(COLUMN_WIDTH_2_OF_12, 2);
×
61
        columnWidths.put(COLUMN_WIDTH_3_OF_12, 3);
×
62
        columnWidths.put(COLUMN_WIDTH_4_OF_12, 4);
×
63
        columnWidths.put(COLUMN_WIDTH_5_OF_12, 5);
×
64
        columnWidths.put(COLUMN_WIDTH_6_OF_12, 6);
×
65
        columnWidths.put(COLUMN_WIDTH_7_OF_12, 7);
×
66
        columnWidths.put(COLUMN_WIDTH_8_OF_12, 8);
×
67
        columnWidths.put(COLUMN_WIDTH_9_OF_12, 9);
×
68
        columnWidths.put(COLUMN_WIDTH_10_OF_12, 10);
×
69
        columnWidths.put(COLUMN_WIDTH_11_OF_12, 11);
×
70
        columnWidths.put(COLUMN_WIDTH_12_OF_12, 12);
×
71
    }
72

73
    public static final IRI VIEW_DISPLAY = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/ViewDisplay");
×
74
    public static final IRI IS_DISPLAY_OF_VIEW = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/isDisplayOfView");
×
75
    public static final IRI IS_DISPLAY_FOR = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/isDisplayFor");
×
76

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

79
    /**
80
     * Get a ResourceView by its ID.
81
     *
82
     * @param id the ID of the ResourceView
83
     * @return the ResourceView object
84
     */
85
    public static ResourceView get(String id) {
86
        if (!resourceViews.containsKey(id)) {
×
87
            try {
88
                Nanopub np = Utils.getAsNanopub(id.replaceFirst("^(.*[^A-Za-z0-9-_])?(RA[A-Za-z0-9-_]{43})[^A-Za-z0-9-_].*$", "$2"));
×
89
                resourceViews.put(id, new ResourceView(id, np));
×
90
            } catch (Exception ex) {
×
91
                logger.error("Couldn't load nanopub for resource: " + id, ex);
×
92
            }
×
93
        }
94
        return resourceViews.get(id);
×
95
    }
96

97
    private String id;
98
    private Nanopub nanopub;
99
    private String label;
100
    private String title = "View";
×
101
    private GrlcQuery query;
102
    private String queryField = "resource";
×
103
    private Integer pageSize;
104
    private Integer displayWidth;
105
    private String structuralPosition;
106
    private List<IRI> actionList = new ArrayList<>();
×
107
    private Set<IRI> targetClasses = new HashSet<>();
×
108
    private Set<IRI> elementNamespaces = new HashSet<>();
×
109
    private Map<IRI, Template> actionTemplateMap = new HashMap<>();
×
110
    private Map<IRI, String> actionTemplateTargetFieldMap = new HashMap<>();
×
111
    private Map<IRI, String> actionTemplatePartFieldMap = new HashMap<>();
×
112
    private Map<IRI, String> labelMap = new HashMap<>();
×
113
    private IRI viewType;
114

115
    private ResourceView(String id, Nanopub nanopub) {
×
116
        this.id = id;
×
117
        this.nanopub = nanopub;
×
118
        boolean resourceViewTypeFound = false;
×
119
        for (Statement st : nanopub.getAssertion()) {
×
120
            if (st.getSubject().stringValue().equals(id)) {
×
121
                if (st.getPredicate().equals(RDF.TYPE)) {
×
122
                    if (st.getObject().equals(RESOURCE_VIEW)) {
×
123
                        resourceViewTypeFound = true;
×
124
                    }
125
                    if (st.getObject().equals(TABULAR_VIEW) || st.getObject().equals(LIST_VIEW)) {
×
126
                        viewType = (IRI) st.getObject();
×
127
                    }
128
                } else if (st.getPredicate().equals(RDFS.LABEL)) {
×
129
                    label = st.getObject().stringValue();
×
130
                } else if (st.getPredicate().equals(DCTERMS.TITLE)) {
×
131
                    title = st.getObject().stringValue();
×
132
                } else if (st.getPredicate().equals(HAS_VIEW_QUERY)) {
×
133
                    query = GrlcQuery.get(st.getObject().stringValue());
×
134
                } else if (st.getPredicate().equals(HAS_VIEW_QUERY_TARGET_FIELD)) {
×
135
                    queryField = st.getObject().stringValue();
×
136
                } else if (st.getPredicate().equals(HAS_VIEW_ACTION) && st.getObject() instanceof IRI objIri) {
×
137
                    actionList.add(objIri);
×
138
                } else if (st.getPredicate().equals(HAS_ELEMENT_NAMESPACE) && st.getObject() instanceof IRI objIri) {
×
139
                    elementNamespaces.add(objIri);
×
140
                } else if (st.getPredicate().equals(HAS_VIEW_TARGET_CLASS) && st.getObject() instanceof IRI objIri) {
×
141
                    targetClasses.add(objIri);
×
142
                } else if (st.getPredicate().equals(HAS_PAGE_SIZE) && st.getObject() instanceof Literal objL) {
×
143
                    try {
144
                        pageSize = Integer.parseInt(objL.stringValue());
×
145
                    } catch (NumberFormatException ex) {
×
146
                        logger.error("Invalid page size value: " + objL.stringValue(), ex);
×
147
                    }
×
148
                } else if (st.getPredicate().equals(HAS_DISPLAY_WIDTH) && st.getObject() instanceof IRI objIri) {
×
149
                    displayWidth = columnWidths.get(objIri);
×
150
                } else if (st.getPredicate().equals(HAS_DISPLAY_WIDTH) && st.getObject() instanceof Literal objL) {
×
151
                    structuralPosition = objL.stringValue();
×
152
                }
153
            } else if (st.getPredicate().equals(HAS_ACTION_TEMPLATE)) {
×
154
                Template template = TemplateData.get().getTemplate(st.getObject().stringValue());
×
155
                actionTemplateMap.put((IRI) st.getSubject(), template);
×
156
            } else if (st.getPredicate().equals(HAS_ACTION_TEMPLATE_TARGET_FIELD)) {
×
157
                actionTemplateTargetFieldMap.put((IRI) st.getSubject(), st.getObject().stringValue());
×
158
            } else if (st.getPredicate().equals(HAS_ACTION_TEMPLATE_PART_FIELD)) {
×
159
                actionTemplatePartFieldMap.put((IRI) st.getSubject(), st.getObject().stringValue());
×
160
            } else if (st.getPredicate().equals(RDFS.LABEL)) {
×
161
                labelMap.put((IRI) st.getSubject(), st.getObject().stringValue());
×
162
            }
163
        }
×
164
        if (!resourceViewTypeFound) throw new IllegalArgumentException("Not a proper resource view nanopub: " + id);
×
165
        if (query == null) throw new IllegalArgumentException("Query not found: " + id);
×
166
    }
×
167

168
    /**
169
     * Gets the ID of the ResourceView.
170
     *
171
     * @return the ID of the ResourceView
172
     */
173
    public String getId() {
174
        return id;
×
175
    }
176

177
    /**
178
     * Gets the Nanopub defining this ResourceView.
179
     *
180
     * @return the Nanopub defining this ResourceView
181
     */
182
    public Nanopub getNanopub() {
183
        return nanopub;
×
184
    }
185

186
    /**
187
     * Gets the label of the ResourceView.
188
     *
189
     * @return the label of the ResourceView
190
     */
191
    public String getLabel() {
192
        return label;
×
193
    }
194

195
    /**
196
     * Gets the title of the ResourceView.
197
     *
198
     * @return the title of the ResourceView
199
     */
200
    public String getTitle() {
201
        return title;
×
202
    }
203

204
    /**
205
     * Gets the GrlcQuery associated with the ResourceView.
206
     *
207
     * @return the GrlcQuery associated with the ResourceView
208
     */
209
    public GrlcQuery getQuery() {
210
        return query;
×
211
    }
212

213
    /**
214
     * Gets the query field of the ResourceView.
215
     *
216
     * @return the query field
217
     */
218
    public String getQueryField() {
219
        return queryField;
×
220
    }
221

222
    /**
223
     * Returns the preferred page size.
224
     *
225
     * @return page size (0 = everything on first page)
226
     */
227
    public Integer getPageSize() {
228
        return pageSize;
×
229
    }
230

231
    public Integer getDisplayWidth() {
232
        return displayWidth;
×
233
    }
234

235
    public String getStructuralPosition() {
236
        return structuralPosition;
×
237
    }
238

239
    /**
240
     * Gets the list of action IRIs associated with the ResourceView.
241
     *
242
     * @return the list of action IRIs
243
     */
244
    public List<IRI> getActionList() {
245
        return actionList;
×
246
    }
247

248
    /**
249
     * Gets the Template for a given action IRI.
250
     *
251
     * @param actionIri the action IRI
252
     * @return the Template for the action IRI
253
     */
254
    public Template getTemplateForAction(IRI actionIri) {
255
        return actionTemplateMap.get(actionIri);
×
256
    }
257

258
    /**
259
     * Gets the template field for a given action IRI.
260
     *
261
     * @param actionIri the action IRI
262
     * @return the template field for the action IRI
263
     */
264
    public String getTemplateTargetFieldForAction(IRI actionIri) {
265
        return actionTemplateTargetFieldMap.get(actionIri);
×
266
    }
267

268
    public String getTemplatePartFieldForAction(IRI actionIri) {
269
        return actionTemplatePartFieldMap.get(actionIri);
×
270
    }
271

272
    /**
273
     * Gets the label for a given action IRI.
274
     *
275
     * @param actionIri the action IRI
276
     * @return the label for the action IRI
277
     */
278
    public String getLabelForAction(IRI actionIri) {
279
        return labelMap.get(actionIri);
×
280
    }
281

282
    public boolean coversElement(String elementId) {
283
        for (IRI namespace : elementNamespaces) {
×
284
            if (elementId.startsWith(namespace.stringValue())) return true;
×
285
        }
×
286
        return false;
×
287
    }
288

289
    /**
290
     * Checks if the ResourceView has target classes.
291
     *
292
     * @return true if the ResourceView has target classes, false otherwise
293
     */
294
    public boolean hasTargetClasses() {
295
        return !targetClasses.isEmpty();
×
296
    }
297

298
    /**
299
     * Checks if the ResourceView has a specific target class.
300
     *
301
     * @param targetClass the target class IRI
302
     * @return true if the ResourceView has the target class, false otherwise
303
     */
304
    public boolean hasTargetClass(IRI targetClass) {
305
        return targetClasses.contains(targetClass);
×
306
    }
307

308
    @Override
309
    public String toString() {
310
        return id;
×
311
    }
312

313
    /**
314
     * Gets the view type of the ResourceView.
315
     *
316
     * @return the view type mode IRI
317
     */
318
    public IRI getViewType() {
319
        return viewType;
×
320
    }
321

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