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

knowledgepixels / nanodash / 19292766293

12 Nov 2025 09:32AM UTC coverage: 13.802% (-0.4%) from 14.211%
19292766293

push

github

tkuhn
feat(ResourceView): Support for hasActionTemplateQueryMapping

512 of 4746 branches covered (10.79%)

Branch coverage included in aggregate %.

1350 of 8745 relevant lines covered (15.44%)

0.69 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
    public static final IRI HAS_ACTION_TEMPLATE_QUERY_MAPPING = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/hasActionTemplateQueryMapping");
×
41

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

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

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

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

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

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

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

172
    /**
173
     * Gets the ID of the ResourceView.
174
     *
175
     * @return the ID of the ResourceView
176
     */
177
    public String getId() {
178
        return id;
×
179
    }
180

181
    /**
182
     * Gets the Nanopub defining this ResourceView.
183
     *
184
     * @return the Nanopub defining this ResourceView
185
     */
186
    public Nanopub getNanopub() {
187
        return nanopub;
×
188
    }
189

190
    /**
191
     * Gets the label of the ResourceView.
192
     *
193
     * @return the label of the ResourceView
194
     */
195
    public String getLabel() {
196
        return label;
×
197
    }
198

199
    /**
200
     * Gets the title of the ResourceView.
201
     *
202
     * @return the title of the ResourceView
203
     */
204
    public String getTitle() {
205
        return title;
×
206
    }
207

208
    /**
209
     * Gets the GrlcQuery associated with the ResourceView.
210
     *
211
     * @return the GrlcQuery associated with the ResourceView
212
     */
213
    public GrlcQuery getQuery() {
214
        return query;
×
215
    }
216

217
    /**
218
     * Gets the query field of the ResourceView.
219
     *
220
     * @return the query field
221
     */
222
    public String getQueryField() {
223
        return queryField;
×
224
    }
225

226
    /**
227
     * Returns the preferred page size.
228
     *
229
     * @return page size (0 = everything on first page)
230
     */
231
    public Integer getPageSize() {
232
        return pageSize;
×
233
    }
234

235
    public Integer getDisplayWidth() {
236
        return displayWidth;
×
237
    }
238

239
    public String getStructuralPosition() {
240
        return structuralPosition;
×
241
    }
242

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

252
    /**
253
     * Gets the Template for a given action IRI.
254
     *
255
     * @param actionIri the action IRI
256
     * @return the Template for the action IRI
257
     */
258
    public Template getTemplateForAction(IRI actionIri) {
259
        return actionTemplateMap.get(actionIri);
×
260
    }
261

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

272
    public String getTemplatePartFieldForAction(IRI actionIri) {
273
        return actionTemplatePartFieldMap.get(actionIri);
×
274
    }
275

276
    public String getTemplateQueryMapping(IRI actionIri) {
277
        return actionTemplateQueryMappingMap.get(actionIri);
×
278
    }
279

280
    /**
281
     * Gets the label for a given action IRI.
282
     *
283
     * @param actionIri the action IRI
284
     * @return the label for the action IRI
285
     */
286
    public String getLabelForAction(IRI actionIri) {
287
        return labelMap.get(actionIri);
×
288
    }
289

290
    public boolean coversElement(String elementId) {
291
        for (IRI namespace : elementNamespaces) {
×
292
            if (elementId.startsWith(namespace.stringValue())) return true;
×
293
        }
×
294
        return false;
×
295
    }
296

297
    /**
298
     * Checks if the ResourceView has target classes.
299
     *
300
     * @return true if the ResourceView has target classes, false otherwise
301
     */
302
    public boolean hasTargetClasses() {
303
        return !targetClasses.isEmpty();
×
304
    }
305

306
    /**
307
     * Checks if the ResourceView has a specific target class.
308
     *
309
     * @param targetClass the target class IRI
310
     * @return true if the ResourceView has the target class, false otherwise
311
     */
312
    public boolean hasTargetClass(IRI targetClass) {
313
        return targetClasses.contains(targetClass);
×
314
    }
315

316
    @Override
317
    public String toString() {
318
        return id;
×
319
    }
320

321
    /**
322
     * Gets the view type of the ResourceView.
323
     *
324
     * @return the view type mode IRI
325
     */
326
    public IRI getViewType() {
327
        return viewType;
×
328
    }
329

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