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

knowledgepixels / nanodash / 19097758229

05 Nov 2025 09:43AM UTC coverage: 14.319% (-0.6%) from 14.966%
19097758229

push

github

tkuhn
feat: Add ViewDisplay class to link source nanopub for QueryResultTable

518 of 4516 branches covered (11.47%)

Branch coverage included in aggregate %.

1332 of 8404 relevant lines covered (15.85%)

0.71 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 java.io.Serializable;
4
import java.util.ArrayList;
5
import java.util.HashMap;
6
import java.util.HashSet;
7
import java.util.List;
8
import java.util.Map;
9
import java.util.Set;
10

11
import org.eclipse.rdf4j.model.IRI;
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.eclipse.rdf4j.model.vocabulary.RDFS;
16
import org.nanopub.Nanopub;
17
import org.slf4j.Logger;
18
import org.slf4j.LoggerFactory;
19

20
import com.knowledgepixels.nanodash.template.Template;
21
import com.knowledgepixels.nanodash.template.TemplateData;
22

23
public class ResourceView implements Serializable {
24

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

27
    public static final IRI RESOURCE_VIEW = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/ResourceView");
×
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_VIEW_ACTION = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/hasViewAction");
×
34
    public static final IRI HAS_ACTION_TEMPLATE = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/hasActionTemplate");
×
35
    public static final IRI HAS_ACTION_TEMPLATE_TARGET_FIELD = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/hasActionTemplateTargetField");
×
36

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

39
    public static ResourceView get(String id) {
40
        if (!resourceViews.containsKey(id)) {
×
41
            try {
42
                Nanopub np = Utils.getAsNanopub(id.replaceFirst("^(.*[^A-Za-z0-9-_])?(RA[A-Za-z0-9-_]{43})[^A-Za-z0-9-_].*$", "$2"));
×
43
                resourceViews.put(id, new ResourceView(id, np));
×
44
            } catch (Exception ex) {
×
45
                logger.error("Couldn't load nanopub for resource: " + id, ex);
×
46
            }
×
47
        }
48
        return resourceViews.get(id);
×
49
    }
50

51
    private String id;
52
    private Nanopub nanopub;
53
    private String label;
54
    private String title = "View";
×
55
    private GrlcQuery query;
56
    private String queryField = "resource";
×
57
    private List<IRI> actionList = new ArrayList<>();
×
58
    private Set<IRI> targetClasses = new HashSet<>();
×
59
    private Map<IRI,Template> actionTemplateMap = new HashMap<>();
×
60
    private Map<IRI,String> actionTemplateFieldMap = new HashMap<>();
×
61
    private Map<IRI,String> labelMap = new HashMap<>();
×
62

63
    private ResourceView(String id, Nanopub nanopub) {
×
64
        this.id = id;
×
65
        this.nanopub = nanopub;
×
66
        boolean resourceViewTypeFound = false;
×
67
        for (Statement st : nanopub.getAssertion()) {
×
68
            if (st.getSubject().stringValue().equals(id)) {
×
69
                if (st.getPredicate().equals(RDF.TYPE)) {
×
70
                    if (st.getObject().equals(RESOURCE_VIEW)) {
×
71
                        resourceViewTypeFound = true;
×
72
                    }
73
                } else if (st.getPredicate().equals(RDFS.LABEL)) {
×
74
                    label = st.getObject().stringValue();
×
75
                } else if (st.getPredicate().equals(DCTERMS.TITLE)) {
×
76
                    title = st.getObject().stringValue();
×
77
                } else if (st.getPredicate().equals(HAS_VIEW_QUERY)) {
×
78
                    query = GrlcQuery.get(st.getObject().stringValue());
×
79
                } else if (st.getPredicate().equals(HAS_VIEW_QUERY_TARGET_FIELD)) {
×
80
                    queryField = st.getObject().stringValue();
×
81
                } else if (st.getPredicate().equals(HAS_VIEW_ACTION) && st.getObject() instanceof IRI objIri) {
×
82
                    actionList.add(objIri);
×
83
                } else if (st.getPredicate().equals(HAS_VIEW_TARGET_CLASS) && st.getObject() instanceof IRI objIri) {
×
84
                    targetClasses.add(objIri);
×
85
                }
86
            } else if (st.getPredicate().equals(HAS_ACTION_TEMPLATE)) {
×
87
                Template template = TemplateData.get().getTemplate(st.getObject().stringValue());
×
88
                actionTemplateMap.put((IRI) st.getSubject(), template);
×
89
            } else if (st.getPredicate().equals(HAS_ACTION_TEMPLATE_TARGET_FIELD)) {
×
90
                actionTemplateFieldMap.put((IRI) st.getSubject(), st.getObject().stringValue());
×
91
            } else if (st.getPredicate().equals(RDFS.LABEL)) {
×
92
                labelMap.put((IRI) st.getSubject(), st.getObject().stringValue());
×
93
            }
94
        }
×
95
        if (!resourceViewTypeFound) throw new IllegalArgumentException("Not a proper resource view nanopub: " + id);
×
96
        if (query == null) throw new IllegalArgumentException("Query not found: " + id);
×
97
    }
×
98

99
    public String getId() {
100
        return id;
×
101
    }
102

103
    public Nanopub getNanopub() {
104
        return nanopub;
×
105
    }
106

107
    public String getLabel() {
108
        return label;
×
109
    }
110

111
    public String getTitle() {
112
        return title;
×
113
    }
114

115
    public GrlcQuery getQuery() {
116
        return query;
×
117
    }
118

119
    public String getQueryField() {
120
        return queryField;
×
121
    }
122

123
    public List<IRI> getActionList() {
124
        return actionList;
×
125
    }
126

127
    public Template getTemplateForAction(IRI actionIri) {
128
        return actionTemplateMap.get(actionIri);
×
129
    }
130

131
    public String getTemplateFieldForAction(IRI actionIri) {
132
        return actionTemplateFieldMap.get(actionIri);
×
133
    }
134

135
    public String getLabelForAction(IRI actionIri) {
136
        return labelMap.get(actionIri);
×
137
    }
138

139
    public boolean hasTargetClasses() {
140
        return !targetClasses.isEmpty();
×
141
    }
142

143
    public boolean hasTargetClass(IRI targetClass) {
144
        return targetClasses.contains(targetClass);
×
145
    }
146

147
    @Override
148
    public String toString() {
149
        return id;
×
150
    }
151

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