Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions http-tests/document-hierarchy/GET-namespace-forClass-rdfs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -euo pipefail

initialize_dataset "$END_USER_BASE_URL" "$TMP_END_USER_DATASET" "$END_USER_ENDPOINT_URL"
initialize_dataset "$ADMIN_BASE_URL" "$TMP_ADMIN_DATASET" "$ADMIN_ENDPOINT_URL"
purge_cache "$END_USER_VARNISH_SERVICE"
purge_cache "$ADMIN_VARNISH_SERVICE"
purge_cache "$FRONTEND_VARNISH_SERVICE"

# sp:Describe is declared only as rdfs:Class (not owl:Class) in sp.ttl.
# OntologyFilter must promote rdfs:Class to owl:Class during materialization so
# that OWL2 profiles recognise third-party vocab terms and return their SPIN constructors.

response=$(curl -k -f -s \
-G \
-E "$OWNER_CERT_FILE":"$OWNER_CERT_PWD" \
-H "Accept: application/rdf+xml" \
--data-urlencode "forClass=http://spinrdf.org/sp#Describe" \
"${END_USER_BASE_URL}ns")

# response must be non-empty: sp:Describe must be recognised as an OntClass
echo "$response" | grep -q "http://spinrdf.org/sp#Describe"
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>twirl</artifactId>
<version>1.1.0</version>
<version>1.2.0-SNAPSHOT</version>
<exclusions>
<!-- exclude slf4j-reload4j 1.7.x binding; replaced below with 2.0.x matching slf4j-api from Jena -->
<exclusion>
Expand All @@ -163,13 +163,13 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>client</artifactId>
<version>4.3.0</version>
<version>4.3.1-SNAPSHOT</version>
<classifier>classes</classifier>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>client</artifactId>
<version>4.3.0</version>
<version>4.3.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
Expand Down
155 changes: 68 additions & 87 deletions src/main/java/com/atomgraph/linkeddatahub/Application.java

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/main/java/com/atomgraph/linkeddatahub/resource/Generate.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import jakarta.ws.rs.core.Response.Status;
import jakarta.ws.rs.core.UriBuilder;
import jakarta.ws.rs.core.UriInfo;
import org.apache.jena.ontology.Ontology;
import org.apache.jena.ontapi.model.OntModel;
import org.apache.jena.query.ParameterizedSparqlString;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryFactory;
Expand All @@ -69,7 +69,7 @@ public class Generate
private final UriInfo uriInfo;
private final MediaTypes mediaTypes;
private final Application application;
private final Ontology ontology;
private final OntModel ontology;
private final Optional<AgentContext> agentContext;
private final com.atomgraph.linkeddatahub.Application system;
private final ResourceContext resourceContext;
Expand All @@ -88,7 +88,7 @@ public class Generate
*/
@Inject
public Generate(@Context Request request, @Context UriInfo uriInfo, MediaTypes mediaTypes,
com.atomgraph.linkeddatahub.apps.model.Application application, Optional<Ontology> ontology, Optional<AgentContext> agentContext,
com.atomgraph.linkeddatahub.apps.model.Application application, Optional<OntModel> ontology, Optional<AgentContext> agentContext,
com.atomgraph.linkeddatahub.Application system, @Context ResourceContext resourceContext)
{
if (ontology.isEmpty()) throw new InternalServerErrorException("Ontology is not specified");
Expand Down Expand Up @@ -134,7 +134,7 @@ public Response post(Model model)
if (queryRes == null) throw new BadRequestException("Container query string (spin:query) not provided");

// Lookup query in ontology
Resource queryResource = getOntology().getOntModel().getResource(queryRes.getURI());
Resource queryResource = getOntology().getResource(queryRes.getURI());
if (queryResource == null || !queryResource.hasProperty(SP.text))
throw new BadRequestException("Query resource not found in ontology: " + queryRes.getURI());

Expand Down Expand Up @@ -265,7 +265,7 @@ public Application getApplication()
*
* @return the ontology
*/
public Ontology getOntology()
public OntModel getOntology()
{
return ontology;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import com.atomgraph.core.model.impl.dataset.ServiceImpl;
import com.atomgraph.linkeddatahub.apps.model.Application;
import com.atomgraph.linkeddatahub.apps.model.EndUserApplication;
import com.atomgraph.linkeddatahub.server.util.OntologyModelGetter;
import com.atomgraph.linkeddatahub.server.util.OntologyRepository;
import java.net.URI;
import java.util.List;
import java.util.Optional;
Expand All @@ -47,7 +47,7 @@
import jakarta.ws.rs.core.SecurityContext;
import jakarta.ws.rs.core.UriInfo;
import org.apache.jena.irix.IRIx;
import org.apache.jena.ontology.Ontology;
import org.apache.jena.ontapi.model.OntModel;
import org.apache.jena.query.DatasetFactory;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryFactory;
Expand All @@ -70,7 +70,7 @@ public class Namespace extends com.atomgraph.core.model.impl.SPARQLEndpointImpl
private final URI uri;
private final UriInfo uriInfo;
private final Application application;
private final Ontology ontology;
private final OntModel ontology;
private final com.atomgraph.linkeddatahub.Application system;

/**
Expand All @@ -86,10 +86,10 @@ public class Namespace extends com.atomgraph.core.model.impl.SPARQLEndpointImpl
*/
@Inject
public Namespace(@Context Request request, @Context UriInfo uriInfo,
Application application, Optional<Ontology> ontology, MediaTypes mediaTypes,
Application application, Optional<OntModel> ontology, MediaTypes mediaTypes,
@Context SecurityContext securityContext, com.atomgraph.linkeddatahub.Application system)
{
super(request, new ServiceImpl(DatasetFactory.create(ontology.get().getOntModel()), mediaTypes), mediaTypes);
super(request, new ServiceImpl(DatasetFactory.create(ontology.get()), mediaTypes), mediaTypes);
this.uri = uriInfo.getAbsolutePath();
this.uriInfo = uriInfo;
this.application = application;
Expand Down Expand Up @@ -128,7 +128,7 @@ public Response get(@QueryParam(QUERY) Query query,
Model instances = ModelFactory.createDefaultModel();

forClasses.stream().
map(forClass -> Optional.ofNullable(getOntology().getOntModel().getOntClass(checkURI(forClass).toString()))).
map(forClass -> Optional.ofNullable(getOntology().getOntClass(checkURI(forClass).toString()))).
flatMap(Optional::stream).
forEach(forClass -> new Constructor().construct(forClass, instances, getApplication().getBase().getURI()));

Expand All @@ -141,8 +141,8 @@ public Response get(@QueryParam(QUERY) Query query,
String ontologyURI = getApplication().getOntology().getURI();
if (log.isDebugEnabled()) log.debug("Returning namespace ontology from OntDocumentManager: {}", ontologyURI);
// not returning the injected in-memory ontology because it has inferences applied to it
OntologyModelGetter modelGetter = new OntologyModelGetter(getApplication().as(EndUserApplication.class), getSystem(), getSystem().getOntModelSpec(), getSystem().getOntologyQuery());
return getResponseBuilder(modelGetter.getModel(ontologyURI)).build();
OntologyRepository repository = new OntologyRepository(getApplication().as(EndUserApplication.class), getSystem(), com.atomgraph.linkeddatahub.client.GraphStoreClient.create(getSystem().getClient(), getSystem().getMediaTypes()), getSystem().getOntologyQuery());
return getResponseBuilder(org.apache.jena.rdf.model.ModelFactory.createModelForGraph(repository.get(ontologyURI))).build();
}
else throw new BadRequestException("SPARQL query string not provided");
}
Expand Down Expand Up @@ -223,7 +223,7 @@ public Application getApplication()
*
* @return application ontology
*/
public Ontology getOntology()
public OntModel getOntology()
{
return ontology;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@

import com.atomgraph.linkeddatahub.apps.model.AdminApplication;
import com.atomgraph.linkeddatahub.apps.model.EndUserApplication;
import static com.atomgraph.linkeddatahub.server.filter.request.OntologyFilter.addDocumentModel;
import com.atomgraph.linkeddatahub.server.filter.response.CacheInvalidationFilter;
import com.atomgraph.linkeddatahub.server.util.OntologyModelGetter;
import com.atomgraph.linkeddatahub.server.util.OntologyRepository;
import java.net.URI;
import jakarta.inject.Inject;
import jakarta.ws.rs.BadRequestException;
Expand All @@ -31,8 +30,7 @@
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriBuilder;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.ontology.OntModelSpec;
import com.atomgraph.linkeddatahub.server.filter.request.OntologyFilter;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
Expand Down Expand Up @@ -82,11 +80,11 @@ public Response post(@FormParam("uri") String ontologyURI, @HeaderParam("Referer
if (ontologyURI == null) throw new BadRequestException("Ontology URI not specified");

EndUserApplication endUserApp = getApplication().as(AdminApplication.class).getEndUserApplication(); // we're assuming the current app is admin
OntModelSpec ontModelSpec = new OntModelSpec(getSystem().getOntModelSpec(endUserApp));
if (ontModelSpec.getDocumentManager().getFileManager().hasCachedModel(ontologyURI))
OntologyRepository repository = getSystem().getRepository(endUserApp);
if (repository.isCached(ontologyURI))
{
if (log.isDebugEnabled()) log.debug("Clearing ontology with URI '{}' from memory", ontologyURI);
ontModelSpec.getDocumentManager().getFileManager().removeCacheModel(ontologyURI);
repository.remove(ontologyURI);

URI ontologyDocURI = UriBuilder.fromUri(ontologyURI).fragment(null).build(); // skip fragment from the ontology URI to get its graph URI
// frontend proxy still uses URL-pattern BAN for direct document GETs (until Stage 3 brings xkey tagging to varnish-frontend).
Expand Down Expand Up @@ -116,19 +114,7 @@ public Response post(@FormParam("uri") String ontologyURI, @HeaderParam("Referer
}

// !!! we need to reload the ontology model before returning a response, to make sure the next request already gets the new version !!!
// same logic as in OntologyFilter. TO-DO: encapsulate?
OntologyModelGetter modelGetter = new OntologyModelGetter(endUserApp, getSystem(), ontModelSpec, getSystem().getOntologyQuery());
ontModelSpec.setImportModelGetter(modelGetter);
if (log.isDebugEnabled()) log.debug("Started loading ontology with URI '{}' from the admin dataset", ontologyURI);
Model baseModel = modelGetter.getModel(ontologyURI);
OntModel ontModel = ModelFactory.createOntologyModel(ontModelSpec, baseModel);
// materialize OntModel inferences to avoid invoking rules engine on every request
OntModel materializedModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); // no inference
materializedModel.add(ontModel);
ontModel.getDocumentManager().addModel(ontologyURI, materializedModel, true); // make immutable and add as OntModel so that imports do not need to be reloaded during retrieval
// make sure to cache imported models not only by ontology URI but also by document URI
ontModel.listImportedOntologyURIs(true).forEach((String importURI) -> addDocumentModel(ontModel.getDocumentManager(), importURI));
if (log.isDebugEnabled()) log.debug("Finished loading ontology with URI '{}' from the admin dataset", ontologyURI);
OntologyFilter.loadOntology(repository, ontologyURI);
}

if (referer != null) return Response.seeOther(referer).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
import jakarta.ws.rs.core.UriInfo;
import jakarta.ws.rs.ext.Providers;
import static org.apache.jena.datatypes.xsd.XSDDatatype.XSDhexBinary;
import org.apache.jena.ontology.Ontology;
import org.apache.jena.ontapi.model.OntModel;
import org.apache.jena.query.ParameterizedSparqlString;
import org.apache.jena.query.Query;
import org.apache.jena.query.ResultSet;
Expand Down Expand Up @@ -144,7 +144,7 @@ public class SignUp extends DocumentHierarchyGraphStoreImpl
// TO-DO: move to AuthenticationExceptionMapper and handle as state instead of URI resource?
@Inject
public SignUp(@Context Request request, @Context UriInfo uriInfo, MediaTypes mediaTypes,
com.atomgraph.linkeddatahub.apps.model.Application application, Optional<Ontology> ontology, Optional<Service> service,
com.atomgraph.linkeddatahub.apps.model.Application application, Optional<OntModel> ontology, Optional<Service> service,
@Context SecurityContext securityContext, Optional<AgentContext> agentContext,
@Context Providers providers, com.atomgraph.linkeddatahub.Application system, @Context ServletConfig servletConfig)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.atomgraph.linkeddatahub.resource.admin.pkg;

import static com.atomgraph.client.MediaType.TEXT_XSL;
import com.atomgraph.client.util.DataManager;
import com.atomgraph.linkeddatahub.apps.model.AdminApplication;
import com.atomgraph.linkeddatahub.apps.model.EndUserApplication;
import com.atomgraph.linkeddatahub.client.GraphStoreClient;
Expand Down Expand Up @@ -60,7 +59,6 @@
import org.apache.jena.ontology.ConversionException;
import org.apache.jena.update.UpdateFactory;
import org.apache.jena.update.UpdateRequest;
import org.apache.jena.util.FileManager;
import com.atomgraph.linkeddatahub.vocabulary.DH;
import com.atomgraph.linkeddatahub.vocabulary.FOAF;
import com.atomgraph.linkeddatahub.vocabulary.SIOC;
Expand Down Expand Up @@ -88,7 +86,6 @@ public class InstallPackage

private final com.atomgraph.linkeddatahub.apps.model.Application application;
private final com.atomgraph.linkeddatahub.Application system;
private final DataManager dataManager;
private final Optional<AgentContext> agentContext;

@Context ServletContext servletContext;
Expand All @@ -105,12 +102,10 @@ public class InstallPackage
@Inject
public InstallPackage(com.atomgraph.linkeddatahub.apps.model.Application application,
com.atomgraph.linkeddatahub.Application system,
DataManager dataManager,
Optional<AgentContext> agentContext)
{
this.application = application;
this.system = system;
this.dataManager = dataManager;
this.agentContext = agentContext;
}

Expand Down Expand Up @@ -242,12 +237,12 @@ private com.atomgraph.linkeddatahub.apps.model.Package getPackage(String package
final Model model;

// check if we have the model in the cache first and if yes, return it from there instead making an HTTP request
if (((FileManager)getDataManager()).hasCachedModel(packageURI) ||
(getDataManager().isResolvingMapped() && getDataManager().isMapped(packageURI))) // read mapped URIs (such as system ontologies) from a file
if (getSystem().getRepository().isCached(packageURI) ||
(getSystem().getRepository().isMapped(packageURI))) // read mapped URIs (such as system ontologies) from a file
{
if (log.isDebugEnabled()) log.debug("hasCachedModel({}): {}", packageURI, ((FileManager)getDataManager()).hasCachedModel(packageURI));
if (log.isDebugEnabled()) log.debug("isMapped({}): {}", packageURI, getDataManager().isMapped(packageURI));
model = getDataManager().loadModel(packageURI);
if (log.isDebugEnabled()) log.debug("hasCachedModel({}): {}", packageURI, getSystem().getRepository().isCached(packageURI));
if (log.isDebugEnabled()) log.debug("isMapped({}): {}", packageURI, getSystem().getRepository().isMapped(packageURI));
model = ModelFactory.createModelForGraph(getSystem().getRepository().get(packageURI));
}
else
{
Expand Down Expand Up @@ -284,12 +279,12 @@ private Model downloadOntology(String uri)
if (log.isDebugEnabled()) log.debug("Downloading ontology from: {}", uri);

// check if we have the model in the cache first and if yes, return it from there instead making an HTTP request
if (((FileManager)getDataManager()).hasCachedModel(uri) ||
(getDataManager().isResolvingMapped() && getDataManager().isMapped(uri))) // read mapped URIs (such as system ontologies) from a file
if (getSystem().getRepository().isCached(uri) ||
(getSystem().getRepository().isMapped(uri))) // read mapped URIs (such as system ontologies) from a file
{
if (log.isDebugEnabled()) log.debug("hasCachedModel({}): {}", uri, ((FileManager)getDataManager()).hasCachedModel(uri));
if (log.isDebugEnabled()) log.debug("isMapped({}): {}", uri, getDataManager().isMapped(uri));
return getDataManager().loadModel(uri);
if (log.isDebugEnabled()) log.debug("hasCachedModel({}): {}", uri, getSystem().getRepository().isCached(uri));
if (log.isDebugEnabled()) log.debug("isMapped({}): {}", uri, getSystem().getRepository().isMapped(uri));
return ModelFactory.createModelForGraph(getSystem().getRepository().get(uri));
}
else
{
Expand Down Expand Up @@ -522,15 +517,6 @@ public ServletContext getServletContext()
return servletContext;
}

/**
* Returns RDF data manager.
*
* @return RDF data manager
*/
public DataManager getDataManager()
{
return dataManager;
}

/**
* Returns JAX-RS resource context.
Expand Down
Loading
Loading