Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use Lyo Store in TRS Client #388

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
### Added

- Introducing capability to set the servletUri to be used by the OAuthConfiguration
- `Store.rawUpdateQuery(String)` allows making raw SPARQL UPDATE queries.

### Changed

- TRS Client uses Lyo Store instead of using Eclipse RDF4J directly.
- Kotlin 1.9.0 is used; `kotlin-stdlib-jdk8` dependency was replaced with `kotlin-stdlib` due to [Kotlin updates](https://kotlinlang.org/docs/whatsnew18.html#updated-jvm-compilation-target).
- Allow application to reset the oauth token cached within the server, when it deems that it is no longer valid
- 🧨Corrected cardinality and range of the oslc_config:acceptedBy property (from String[0..1] to Resource[0..*])
Expand All @@ -17,6 +19,7 @@
### Removed

- 🧨 Support for JDK 11 (and all versions below 17) is removed. **JDK 17 is the new baseline for Eclipse Lyo.** The SDK and sample code has been tested using JDK 17, 20, and 21-ea.
- TRS Client no longer depends on Eclipse RDF4J. Helper methods for RDF4J were also removed.

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,11 @@ default <T extends IResource> boolean appendResource(URI namedGraphUri, final T
* @since 4.1.0
*/
void close();

/**
* Execute a raw SPARQL query against the UPDATE endpoint.
*
* @param finalQueryString
*/
void rawUpdateQuery(String finalQueryString);
}
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@ public void close() {
log.debug("Underlying SPARQL connection has been released");
}

@Override
public void rawUpdateQuery(String finalQueryString) {
queryExecutor.prepareSparqlUpdate(finalQueryString).execute();
}

private <T extends IResource> String oslcQueryPrefixes(final Class<T> clazz) {
return "rdf=" + "<" + org.apache.jena.vocabulary.RDF.uri + ">";
}
Expand Down
10 changes: 6 additions & 4 deletions trs/client/trs-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-repository-sparql</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
Expand All @@ -139,6 +135,12 @@
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.lyo.store</groupId>
<artifactId>store-core</artifactId>
<version>6.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.List;
import org.eclipse.lyo.core.trs.ChangeEvent;
import org.eclipse.lyo.core.trs.Deletion;
import org.eclipse.lyo.store.Store;
import org.eclipse.lyo.store.StoreFactory;
import org.eclipse.lyo.trs.client.handlers.IProviderEventHandler;
import org.eclipse.lyo.trs.client.model.BaseMember;
import org.eclipse.lyo.trs.client.model.ChangeEventMessageTR;
Expand All @@ -30,11 +32,18 @@ public SparqlBatchingHandler(final String sparqlUpdateService,
@Override
public void finishCycle() {
log.debug("number of processed queries: " + queries.size());
String finalQueryString = buildYugeQuery(queries);
String updateQuery = buildYugeQuery(queries);
log.debug("sending Update SPARQL Query to server");

SparqlUtil.processQuery_sesame(finalQueryString, sparqlUpdateService,
sparql_baseAuth_userName, sparql_baseAuth_pwd);
// TODO: build one or use a pool
Store store = StoreFactory.sparql(null, sparqlUpdateService,
sparql_baseAuth_userName, sparql_baseAuth_pwd);
try {
store.rawUpdateQuery(updateQuery);
} finally {
store.close();
}

log.debug("Update SPARQL Queries successful!");

queries.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@
import org.eclipse.lyo.core.trs.Creation;
import org.eclipse.lyo.core.trs.Deletion;
import org.eclipse.lyo.core.trs.Modification;
import org.eclipse.rdf4j.query.QueryLanguage;
import org.eclipse.rdf4j.query.TupleQueryResult;
import org.eclipse.rdf4j.query.Update;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.sparql.SPARQLRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -393,13 +388,13 @@ static public void processQuery(String query, String serviceUrl) {
* @param pwd
* password for authentication if applicable
*/
static public void processQuery_sesame(String query, String serviceUrl, String user, String pwd) {
SPARQLRepository repo = new SPARQLRepository(serviceUrl);
repo.setUsernameAndPassword(user, pwd);
repo.initialize();
RepositoryConnection rc = repo.getConnection();
processQuery_sesame(query, rc);
}
// static public void processQuery_sesame(String query, String serviceUrl, String user, String pwd) {
// SPARQLRepository repo = new SPARQLRepository(serviceUrl);
// repo.setUsernameAndPassword(user, pwd);
// repo.initialize();
// RepositoryConnection rc = repo.getConnection();
// processQuery_sesame(query, rc);
// }

/**
* Send the given sparql update to the sparql update service using the
Expand All @@ -411,10 +406,10 @@ static public void processQuery_sesame(String query, String serviceUrl, String u
* the repository connection object holding credentials and the
* sparql update endpoint
*/
static public void processQuery_sesame(String query, RepositoryConnection conn) {
Update u = conn.prepareUpdate(query);
u.execute();
}
// static public void processQuery_sesame(String query, RepositoryConnection conn) {
// Update u = conn.prepareUpdate(query);
// u.execute();
// }

/**
* return the repo connection object in order to be able to use the sesame
Expand All @@ -428,23 +423,23 @@ static public void processQuery_sesame(String query, RepositoryConnection conn)
* password for authentication if applicable
* @return
*/
public static RepositoryConnection getRepoConnection(String queryEndpoint, String user, String pwd) {
SPARQLRepository repo = new SPARQLRepository(queryEndpoint);
if (user != null && pwd != null && !user.isEmpty() && !pwd.isEmpty()) {
repo.setUsernameAndPassword("okacimi", "nohheis4ae");
}
repo.initialize();
try {
RepositoryConnection conn = repo.getConnection();
if (conn == null) {
logger.error("error getting sparql repo connection !");
}
return conn;
} catch (Exception e) {
logger.error("error getting sparql repo connection !", e);
return null;
}
}
// public static RepositoryConnection getRepoConnection(String queryEndpoint, String user, String pwd) {
// SPARQLRepository repo = new SPARQLRepository(queryEndpoint);
// if (user != null && pwd != null && !user.isEmpty() && !pwd.isEmpty()) {
// repo.setUsernameAndPassword("okacimi", "nohheis4ae");
// }
// repo.initialize();
// try {
// RepositoryConnection conn = repo.getConnection();
// if (conn == null) {
// logger.error("error getting sparql repo connection !");
// }
// return conn;
// } catch (Exception e) {
// logger.error("error getting sparql repo connection !", e);
// return null;
// }
// }

/**
* return the repo connection object in order to be able to use the sesame
Expand All @@ -458,25 +453,25 @@ public static RepositoryConnection getRepoConnection(String queryEndpoint, Strin
* password for authentication if applicable
* @return
*/
public static RepositoryConnection getRepoConnection(String queryEndpoint, String updateEndPoint, String user,
String pwd) {
SPARQLRepository repo = new SPARQLRepository(queryEndpoint, updateEndPoint);
if (user != null && pwd != null && !user.isEmpty() && !pwd.isEmpty() && !user.isEmpty()) {
repo.setUsernameAndPassword(user, pwd);
}
repo.initialize();
try {
RepositoryConnection conn = repo.getConnection();

if (conn == null) {
logger.error("error getting sparql repo connection !");
}
return conn;
} catch (Exception e) {
logger.error("error getting sparql repo connection !", e);
return null;
}
}
// public static RepositoryConnection getRepoConnection(String queryEndpoint, String updateEndPoint, String user,
// String pwd) {
// SPARQLRepository repo = new SPARQLRepository(queryEndpoint, updateEndPoint);
// if (user != null && pwd != null && !user.isEmpty() && !pwd.isEmpty() && !user.isEmpty()) {
// repo.setUsernameAndPassword(user, pwd);
// }
// repo.initialize();
// try {
// RepositoryConnection conn = repo.getConnection();
//
// if (conn == null) {
// logger.error("error getting sparql repo connection !");
// }
// return conn;
// } catch (Exception e) {
// logger.error("error getting sparql repo connection !", e);
// return null;
// }
// }

/**
* evaluate the given sparql query against the given sparql query endpoint
Expand All @@ -491,19 +486,19 @@ public static RepositoryConnection getRepoConnection(String queryEndpoint, Strin
* sparql query
* @return the result of the querie's evaluation
*/
public static TupleQueryResult evalQuery(String queryEndpoint, String user, String pwd, String query) {
RepositoryConnection conn = getRepoConnection(queryEndpoint, user, pwd, query);
TupleQueryResult result = null;
try {

result = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
} catch (Exception e) {
logger.error("error during the execution of the query !", e);
} finally {
conn.close();
}
return result;
}
// public static TupleQueryResult evalQuery(String queryEndpoint, String user, String pwd, String query) {
// RepositoryConnection conn = getRepoConnection(queryEndpoint, user, pwd, query);
// TupleQueryResult result = null;
// try {
//
// result = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
// } catch (Exception e) {
// logger.error("error during the execution of the query !", e);
// } finally {
// conn.close();
// }
// return result;
// }

/**
* evaluate the given sparql update using the sesame repository connection
Expand All @@ -514,14 +509,14 @@ public static TupleQueryResult evalQuery(String queryEndpoint, String user, Stri
* @param sparqlQuery
* sparql update to evaluate
*/
public static void evalUpdate(RepositoryConnection conn, String sparqlQuery) {
try {

conn.prepareUpdate(QueryLanguage.SPARQL, sparqlQuery).execute();
} catch (Exception e) {
logger.error("error during the execution of the query !", e);
}
}
// public static void evalUpdate(RepositoryConnection conn, String sparqlQuery) {
// try {
//
// conn.prepareUpdate(QueryLanguage.SPARQL, sparqlQuery).execute();
// } catch (Exception e) {
// logger.error("error during the execution of the query !", e);
// }
// }

/**
* evaluate the given sparql query using the sesame repository connection
Expand All @@ -533,18 +528,18 @@ public static void evalUpdate(RepositoryConnection conn, String sparqlQuery) {
* sparql query to evaluate
* @return the queri's evaluation result
*/
public static TupleQueryResult evalQuery(RepositoryConnection conn, String sparqlQuery) {
TupleQueryResult result = null;
try {

result = conn.prepareTupleQuery(QueryLanguage.SPARQL, sparqlQuery).evaluate();

} catch (Exception e) {
logger.error("error during the execution of the query !", e);
}

return result;
}
// public static TupleQueryResult evalQuery(RepositoryConnection conn, String sparqlQuery) {
// TupleQueryResult result = null;
// try {
//
// result = conn.prepareTupleQuery(QueryLanguage.SPARQL, sparqlQuery).evaluate();
//
// } catch (Exception e) {
// logger.error("error during the execution of the query !", e);
// }
//
// return result;
// }

/**
* append a sparql update to another
Expand Down Expand Up @@ -583,10 +578,10 @@ public static String appendSparqldQuery(String appending, String appended) {
* @param graphName
* named graph to which the triples shall be added
*/
public void processTripleAdditionQuery(RepositoryConnection conn, String triples, String graphName) {
String addTriplesToGraphQuery = SparqlUtil.addTriplesToGraphQuery(graphName, triples);
SparqlUtil.processQuery_sesame(addTriplesToGraphQuery, conn);
}
// public void processTripleAdditionQuery(RepositoryConnection conn, String triples, String graphName) {
// String addTriplesToGraphQuery = SparqlUtil.addTriplesToGraphQuery(graphName, triples);
// SparqlUtil.processQuery_sesame(addTriplesToGraphQuery, conn);
// }

/**
* Create a triple with the link type as a predicate the src as subject and
Expand Down