Class SparqlUtil

java.lang.Object
org.eclipse.lyo.trs.client.util.SparqlUtil

public class SparqlUtil extends Object
* A utility class with static methods enabling the processing of trs tasks as sparql update requests e.g. A sparql update corresponding to the removal of the old statements of a resource and the addition of the statements of its update representation can be returned in exchange for a TRS Modification Event
Author:
Omar
  • Constructor Details

    • SparqlUtil

      public SparqlUtil()
  • Method Details

    • createGraphQuery

      public static String createGraphQuery(String namedGraphUrl)
      returns the sparql query for the creation of the named graph with the given name as a String
      Parameters:
      namedGraphUrl - name of the named graph to be created
      Returns:
      the graph creation sparql query as a string
    • createGraphQuery

      public static String createGraphQuery(URI namedGraphUrl)
    • dropGraphQuery

      public static String dropGraphQuery(String namedGraphUrl)
      returns the query deleting siltently the graph with the given name
      Parameters:
      namedGraphUrl - the name of the graph to be deleted
      Returns:
      the deletion query as a string
    • removeAllTriplesInGraphQuery

      public static String removeAllTriplesInGraphQuery(String namedGraphUrl)
      returns the sparql query removing all the triples in the requested graph as a string
      Parameters:
      namedGraphUrl - graph to be emptied
      Returns:
      the query for emptying the graph
    • addTriplesToGraphQuery

      public static String addTriplesToGraphQuery(String namedGraphUrl, Model jenaModel)
      Gets an rdf model and a named graph as arguments and returns a sparql query for adding the statements of the rdf model to the named graph
      Parameters:
      namedGraphUrl - named graph to which the statements shall be added
      jenaModel - the rdf model of which statements are to be added to the named graph
      Returns:
      the sparql update
    • addTriplesToGraphQuery

      public static String addTriplesToGraphQuery(URI namedGraphUrl, Model jenaModel)
    • addTriplesToGraphQuery

      public static String addTriplesToGraphQuery(String namedGraphUrl, String triples)
      Gets a set of statements and a named graph as arguments and returns a sparql query for adding the statements to the named graph
      Parameters:
      namedGraphUrl - named graph to which the statements shall be added
      triples - statements to be added to the named graph
      Returns:
      the sparql update
    • getChangeEventQuery

      public static String getChangeEventQuery(ChangeEvent changeEvent, Model model)
      For a change event return a sparql update relfecting the change event.
      Parameters:
      changeEvent - the change event for which the sparql update is created
      model - the rdf model corresponding to the updated representation of the changed resource if applicable ( no rdf model is needed for a deletion event)
      Returns:
      the sparql update
    • getModificationEventQuery

      public static String getModificationEventQuery(ChangeEvent changeEvent, Model model)
      For a modification event return a sparql update relfecting the change event.
      Parameters:
      changeEvent - the change event for which the sparql update is created
      model - the rdf model corresponding to the updated representation of the changed resource
      Returns:
      the sparql update
    • getModificationEventQuery

      public static String getModificationEventQuery(ChangeEvent changeEvent, String triples)
      For a modification event return a sparql update relfecting the change event.
      Parameters:
      changeEvent - the change event for which the sparql update is created
      triples - the rdf model in n triples corresponding to the updated representation of the changed resource
      Returns:
      the sparql update
    • getModificationEventQuery

      public static String getModificationEventQuery(String changeEventTarget, String triples)
      For a modification event target return a sparql update relfecting the change event.
      Parameters:
      changeEventTarget - the change resource for which the sparql update is created
      triples - the rdf model in n triples corresponding to the updated representation of the changed resource
      Returns:
      the sparql update
    • getCreationEventQuery

      public static String getCreationEventQuery(ChangeEvent changeEvent, Model model)
      * For a creation event return a sparql update reflecting the change event.
      Parameters:
      changeEvent - change event for which update will be created
      model - updated rdf representation of the changed resource
      Returns:
    • getDeletionEventQuery

      public static String getDeletionEventQuery(ChangeEvent changeEvent)
      For a deletion event return a sparql update relfecting the change event.
      Parameters:
      changeEvent - the deletion change event for which the sparql update is created
      Returns:
      the sparql update
    • createGraph

      public static void createGraph(String namedGraphUrl, String serviceUrl)
      create a graph creation of the graph with the specified name sparql update and post it to the given service url
      Parameters:
      namedGraphUrl - name of the graph to be created
      serviceUrl - sparql update endpoint url
    • dropGraph

      public static void dropGraph(String namedGraphUrl, String serviceUrl)
      create a graph creation of the graph with the specified name sparql update and post it to the given service url
      Parameters:
      namedGraphUrl - name of the graph to be deleted
      serviceUrl - sparql update endpoint url
    • addTriplesToNamedGraph

      public static void addTriplesToNamedGraph(Model jenaModel, String namedGraphUrl, String serviceUrl)
      create a spaql update adding the triples in the given rdf model to the graph with the given name and send it to the specified sparql update endpoint
      Parameters:
      jenaModel - the triples to be added to the named graph
      namedGraphUrl - the named graph to which the triples shall be added
      serviceUrl - the sparql update endpoint
    • removeAllTriplesInNamedGraph

      public static void removeAllTriplesInNamedGraph(String namedGraphUrl, String serviceUrl)
      create a spaql update removing all triples from the graph with the given name and send it to the specified sparql update endpoint
      Parameters:
      namedGraphUrl - the named graph that shall be emptied
      serviceUrl - the sparql update endpoint
    • processChangeEvent

      public static void processChangeEvent(ChangeEvent changeEvent, Model model, String serviceUrl)
      create a spaql update reflecting the given change event and send it to the sparql update endpoint
      Parameters:
      changeEvent - the change event to be processed
      model - the updated representation of the changed resource if applicable
      serviceUrl - the sparql update endpoint
    • processQuery

      public static void processQuery(String query, String serviceUrl)
      Send the given sparql update to the sparql update service using the jena arq libraries
      Parameters:
      query - sparql update to be processeda
      serviceUrl - sparql update endpoint for processing the sparql update
    • processQuery_sesame

      public static void processQuery_sesame(String query, String serviceUrl, String user, String pwd)
      Send the given sparql update to the sparql update service using the sesame libraries
      Parameters:
      query - sparql update to be processeda
      serviceUrl - sparql update endpoint for processing the sparql update
      user - username for authentication if applicable
      pwd - password for authentication if applicable
    • processQuery_sesame

      public static void processQuery_sesame(String query, org.eclipse.rdf4j.repository.RepositoryConnection conn)
      Send the given sparql update to the sparql update service using the sesame libraries
      Parameters:
      query - sparql update to be processeda
      conn - the repository connection object holding credentials and the sparql update endpoint
    • getRepoConnection

      public static org.eclipse.rdf4j.repository.RepositoryConnection getRepoConnection(String queryEndpoint, String user, String pwd)
      return the repo connection object in order to be able to use the sesame client libraries
      Parameters:
      queryEndpoint - the sparl query endpoint
      user - username for authentication if applicable
      pwd - password for authentication if applicable
      Returns:
    • getRepoConnection

      public static org.eclipse.rdf4j.repository.RepositoryConnection getRepoConnection(String queryEndpoint, String updateEndPoint, String user, String pwd)
      return the repo connection object in order to be able to use the sesame client libraries
      Parameters:
      queryEndpoint - the sparl query endpoint
      user - username for authentication if applicable
      pwd - password for authentication if applicable
      Returns:
    • evalQuery

      public static org.eclipse.rdf4j.query.TupleQueryResult evalQuery(String queryEndpoint, String user, String pwd, String query)
      evaluate the given sparql query against the given sparql query endpoint
      Parameters:
      queryEndpoint - sparql query endpoint
      user - username for authentication if applicable
      pwd - password for authentication if applicable
      query - sparql query
      Returns:
      the result of the querie's evaluation
    • evalUpdate

      public static void evalUpdate(org.eclipse.rdf4j.repository.RepositoryConnection conn, String sparqlQuery)
      evaluate the given sparql update using the sesame repository connection object
      Parameters:
      conn - repo connection sesame object
      sparqlQuery - sparql update to evaluate
    • evalQuery

      public static org.eclipse.rdf4j.query.TupleQueryResult evalQuery(org.eclipse.rdf4j.repository.RepositoryConnection conn, String sparqlQuery)
      evaluate the given sparql query using the sesame repository connection object
      Parameters:
      conn - repo connection sesame object
      sparqlQuery - sparql query to evaluate
      Returns:
      the queri's evaluation result
    • appendSparqldQuery

      public static String appendSparqldQuery(String appending, String appended)
      append a sparql update to another
      Parameters:
      appending - the original sparql update
      appended - the sparql update to be appended
      Returns:
      the concatnated sparql update
    • processTripleAdditionQuery

      public void processTripleAdditionQuery(org.eclipse.rdf4j.repository.RepositoryConnection conn, String triples, String graphName)
      Create a sparql update ading the triples to the named graph with the specified name and send it to the sparql update endpoint specified using the given repo connection object. Uses the sesame libraries
      Parameters:
      conn - sesame repo connection object
      triples - triples to be added to the named graph
      graphName - named graph to which the triples shall be added
    • linkTriple

      public static String linkTriple(String src, String dst, String linkType)
      Create a triple with the link type as a predicate the src as subject and destination as object. This is a conveniece for enabling the creation of links in a ageneric way
      Parameters:
      src - source of the link
      dst - destination of the link
      linkType - type of the link
      Returns:
      the rdf triple as n triple