Package org.eclipse.rdf4j.workbench.util
Class QueryStorage
java.lang.Object
org.eclipse.rdf4j.workbench.util.QueryStorage
Provides an interface to the private repository with the saved queries.
- Author:
- Dale Visser
-
Method Summary
Modifier and TypeMethodDescriptionboolean
askExists
(HTTPRepository repository, String queryName, String userName) boolean
Determines whether the user with the given userName is allowed to update or delete the given query.boolean
Determines whether the user with the given userName is allowed to read the given query.boolean
checkAccess
(HTTPRepository repository) Checks whether the current user/password credentials can really access the current repository.void
deleteQuery
(IRI query, String userName) Delete the given query for the given user.getQueryText
(HTTPRepository repository, String owner, String queryName) Retrieves the specified query text.static QueryStorage
getSingletonInstance
(AppConfiguration config) void
saveQuery
(HTTPRepository repository, String queryName, String userName, boolean shared, QueryLanguage queryLanguage, String queryText, boolean infer, int rowsPerPage) Save a query.void
selectSavedQueries
(HTTPRepository repository, String userName, TupleResultBuilder builder) Prepares a query to retrieve the queries accessible to the given user in the given repository.selectSavedQuery
(HTTPRepository repository, String owner, String queryName) Returns the URI for the saved query in the given repository with the given name, owned by the given owner.void
shutdown()
void
updateQuery
(IRI query, String userName, boolean shared, QueryLanguage queryLanguage, String queryText, boolean infer, int rowsPerPage) Update the entry for the given query.
-
Method Details
-
getSingletonInstance
- Throws:
RepositoryException
-
shutdown
public void shutdown() -
checkAccess
Checks whether the current user/password credentials can really access the current repository.- Parameters:
repository
- the current repository- Returns:
- true, if it is possible to request a statement from the repository with the given credentials
- Throws:
RepositoryException
- if there is an issue closing the connection
-
saveQuery
public void saveQuery(HTTPRepository repository, String queryName, String userName, boolean shared, QueryLanguage queryLanguage, String queryText, boolean infer, int rowsPerPage) throws RDF4JException Save a query. UNSAFE from an injection point of view. It is the responsibility of the calling code to call checkAccess() with the full credentials first.- Parameters:
repository
- the repository the query is associated withqueryName
- the name for the queryuserName
- the user saving the queryshared
- whether the query is to be shared with other usersqueryLanguage
- the language of the query (only SPARQL is currently supported)queryText
- the actual query textinfer
-rowsPerPage
- rows to display per page, may be 0 (all), 10, 50, 100, or 200)- Throws:
RDF4JException
-
canChange
public boolean canChange(IRI query, String currentUser) throws RepositoryException, QueryEvaluationException, MalformedQueryException Determines whether the user with the given userName is allowed to update or delete the given query.- Parameters:
query
- the node identifying the query of interestcurrentUser
- the user to check access for- Returns:
- true if the given query was saved by the given user or the anonymous user
- Throws:
RepositoryException
QueryEvaluationException
MalformedQueryException
-
canRead
public boolean canRead(IRI query, String currentUser) throws RepositoryException, QueryEvaluationException, MalformedQueryException Determines whether the user with the given userName is allowed to read the given query.- Parameters:
query
- the node identifying the query of interestcurrentUser
- the user to check access for- Returns:
- true if the given query was saved by either the given user or the anonymous user, or is shared
- Throws:
RepositoryException
QueryEvaluationException
MalformedQueryException
-
askExists
public boolean askExists(HTTPRepository repository, String queryName, String userName) throws QueryEvaluationException, RepositoryException, MalformedQueryException -
deleteQuery
public void deleteQuery(IRI query, String userName) throws RepositoryException, UpdateExecutionException, MalformedQueryException Delete the given query for the given user. It is the responsibility of the calling code to call checkAccess() and canDelete() with the full credentials first.- Parameters:
query
-userName
-- Throws:
RepositoryException
UpdateExecutionException
MalformedQueryException
-
updateQuery
public void updateQuery(IRI query, String userName, boolean shared, QueryLanguage queryLanguage, String queryText, boolean infer, int rowsPerPage) throws RepositoryException, UpdateExecutionException, MalformedQueryException Update the entry for the given query. It is the responsibility of the calling code to call checkAccess() with the full credentials first.- Parameters:
query
- the query to updateuserName
- the user nameshared
- whether to share with other usersqueryLanguage
- the query languagequeryText
- the text of the queryinfer
-rowsPerPage
- the rows per page to display of the query- Throws:
RepositoryException
- if a problem occurs during the updateUpdateExecutionException
- if a problem occurs during the updateMalformedQueryException
- if a problem occurs during the update
-
selectSavedQueries
public void selectSavedQueries(HTTPRepository repository, String userName, TupleResultBuilder builder) throws RepositoryException, MalformedQueryException, QueryEvaluationException, QueryResultHandlerException Prepares a query to retrieve the queries accessible to the given user in the given repository. When evaluated, the query result will have the following binding names: query, user, queryName, shared, queryLn, queryText, rowsPerPage. It is the responsibility of the calling code to call checkAccess() with the full credentials first.- Parameters:
repository
- that the saved queries run againstuserName
- that is requesting the saved queriesbuilder
- receives a list of all the saved queries against the given repository and accessible to the given user- Throws:
RepositoryException
- if there's a problem connecting to the saved queries repositoryMalformedQueryException
- if the query is not legal SPARQLQueryEvaluationException
- if there is a problem while attempting to evaluate the queryQueryResultHandlerException
-
selectSavedQuery
public IRI selectSavedQuery(HTTPRepository repository, String owner, String queryName) throws RDF4JException, BadRequestException Returns the URI for the saved query in the given repository with the given name, owned by the given owner.- Parameters:
repository
- The repository the query is associated with.owner
- The user that saved the query.queryName
- The name given to the query.- Returns:
- if it exists, the URI referring to the specified saved query.
- Throws:
RDF4JException
- if issues occur performing the necessary queries.BadRequestException
- if the the specified stored query doesn't exist
-
getQueryText
public String getQueryText(HTTPRepository repository, String owner, String queryName) throws RDF4JException, BadRequestException Retrieves the specified query text. No security checks are done here. If the saved query exists, its text is returned.- Parameters:
repository
- Repository that the saved query is associated with.owner
- The user that saved the query.queryName
- The name given to the saved query.- Returns:
- the text of the saved query, if it exists
- Throws:
RDF4JException
- if a problem occurs accessing storageBadRequestException
- if the specified query doesn't exist
-