2222import static com .atomgraph .core .model .SPARQLEndpoint .QUERY ;
2323import com .atomgraph .linkeddatahub .apps .model .AdminApplication ;
2424import com .atomgraph .linkeddatahub .apps .model .Application ;
25- import com .atomgraph .linkeddatahub .client .SesameProtocolClient ;
2625import com .atomgraph .linkeddatahub .model .Service ;
2726import com .atomgraph .linkeddatahub .model .auth .Agent ;
2827import com .atomgraph .linkeddatahub .server .security .AgentContext ;
4948import org .apache .jena .query .Query ;
5049import org .apache .jena .query .QuerySolution ;
5150import org .apache .jena .query .QuerySolutionMap ;
52- import org .apache .jena .query .ResultSet ;
5351import org .apache .jena .query .ResultSetRewindable ;
5452import org .apache .jena .rdf .model .Model ;
5553import org .apache .jena .rdf .model .ModelFactory ;
@@ -104,7 +102,7 @@ public Access(@Context Request request, @Context UriInfo uriInfo,
104102
105103 @ Override
106104 @ GET
107- public Response get (@ QueryParam (QUERY ) Query query ,
105+ public Response get (@ QueryParam (QUERY ) Query unused ,
108106 @ QueryParam (DEFAULT_GRAPH_URI ) List <URI > defaultGraphUris , @ QueryParam (NAMED_GRAPH_URI ) List <URI > namedGraphUris )
109107 {
110108 final Agent agent = getAgentContext ().map (AgentContext ::getAgent ).orElse (null );
@@ -113,9 +111,7 @@ public Response get(@QueryParam(QUERY) Query query,
113111// addProperty(RDF.type, FOAF.Agent).
114112// as(Agent.class);
115113
116- //final ParameterizedSparqlString pss = getApplication().canAs(EndUserApplication.class) ? getACLQuery() : getOwnerACLQuery();
117- final ParameterizedSparqlString authPss = getACLQuery ();
118-
114+ //final ParameterizedSparqlString pss = getApplication().canAs(EndUserApplication.class) ? getACLQuery() : getOwnerACLQuery();
119115 try
120116 {
121117 if (!getUriInfo ().getQueryParameters ().containsKey (SPIN .THIS_VAR_NAME )) throw new BadRequestException ("?this query param is not provided" );
@@ -125,15 +121,18 @@ public Response get(@QueryParam(QUERY) Query query,
125121
126122 QuerySolutionMap thisQsm = new QuerySolutionMap ();
127123 thisQsm .add (SPIN .THIS_VAR_NAME , accessTo );
128- ResultSetRewindable docTypesResult = loadResultSet (getEndUserService (), getDocumentTypeQuery (), thisQsm );
124+ ParameterizedSparqlString typePss = getDocumentTypeQuery ();
125+ typePss .setParams (thisQsm );
129126
127+ ResultSetRewindable docTypesResult = getEndpointAccessor ().select (typePss .asQuery (), null , null );
130128 try
131129 {
130+ final ParameterizedSparqlString authPss = getACLQuery ();
132131 authPss .setParams (new AuthorizationParams (getApplication ().getBase (), accessTo , agent ).get ());
133- query = new SetResultSetValues ().apply (authPss .asQuery (), docTypesResult );
134- assert query .toString ().contains ("VALUES" );
132+ Query authQuery = new SetResultSetValues ().apply (authPss .asQuery (), docTypesResult );
133+ assert authQuery .toString ().contains ("VALUES" );
135134
136- Model authModel = getEndpointAccessor ().loadModel (query , defaultGraphUris , namedGraphUris );
135+ Model authModel = getEndpointAccessor ().loadModel (authQuery , defaultGraphUris , namedGraphUris );
137136 // special case where the agent is the owner of the requested document - automatically grant acl:Read/acl:Append/acl:Write access
138137 if (isOwner (accessTo , agent ))
139138 {
@@ -154,38 +153,6 @@ public Response get(@QueryParam(QUERY) Query query,
154153 }
155154 }
156155
157- /**
158- * Loads SPARQL result set from a service.
159- *
160- * @param service SPARQL service
161- * @param pss auth query string
162- * @param qsm query solution map (applied to the query string or sent as request params, depending on the protocol)
163- * @return authorization graph (can be empty)
164- * @see com.atomgraph.linkeddatahub.vocabulary.LDHC#authQuery
165- */
166- protected ResultSetRewindable loadResultSet (com .atomgraph .linkeddatahub .model .Service service , ParameterizedSparqlString pss , QuerySolutionMap qsm )
167- {
168- if (service == null ) throw new IllegalArgumentException ("Service cannot be null" );
169- if (pss == null ) throw new IllegalArgumentException ("ParameterizedSparqlString cannot be null" );
170- if (qsm == null ) throw new IllegalArgumentException ("QuerySolutionMap cannot be null" );
171-
172- // send query bindings separately from the query if the service supports the Sesame protocol
173- if (service .getSPARQLClient () instanceof SesameProtocolClient sesameProtocolClient )
174- try (Response cr = sesameProtocolClient .query (pss .asQuery (), ResultSet .class , qsm )) // register(new CacheControlFilter(CacheControl.valueOf("no-cache"))). // add Cache-Control: no-cache to request
175- {
176- return cr .readEntity (ResultSetRewindable .class );
177- }
178- else
179- {
180- pss .setParams (qsm );
181- try (Response cr = service .getSPARQLClient (). // register(new CacheControlFilter(CacheControl.valueOf("no-cache"))). // add Cache-Control: no-cache to request
182- query (pss .asQuery (), ResultSet .class ))
183- {
184- return cr .readEntity (ResultSetRewindable .class );
185- }
186- }
187- }
188-
189156 /**
190157 * Checks if the given agent is the <code>acl:owner</code> of the document.
191158 *
@@ -197,8 +164,11 @@ protected boolean isOwner(Resource accessTo, Resource agent)
197164 {
198165 QuerySolutionMap qsm = new QuerySolutionMap ();
199166 qsm .add (SPIN .THIS_VAR_NAME , accessTo );
167+ ParameterizedSparqlString pss = getDocumentOwnerQuery ();
168+ pss .setParams (qsm );
200169
201- ResultSetRewindable docOwnerResult = loadResultSet (getApplication ().getService (), getDocumentOwnerQuery (), qsm ); // could use ASK query in principle
170+ ResultSetRewindable docOwnerResult = getEndpointAccessor ().select (pss .asQuery (), null , null );
171+ //loadResultSet(getApplication().getService(), getDocumentOwnerQuery(), qsm); // could use ASK query in principle
202172 try
203173 {
204174 return isOwner (docOwnerResult , agent );
0 commit comments