Class QueryStorage


  • public class QueryStorage
    extends Object
    Provides an interface to the private repository with the saved queries.
    Author:
    Dale Visser
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean askExists​(org.eclipse.rdf4j.repository.http.HTTPRepository repository, String queryName, String userName)  
      boolean canChange​(org.eclipse.rdf4j.model.IRI query, String currentUser)
      Determines whether the user with the given userName is allowed to update or delete the given query.
      boolean canRead​(org.eclipse.rdf4j.model.IRI query, String currentUser)
      Determines whether the user with the given userName is allowed to read the given query.
      boolean checkAccess​(org.eclipse.rdf4j.repository.http.HTTPRepository repository)
      Checks whether the current user/password credentials can really access the current repository.
      void deleteQuery​(org.eclipse.rdf4j.model.IRI query, String userName)
      Delete the given query for the given user.
      String getQueryText​(org.eclipse.rdf4j.repository.http.HTTPRepository repository, String owner, String queryName)
      Retrieves the specified query text.
      static QueryStorage getSingletonInstance​(AppConfiguration config)  
      void saveQuery​(org.eclipse.rdf4j.repository.http.HTTPRepository repository, String queryName, String userName, boolean shared, org.eclipse.rdf4j.query.QueryLanguage queryLanguage, String queryText, boolean infer, int rowsPerPage)
      Save a query.
      void selectSavedQueries​(org.eclipse.rdf4j.repository.http.HTTPRepository repository, String userName, TupleResultBuilder builder)
      Prepares a query to retrieve the queries accessible to the given user in the given repository.
      org.eclipse.rdf4j.model.IRI selectSavedQuery​(org.eclipse.rdf4j.repository.http.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​(org.eclipse.rdf4j.model.IRI query, String userName, boolean shared, org.eclipse.rdf4j.query.QueryLanguage queryLanguage, String queryText, boolean infer, int rowsPerPage)
      Update the entry for the given query.
    • Method Detail

      • getSingletonInstance

        public static QueryStorage getSingletonInstance​(AppConfiguration config)
                                                 throws org.eclipse.rdf4j.repository.RepositoryException
        Throws:
        org.eclipse.rdf4j.repository.RepositoryException
      • shutdown

        public void shutdown()
      • checkAccess

        public boolean checkAccess​(org.eclipse.rdf4j.repository.http.HTTPRepository repository)
                            throws org.eclipse.rdf4j.repository.RepositoryException
        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:
        org.eclipse.rdf4j.repository.RepositoryException - if there is an issue closing the connection
      • saveQuery

        public void saveQuery​(org.eclipse.rdf4j.repository.http.HTTPRepository repository,
                              String queryName,
                              String userName,
                              boolean shared,
                              org.eclipse.rdf4j.query.QueryLanguage queryLanguage,
                              String queryText,
                              boolean infer,
                              int rowsPerPage)
                       throws org.eclipse.rdf4j.common.exception.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 with
        queryName - the name for the query
        userName - the user saving the query
        shared - whether the query is to be shared with other users
        queryLanguage - the language of the query (only SPARQL is currently supported)
        queryText - the actual query text
        infer -
        rowsPerPage - rows to display per page, may be 0 (all), 10, 50, 100, or 200)
        Throws:
        org.eclipse.rdf4j.common.exception.RDF4JException
      • canChange

        public boolean canChange​(org.eclipse.rdf4j.model.IRI query,
                                 String currentUser)
                          throws org.eclipse.rdf4j.repository.RepositoryException,
                                 org.eclipse.rdf4j.query.QueryEvaluationException,
                                 org.eclipse.rdf4j.query.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 interest
        currentUser - the user to check access for
        Returns:
        true if the given query was saved by the given user or the anonymous user
        Throws:
        org.eclipse.rdf4j.repository.RepositoryException
        org.eclipse.rdf4j.query.QueryEvaluationException
        org.eclipse.rdf4j.query.MalformedQueryException
      • canRead

        public boolean canRead​(org.eclipse.rdf4j.model.IRI query,
                               String currentUser)
                        throws org.eclipse.rdf4j.repository.RepositoryException,
                               org.eclipse.rdf4j.query.QueryEvaluationException,
                               org.eclipse.rdf4j.query.MalformedQueryException
        Determines whether the user with the given userName is allowed to read the given query.
        Parameters:
        query - the node identifying the query of interest
        currentUser - 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:
        org.eclipse.rdf4j.repository.RepositoryException
        org.eclipse.rdf4j.query.QueryEvaluationException
        org.eclipse.rdf4j.query.MalformedQueryException
      • askExists

        public boolean askExists​(org.eclipse.rdf4j.repository.http.HTTPRepository repository,
                                 String queryName,
                                 String userName)
                          throws org.eclipse.rdf4j.query.QueryEvaluationException,
                                 org.eclipse.rdf4j.repository.RepositoryException,
                                 org.eclipse.rdf4j.query.MalformedQueryException
        Throws:
        org.eclipse.rdf4j.query.QueryEvaluationException
        org.eclipse.rdf4j.repository.RepositoryException
        org.eclipse.rdf4j.query.MalformedQueryException
      • deleteQuery

        public void deleteQuery​(org.eclipse.rdf4j.model.IRI query,
                                String userName)
                         throws org.eclipse.rdf4j.repository.RepositoryException,
                                org.eclipse.rdf4j.query.UpdateExecutionException,
                                org.eclipse.rdf4j.query.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:
        org.eclipse.rdf4j.repository.RepositoryException
        org.eclipse.rdf4j.query.UpdateExecutionException
        org.eclipse.rdf4j.query.MalformedQueryException
      • updateQuery

        public void updateQuery​(org.eclipse.rdf4j.model.IRI query,
                                String userName,
                                boolean shared,
                                org.eclipse.rdf4j.query.QueryLanguage queryLanguage,
                                String queryText,
                                boolean infer,
                                int rowsPerPage)
                         throws org.eclipse.rdf4j.repository.RepositoryException,
                                org.eclipse.rdf4j.query.UpdateExecutionException,
                                org.eclipse.rdf4j.query.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 update
        userName - the user name
        shared - whether to share with other users
        queryLanguage - the query language
        queryText - the text of the query
        infer -
        rowsPerPage - the rows per page to display of the query
        Throws:
        org.eclipse.rdf4j.repository.RepositoryException - if a problem occurs during the update
        org.eclipse.rdf4j.query.UpdateExecutionException - if a problem occurs during the update
        org.eclipse.rdf4j.query.MalformedQueryException - if a problem occurs during the update
      • selectSavedQueries

        public void selectSavedQueries​(org.eclipse.rdf4j.repository.http.HTTPRepository repository,
                                       String userName,
                                       TupleResultBuilder builder)
                                throws org.eclipse.rdf4j.repository.RepositoryException,
                                       org.eclipse.rdf4j.query.MalformedQueryException,
                                       org.eclipse.rdf4j.query.QueryEvaluationException,
                                       org.eclipse.rdf4j.query.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 against
        userName - that is requesting the saved queries
        builder - receives a list of all the saved queries against the given repository and accessible to the given user
        Throws:
        org.eclipse.rdf4j.repository.RepositoryException - if there's a problem connecting to the saved queries repository
        org.eclipse.rdf4j.query.MalformedQueryException - if the query is not legal SPARQL
        org.eclipse.rdf4j.query.QueryEvaluationException - if there is a problem while attempting to evaluate the query
        org.eclipse.rdf4j.query.QueryResultHandlerException
      • selectSavedQuery

        public org.eclipse.rdf4j.model.IRI selectSavedQuery​(org.eclipse.rdf4j.repository.http.HTTPRepository repository,
                                                            String owner,
                                                            String queryName)
                                                     throws org.eclipse.rdf4j.common.exception.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:
        org.eclipse.rdf4j.common.exception.RDF4JException - if issues occur performing the necessary queries.
        BadRequestException - if the the specified stored query doesn't exist
      • getQueryText

        public String getQueryText​(org.eclipse.rdf4j.repository.http.HTTPRepository repository,
                                   String owner,
                                   String queryName)
                            throws org.eclipse.rdf4j.common.exception.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:
        org.eclipse.rdf4j.common.exception.RDF4JException - if a problem occurs accessing storage
        BadRequestException - if the specified query doesn't exist