1818
1919import com .atomgraph .core .MediaTypes ;
2020import com .atomgraph .linkeddatahub .apps .model .Application ;
21- import com .atomgraph .linkeddatahub .client .GraphStoreClient ;
22- import com .atomgraph .linkeddatahub .imports .QueryLoader ;
2321import com .atomgraph .linkeddatahub .server .model .impl .DirectGraphStoreImpl ;
2422import com .atomgraph .linkeddatahub .server .security .AgentContext ;
2523import com .atomgraph .linkeddatahub .server .util .Skolemizer ;
4442import jakarta .ws .rs .core .Response .Status ;
4543import jakarta .ws .rs .core .UriBuilder ;
4644import jakarta .ws .rs .core .UriInfo ;
45+ import org .apache .jena .ontology .Ontology ;
4746import org .apache .jena .query .ParameterizedSparqlString ;
4847import org .apache .jena .query .Query ;
48+ import org .apache .jena .query .QueryFactory ;
4949import org .apache .jena .query .Syntax ;
5050import org .apache .jena .rdf .model .Model ;
5151import 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 *
0 commit comments