|
23 | 23 | import com.atomgraph.core.util.ModelUtils; |
24 | 24 | import com.atomgraph.core.util.ResultSetUtils; |
25 | 25 | import com.atomgraph.linkeddatahub.apps.model.Dataset; |
| 26 | +import org.apache.jena.ontology.Ontology; |
26 | 27 | import com.atomgraph.linkeddatahub.client.GraphStoreClient; |
27 | 28 | import com.atomgraph.linkeddatahub.client.filter.auth.IDTokenDelegationFilter; |
28 | 29 | import com.atomgraph.linkeddatahub.client.filter.auth.WebIDDelegationFilter; |
|
36 | 37 | import java.util.ArrayList; |
37 | 38 | import java.util.List; |
38 | 39 | import java.util.Optional; |
| 40 | +import org.apache.jena.query.QueryExecution; |
| 41 | +import org.apache.jena.query.QueryFactory; |
39 | 42 | import jakarta.annotation.Priority; |
40 | 43 | import jakarta.inject.Inject; |
41 | 44 | import jakarta.ws.rs.NotAcceptableException; |
@@ -91,6 +94,7 @@ public class ProxyRequestFilter implements ContainerRequestFilter |
91 | 94 |
|
92 | 95 | @Inject com.atomgraph.linkeddatahub.Application system; |
93 | 96 | @Inject MediaTypes mediaTypes; |
| 97 | + @Inject Optional<Ontology> ontology; |
94 | 98 | @Context Request request; |
95 | 99 |
|
96 | 100 | @Override |
@@ -123,6 +127,26 @@ public void filter(ContainerRequestContext requestContext) throws IOException |
123 | 127 | return; |
124 | 128 | } |
125 | 129 |
|
| 130 | + // serve terms from the app's in-memory namespace ontology (full imports closure) via DESCRIBE. |
| 131 | + // covers both slash-based term URIs (e.g. schema:category) and hash-based namespaces |
| 132 | + // (e.g. sioc:UserAccount → ac:document-uri strips to sioc:ns, so we also describe all |
| 133 | + // ?term where STR(?term) starts with "<targetURI>#") |
| 134 | + if (getOntology().isPresent()) |
| 135 | + { |
| 136 | + String describeQueryStr = "DESCRIBE <" + targetURI + "> ?term " + |
| 137 | + "WHERE { ?term ?p ?o FILTER(STRSTARTS(STR(?term), CONCAT(STR(<" + targetURI + ">), \"#\"))) }"; |
| 138 | + try (QueryExecution qe = QueryExecution.create(QueryFactory.create(describeQueryStr), getOntology().get().getOntModel())) |
| 139 | + { |
| 140 | + Model description = qe.execDescribe(); |
| 141 | + if (!description.isEmpty()) |
| 142 | + { |
| 143 | + if (log.isDebugEnabled()) log.debug("Serving URI from namespace ontology: {}", targetURI); |
| 144 | + requestContext.abortWith(getResponse(description, Response.Status.OK)); |
| 145 | + return; |
| 146 | + } |
| 147 | + } |
| 148 | + } |
| 149 | + |
126 | 150 | boolean isRegisteredApp = getSystem().matchApp(targetURI) != null; |
127 | 151 | if (!isRegisteredApp && !getSystem().isEnableLinkedDataProxy()) |
128 | 152 | throw new NotAllowedException("Linked Data proxy not enabled"); |
@@ -312,6 +336,16 @@ public com.atomgraph.linkeddatahub.Application getSystem() |
312 | 336 | return system; |
313 | 337 | } |
314 | 338 |
|
| 339 | + /** |
| 340 | + * Returns the current application's namespace ontology, if available. |
| 341 | + * |
| 342 | + * @return optional ontology |
| 343 | + */ |
| 344 | + public Optional<Ontology> getOntology() |
| 345 | + { |
| 346 | + return ontology; |
| 347 | + } |
| 348 | + |
315 | 349 | /** |
316 | 350 | * Returns the media types registry. |
317 | 351 | * |
|
0 commit comments