Skip to content

Commit b48dfa1

Browse files
committed
Class tree feature
1 parent 7f4b8f4 commit b48dfa1

8 files changed

Lines changed: 315 additions & 67 deletions

File tree

platform/datasets/admin.trig

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -94,46 +94,6 @@ WHERE
9494

9595
}
9696

97-
<queries/select-instances/>
98-
{
99-
100-
<queries/select-instances/> a dh:Item ;
101-
sioc:has_container <queries/> ;
102-
dct:title "Select instances" ;
103-
foaf:primaryTopic <queries/select-instances/#this> .
104-
105-
<queries/select-instances/#this> a sp:Select ;
106-
dct:title "Select instances" ;
107-
dct:description "Selects instances of type from the default graph" ;
108-
sp:text """SELECT DISTINCT ?s
109-
WHERE
110-
{ ?s a $type ;
111-
?p ?o
112-
}""" .
113-
114-
}
115-
116-
<queries/select-instances-in-graphs/>
117-
{
118-
119-
<queries/select-instances-in-graphs/> a dh:Item ;
120-
sioc:has_container <queries/> ;
121-
dct:title "Select instances in graphs" ;
122-
foaf:primaryTopic <queries/select-instances-in-graphs/#this> .
123-
124-
<queries/select-instances-in-graphs/#this> a sp:Select ;
125-
dct:title "Select instances in graphs" ;
126-
dct:description "Selects instances of type from named graphs" ;
127-
sp:text """SELECT DISTINCT ?s
128-
WHERE
129-
{ GRAPH ?g
130-
{ ?s a $type ;
131-
?p ?o
132-
}
133-
}""" .
134-
135-
}
136-
13797
<files/>
13898
{
13999

src/main/java/com/atomgraph/linkeddatahub/resource/Generate.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
import com.atomgraph.core.MediaTypes;
2020
import com.atomgraph.linkeddatahub.apps.model.Application;
21-
import com.atomgraph.linkeddatahub.client.GraphStoreClient;
22-
import com.atomgraph.linkeddatahub.imports.QueryLoader;
2321
import com.atomgraph.linkeddatahub.server.model.impl.DirectGraphStoreImpl;
2422
import com.atomgraph.linkeddatahub.server.security.AgentContext;
2523
import com.atomgraph.linkeddatahub.server.util.Skolemizer;
@@ -44,8 +42,10 @@
4442
import jakarta.ws.rs.core.Response.Status;
4543
import jakarta.ws.rs.core.UriBuilder;
4644
import jakarta.ws.rs.core.UriInfo;
45+
import org.apache.jena.ontology.Ontology;
4746
import org.apache.jena.query.ParameterizedSparqlString;
4847
import org.apache.jena.query.Query;
48+
import org.apache.jena.query.QueryFactory;
4949
import org.apache.jena.query.Syntax;
5050
import org.apache.jena.rdf.model.Model;
5151
import org.apache.jena.rdf.model.ModelFactory;
@@ -69,29 +69,33 @@ public class Generate
6969
private final UriInfo uriInfo;
7070
private final MediaTypes mediaTypes;
7171
private final Application application;
72+
private final Ontology ontology;
7273
private final Optional<AgentContext> agentContext;
7374
private final com.atomgraph.linkeddatahub.Application system;
7475
private final ResourceContext resourceContext;
75-
76+
7677
/**
7778
* Constructs endpoint for container generation.
7879
*
7980
* @param request current request
8081
* @param uriInfo current URI info
8182
* @param mediaTypes supported media types
8283
* @param application matched application
84+
* @param ontology ontology of the current application
8385
* @param system system application
8486
* @param agentContext authenticated agent's context
8587
* @param resourceContext resource context for creating resources
8688
*/
8789
@Inject
8890
public Generate(@Context Request request, @Context UriInfo uriInfo, MediaTypes mediaTypes,
89-
com.atomgraph.linkeddatahub.apps.model.Application application, Optional<AgentContext> agentContext,
91+
com.atomgraph.linkeddatahub.apps.model.Application application, Optional<Ontology> ontology, Optional<AgentContext> agentContext,
9092
com.atomgraph.linkeddatahub.Application system, @Context ResourceContext resourceContext)
9193
{
94+
if (ontology.isEmpty()) throw new InternalServerErrorException("Ontology is not specified");
9295
this.uriInfo = uriInfo;
9396
this.mediaTypes = mediaTypes;
9497
this.application = application;
98+
this.ontology = ontology.get();
9599
this.agentContext = agentContext;
96100
this.system = system;
97101
this.resourceContext = resourceContext;
@@ -129,10 +133,13 @@ public Response post(Model model)
129133
Resource queryRes = part.getPropertyResourceValue(SPIN.query);
130134
if (queryRes == null) throw new BadRequestException("Container query string (spin:query) not provided");
131135

132-
GraphStoreClient gsc = GraphStoreClient.create(getSystem().getClient(), getSystem().getMediaTypes()).
133-
delegation(getUriInfo().getBaseUri(), getAgentContext().orElse(null));
134-
QueryLoader queryLoader = new QueryLoader(URI.create(queryRes.getURI()), getApplication().getBase().getURI(), Syntax.syntaxARQ, gsc);
135-
Query query = queryLoader.get();
136+
// Lookup query in ontology
137+
Resource queryResource = getOntology().getOntModel().getResource(queryRes.getURI());
138+
if (queryResource == null || !queryResource.hasProperty(SP.text))
139+
throw new BadRequestException("Query resource not found in ontology: " + queryRes.getURI());
140+
141+
String queryString = queryResource.getProperty(SP.text).getString();
142+
Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
136143
if (!query.isSelectType()) throw new BadRequestException("Container query is not of SELECT type");
137144

138145
ParameterizedSparqlString pss = new ParameterizedSparqlString(query.toString());
@@ -253,6 +260,16 @@ public Application getApplication()
253260
return application;
254261
}
255262

263+
/**
264+
* Returns the ontology.
265+
*
266+
* @return the ontology
267+
*/
268+
public Ontology getOntology()
269+
{
270+
return ontology;
271+
}
272+
256273
/**
257274
* Returns the current URI info.
258275
*

src/main/resources/com/atomgraph/linkeddatahub/ldh.ttl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,28 @@ ORDER BY ?title
493493
""" ;
494494
rdfs:isDefinedBy : .
495495

496+
:SelectInstances a sp:Select ;
497+
rdfs:label "Select instances" ;
498+
dct:description "Selects instances of type from the default graph" ;
499+
sp:text """SELECT DISTINCT ?s
500+
WHERE
501+
{ ?s a $type ;
502+
?p ?o
503+
}""" ;
504+
rdfs:isDefinedBy : .
505+
506+
:SelectInstancesInGraphs a sp:Select ;
507+
rdfs:label "Select instances in graphs" ;
508+
dct:description "Selects instances of type from named graphs" ;
509+
sp:text """SELECT DISTINCT ?s
510+
WHERE
511+
{ GRAPH ?g
512+
{ ?s a $type ;
513+
?p ?o
514+
}
515+
}""" ;
516+
rdfs:isDefinedBy : .
517+
496518
:ChildrenView a :View ;
497519
rdfs:label "Children view" ;
498520
spin:query :SelectChildren ;

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/client/modal.xsl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ ORDER BY DESC(COUNT(?s))
5959
LIMIT 10
6060
]]>
6161
</xsl:param>
62-
62+
6363
<!-- TEMPLATES -->
6464

6565
<xsl:template name="ldh:FirstTimeMessage">
@@ -1369,16 +1369,16 @@ LIMIT 10
13691369
<input type="hidden" name="ob" value="dataset-{position()}"/> <!-- unique bnode ID for each item -->
13701370
<input type="hidden" name="sb" value="dataset-{position()}"/> <!-- unique bnode ID for each item -->
13711371
<input type="hidden" name="pu" value="&spin;query"/>
1372-
1372+
13731373
<xsl:choose>
13741374
<xsl:when test="srx:binding[@name = 'namedGraph']/srx:uri">
1375-
<input type="hidden" name="ou" value="{resolve-uri('queries/select-instances-in-graphs/#this', ldt:base())}"/>
1375+
<input type="hidden" name="ou" value="&ldh;SelectInstancesInGraphs"/>
13761376
</xsl:when>
13771377
<xsl:otherwise>
1378-
<input type="hidden" name="ou" value="{resolve-uri('queries/select-instances/#this', ldt:base())}"/>
1378+
<input type="hidden" name="ou" value="&ldh;SelectInstances"/>
13791379
</xsl:otherwise>
13801380
</xsl:choose>
1381-
1381+
13821382
<input type="hidden" name="pu" value="&void;class"/>
13831383

13841384
<label class="checkbox">

0 commit comments

Comments
 (0)