• 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/ResourceView.java
1
package com.knowledgepixels.nanodash;
2

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

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

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

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

26
    static Map<IRI, Integer> columnWidths = new HashMap<>();
×
27

28
    static {
29
        columnWidths.put(KPXL_TERMS.COLUMN_WIDTH_1_OF_12, 1);
×
30
        columnWidths.put(KPXL_TERMS.COLUMN_WIDTH_2_OF_12, 2);
×
31
        columnWidths.put(KPXL_TERMS.COLUMN_WIDTH_3_OF_12, 3);
×
32
        columnWidths.put(KPXL_TERMS.COLUMN_WIDTH_4_OF_12, 4);
×
33
        columnWidths.put(KPXL_TERMS.COLUMN_WIDTH_5_OF_12, 5);
×
34
        columnWidths.put(KPXL_TERMS.COLUMN_WIDTH_6_OF_12, 6);
×
35
        columnWidths.put(KPXL_TERMS.COLUMN_WIDTH_7_OF_12, 7);
×
36
        columnWidths.put(KPXL_TERMS.COLUMN_WIDTH_8_OF_12, 8);
×
37
        columnWidths.put(KPXL_TERMS.COLUMN_WIDTH_9_OF_12, 9);
×
38
        columnWidths.put(KPXL_TERMS.COLUMN_WIDTH_10_OF_12, 10);
×
39
        columnWidths.put(KPXL_TERMS.COLUMN_WIDTH_11_OF_12, 11);
×
40
        columnWidths.put(KPXL_TERMS.COLUMN_WIDTH_12_OF_12, 12);
×
41
    }
42

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

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

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

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

137
    /**
138
     * Gets the ID of the ResourceView.
139
     *
140
     * @return the ID of the ResourceView
141
     */
142
    public String getId() {
143
        return id;
×
144
    }
145

146
    /**
147
     * Gets the Nanopub defining this ResourceView.
148
     *
149
     * @return the Nanopub defining this ResourceView
150
     */
151
    public Nanopub getNanopub() {
152
        return nanopub;
×
153
    }
154

155
    /**
156
     * Gets the label of the ResourceView.
157
     *
158
     * @return the label of the ResourceView
159
     */
160
    public String getLabel() {
161
        return label;
×
162
    }
163

164
    /**
165
     * Gets the title of the ResourceView.
166
     *
167
     * @return the title of the ResourceView
168
     */
169
    public String getTitle() {
170
        return title;
×
171
    }
172

173
    /**
174
     * Gets the GrlcQuery associated with the ResourceView.
175
     *
176
     * @return the GrlcQuery associated with the ResourceView
177
     */
178
    public GrlcQuery getQuery() {
179
        return query;
×
180
    }
181

182
    /**
183
     * Gets the query field of the ResourceView.
184
     *
185
     * @return the query field
186
     */
187
    public String getQueryField() {
188
        return queryField;
×
189
    }
190

191
    /**
192
     * Returns the preferred page size.
193
     *
194
     * @return page size (0 = everything on first page)
195
     */
196
    public Integer getPageSize() {
197
        return pageSize;
×
198
    }
199

200
    public Integer getDisplayWidth() {
201
        return displayWidth;
×
202
    }
203

204
    public String getStructuralPosition() {
205
        return structuralPosition;
×
206
    }
207

208
    /**
209
     * Gets the list of action IRIs associated with the ResourceView.
210
     *
211
     * @return the list of action IRIs
212
     */
213
    public List<IRI> getActionList() {
214
        return actionList;
×
215
    }
216

217
    /**
218
     * Gets the Template for a given action IRI.
219
     *
220
     * @param actionIri the action IRI
221
     * @return the Template for the action IRI
222
     */
223
    public Template getTemplateForAction(IRI actionIri) {
224
        return actionTemplateMap.get(actionIri);
×
225
    }
226

227
    /**
228
     * Gets the template field for a given action IRI.
229
     *
230
     * @param actionIri the action IRI
231
     * @return the template field for the action IRI
232
     */
233
    public String getTemplateTargetFieldForAction(IRI actionIri) {
234
        return actionTemplateTargetFieldMap.get(actionIri);
×
235
    }
236

237
    public String getTemplatePartFieldForAction(IRI actionIri) {
238
        return actionTemplatePartFieldMap.get(actionIri);
×
239
    }
240

241
    public String getTemplateQueryMapping(IRI actionIri) {
242
        return actionTemplateQueryMappingMap.get(actionIri);
×
243
    }
244

245
    /**
246
     * Gets the label for a given action IRI.
247
     *
248
     * @param actionIri the action IRI
249
     * @return the label for the action IRI
250
     */
251
    public String getLabelForAction(IRI actionIri) {
252
        return labelMap.get(actionIri);
×
253
    }
254

255
    public boolean coversElement(String elementId) {
256
        for (IRI namespace : elementNamespaces) {
×
257
            if (elementId.startsWith(namespace.stringValue())) return true;
×
258
        }
×
259
        return false;
×
260
    }
261

262
    /**
263
     * Checks if the ResourceView has target classes.
264
     *
265
     * @return true if the ResourceView has target classes, false otherwise
266
     */
267
    public boolean hasTargetClasses() {
268
        return !targetClasses.isEmpty();
×
269
    }
270

271
    /**
272
     * Checks if the ResourceView has a specific target class.
273
     *
274
     * @param targetClass the target class IRI
275
     * @return true if the ResourceView has the target class, false otherwise
276
     */
277
    public boolean hasTargetClass(IRI targetClass) {
278
        return targetClasses.contains(targetClass);
×
279
    }
280

281
    @Override
282
    public String toString() {
283
        return id;
×
284
    }
285

286
    /**
287
     * Gets the view type of the ResourceView.
288
     *
289
     * @return the view type mode IRI
290
     */
291
    public IRI getViewType() {
292
        return viewType;
×
293
    }
294

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