From f64940e73aa6281eb6dc21e432158a484043dd63 Mon Sep 17 00:00:00 2001 From: Dennis Schiese Date: Wed, 8 May 2024 16:13:23 +0200 Subject: [PATCH 01/10] Adjusted QanaryTripleStoreConnectorQanaryInternal to store component name --- ...aryTripleStoreConnectorQanaryInternal.java | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorQanaryInternal.java b/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorQanaryInternal.java index de027ace..813f8210 100644 --- a/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorQanaryInternal.java +++ b/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorQanaryInternal.java @@ -2,17 +2,32 @@ import java.net.URI; import java.net.URISyntaxException; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.util.ArrayList; +import java.util.List; +import com.google.api.client.util.Lists; +import com.stardog.stark.vocabs.RDF; +import org.apache.http.Header; +import org.apache.http.HttpHeaders; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.message.BasicHeader; import org.apache.jena.query.QueryExecution; import org.apache.jena.query.ResultSet; import org.apache.jena.query.ResultSetFactory; import org.apache.jena.query.ResultSetRewindable; import org.apache.jena.rdfconnection.RDFConnection; +import org.apache.jena.rdfconnection.RDFConnectionRemote; +import org.apache.jena.rdfconnection.RDFConnectionRemoteBuilder; import org.apache.jena.sparql.exec.QueryExecBuilder; // QueryExecBuilder is required for RDFConnection import org.slf4j.Logger; import org.slf4j.LoggerFactory; import eu.wdaqua.qanary.exceptions.SparqlQueryFailed; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpEntity; /** * simple connection to open endpoint without authorization using the Apache Jena library @@ -24,12 +39,24 @@ public class QanaryTripleStoreConnectorQanaryInternal extends QanaryTripleStoreC private static final Logger logger = LoggerFactory.getLogger(QanaryTripleStoreConnectorQanaryInternal.class); private URI endpoint; private RDFConnection connection; + private String applicationName; + @Value("${data.logging") + private boolean dataLogging; - public QanaryTripleStoreConnectorQanaryInternal(URI endpoint) throws URISyntaxException { + public QanaryTripleStoreConnectorQanaryInternal(URI endpoint, String applicationName) throws URISyntaxException { + this.setApplicationName(applicationName); this.endpoint = endpoint; this.connect(); } + public String getApplicationName() { + return applicationName; + } + + private void setApplicationName(String applicationName) { + this.applicationName = applicationName; // set to "urn:qanary:" + name // Check vulnerabilities + } + private URI getEndpoint() { return this.endpoint; } @@ -38,11 +65,23 @@ private URI getEndpoint() { public void connect() { org.apache.jena.query.ARQ.init(); // maybe it helps to prevent problems? this.connection = RDFConnection.connect(this.getEndpoint().toASCIIString()); + /* TODO; RDFConnectionRemote doesn't accept org.apache.jena.HttpClient/ClosedHttpClient anymore, instead it uses java.HttpClient + TODO; ClosedHttpClient cannot be casted into HttpClient. Therefore, it is not possible to pass the Header as + TODO; java.HttpClient doesn't consist a header, but a HttpRequest does. + TODO; QueryExecution (Jena) instead still accept a org.jena.HttpClient where a header can be added. + Header header = new BasicHeader("QANARY_COMPONENT_LOGGING", String.valueOf(dataLogging)); + List
headers = new ArrayList<>() {{add(header);}}; + org.apache.http.client.HttpClient httpClient = HttpClients.custom().setDefaultHeaders(headers).build(); + + RDFConnection rdfConnection = RDFConnectionRemote.newBuilder().destination(this.getEndpoint().toASCIIString()).httpClient((HttpClient) httpClient).build(); + this.connection = rdfConnection; + */ } @Override public ResultSet select(String sparql) throws SparqlQueryFailed { QueryExecution queryExecution = this.connection.query(sparql); + getLogger().warn("Component name: {} with Select query: {}", this.applicationName, queryExecution.getQuery().toString()); ResultSet myResultSet = queryExecution.execSelect(); ResultSetRewindable resultSet = ResultSetFactory.makeRewindable(myResultSet); return resultSet; From c5ff6d305684188659197e46063147990808e2b2 Mon Sep 17 00:00:00 2001 From: Dennis Schiese Date: Wed, 8 May 2024 16:39:58 +0200 Subject: [PATCH 02/10] Added logging mechanism --- ...aryTripleStoreConnectorQanaryInternal.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorQanaryInternal.java b/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorQanaryInternal.java index 813f8210..4caea36b 100644 --- a/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorQanaryInternal.java +++ b/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorQanaryInternal.java @@ -1,5 +1,6 @@ package eu.wdaqua.qanary.commons.triplestoreconnectors; +import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.http.HttpClient; @@ -14,14 +15,14 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.message.BasicHeader; -import org.apache.jena.query.QueryExecution; -import org.apache.jena.query.ResultSet; -import org.apache.jena.query.ResultSetFactory; -import org.apache.jena.query.ResultSetRewindable; +import org.apache.jena.query.*; +import org.apache.jena.rdf.model.ResourceFactory; import org.apache.jena.rdfconnection.RDFConnection; import org.apache.jena.rdfconnection.RDFConnectionRemote; import org.apache.jena.rdfconnection.RDFConnectionRemoteBuilder; import org.apache.jena.sparql.exec.QueryExecBuilder; // QueryExecBuilder is required for RDFConnection +import org.apache.jena.update.UpdateFactory; +import org.apache.jena.update.UpdateRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -81,12 +82,27 @@ public void connect() { @Override public ResultSet select(String sparql) throws SparqlQueryFailed { QueryExecution queryExecution = this.connection.query(sparql); - getLogger().warn("Component name: {} with Select query: {}", this.applicationName, queryExecution.getQuery().toString()); + logData(sparql); ResultSet myResultSet = queryExecution.execSelect(); ResultSetRewindable resultSet = ResultSetFactory.makeRewindable(myResultSet); return resultSet; } + private void logData(String sparql) { + QuerySolutionMap querySolutionMap = new QuerySolutionMap(); + Query query = QueryFactory.create(sparql); + querySolutionMap.add("graph",ResourceFactory.createResource(query.getGraphURIs().get(0))); + querySolutionMap.add("component", ResourceFactory.createResource("urn:qanary:" + this.applicationName)); + querySolutionMap.add("questionID", ResourceFactory.createResource("urn:qanary:currentQuestion")); + querySolutionMap.add("body", ResourceFactory.createPlainLiteral(sparql)); + try { + this.update(QanaryTripleStoreConnector.readFileFromResourcesWithMap("/queries/insert_explanation_data_sparql_query.rq", querySolutionMap)); + } catch(Exception e) { + getLogger().error("Logging failed, {}", e); + } + + } + @Override public void update(String sparql, URI graph) throws SparqlQueryFailed { this.update(sparql); From 49e3981ae13ff8a8a50a6e8a9ea516946ed1b8eb Mon Sep 17 00:00:00 2001 From: Dennis Schiese Date: Tue, 14 May 2024 09:26:45 +0200 Subject: [PATCH 03/10] Added questionID to explanation-log query, removed old approaches --- .../QanaryTripleStoreConnector.java | 30 ++----------------- .../QanaryTripleStoreConnectorVirtuoso.java | 10 ++----- .../insert_explanation_data_sparql_query.rq | 1 + 3 files changed, 6 insertions(+), 35 deletions(-) diff --git a/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnector.java b/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnector.java index 32db2e67..ac9b412b 100644 --- a/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnector.java +++ b/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnector.java @@ -6,6 +6,8 @@ import java.io.InputStreamReader; import java.net.URI; import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.Map; import java.util.stream.Collectors; import eu.wdaqua.qanary.commons.QanaryUtils; @@ -22,21 +24,13 @@ import eu.wdaqua.qanary.exceptions.SparqlQueryFailed; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; public abstract class QanaryTripleStoreConnector { private static final Logger logger = LoggerFactory.getLogger(QanaryTripleStoreConnector.class); private static final long MAX_ACCEPTABLE_QUERY_EXECUTION_TIME = 10000; - private String processGraph; - private String processComponent; - - public void setProcessInformation(String processGraph, String processComponent) { - this.processGraph = processGraph; - this.processComponent = processComponent; - logger.info("Processed information: {} {}", this.processComponent, this.processGraph); - } - public abstract void connect(); // TODO: add exception public abstract ResultSet select(String sparql) throws SparqlQueryFailed; @@ -47,24 +41,6 @@ public void setProcessInformation(String processGraph, String processComponent) public abstract void update(String sparql) throws SparqlQueryFailed; - public void storeProcessedData(String body) throws URISyntaxException, SparqlQueryFailed, IOException { - try { - URI graph = new URI(processGraph); - // use Query file and insert values - QuerySolutionMap querySolutionMap = new QuerySolutionMap(); - querySolutionMap.add("body", ResourceFactory.createPlainLiteral(body)); - querySolutionMap.add("graph", ResourceFactory.createResource(graph.toASCIIString())); - querySolutionMap.add("component", ResourceFactory.createPlainLiteral(processComponent)); - String query = this.readFileFromResourcesWithMap("/queries/insert_explanation_data_sparql_query.rq", querySolutionMap); - logger.info("Explanation query: {}", query); - // insert annotation to triplestore - this.update(query, graph); - } catch(Exception e) { - logger.error("{}", e.toString()); - e.printStackTrace(); - } - } - /** * return a readable description of the triplestore endpoint * diff --git a/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorVirtuoso.java b/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorVirtuoso.java index b7c0e013..593cadfe 100644 --- a/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorVirtuoso.java +++ b/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorVirtuoso.java @@ -3,11 +3,7 @@ import java.net.URI; import java.util.concurrent.TimeUnit; -import org.apache.jena.query.Query; -import org.apache.jena.query.QueryFactory; -import org.apache.jena.query.ResultSet; -import org.apache.jena.query.ResultSetFactory; -import org.apache.jena.query.ResultSetRewindable; +import org.apache.jena.query.*; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; @@ -132,9 +128,7 @@ public ResultSet select(String sparql) throws SparqlQueryFailed { // try N times if there was a timeout while(numberOfTries < this.maxTriesConnectionTimeout || numberOfTries == 0) { try { - ResultSet rs = this.select(sparql, numberOfTries); - this.storeProcessedData(sparql); - return rs; + return this.select(sparql, numberOfTries); } catch (Exception e) { getLogger().error("Error while executing a SELECT query: {}", e.getMessage()); e.printStackTrace(); diff --git a/qanary_commons/src/main/resources/queries/insert_explanation_data_sparql_query.rq b/qanary_commons/src/main/resources/queries/insert_explanation_data_sparql_query.rq index 16130447..f38bee3d 100644 --- a/qanary_commons/src/main/resources/queries/insert_explanation_data_sparql_query.rq +++ b/qanary_commons/src/main/resources/queries/insert_explanation_data_sparql_query.rq @@ -9,6 +9,7 @@ GRAPH ?graph { ?newAnnotation oa:hasBody ?body . ?newAnnotation oa:annotatedAt ?time . ?newAnnotation oa:annotatedBy ?component . + ?newAnnotation oa:hasTarget ?questionID . } } WHERE { From c3fa15e671e1b9b0d73ce2ceed62c7bcb0bcc1ea Mon Sep 17 00:00:00 2001 From: Dennis Schiese Date: Tue, 14 May 2024 09:29:20 +0200 Subject: [PATCH 04/10] Extended ASK-method --- .../QanaryTripleStoreConnectorQanaryInternal.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorQanaryInternal.java b/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorQanaryInternal.java index 4caea36b..374c857c 100644 --- a/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorQanaryInternal.java +++ b/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorQanaryInternal.java @@ -115,7 +115,8 @@ public void update(String sparql) throws SparqlQueryFailed { } @Override - public boolean ask(String sparql) throws SparqlQueryFailed { + public boolean ask(String sparql) throws SparqlQueryFailed { + logData(sparql); return this.connection.queryAsk(sparql); } From 91af4b29ee1262e7d2715fdcd63de8f686e4beca Mon Sep 17 00:00:00 2001 From: Dennis Schiese Date: Tue, 14 May 2024 09:46:29 +0200 Subject: [PATCH 05/10] Added missing change --- .../java/eu/wdaqua/qanary/component/QanaryComponent.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/qanary_component-template/src/main/java/eu/wdaqua/qanary/component/QanaryComponent.java b/qanary_component-template/src/main/java/eu/wdaqua/qanary/component/QanaryComponent.java index f68f9c7e..b1372b83 100644 --- a/qanary_component-template/src/main/java/eu/wdaqua/qanary/component/QanaryComponent.java +++ b/qanary_component-template/src/main/java/eu/wdaqua/qanary/component/QanaryComponent.java @@ -33,6 +33,10 @@ public abstract class QanaryComponent { public Environment getEnvironment() { return this.env; } + + public String getApplicationName() { + return this.env.getProperty("spring.application.name"); + } /** @@ -66,7 +70,7 @@ public QanaryUtils getUtils() { */ public QanaryUtils getUtils(QanaryMessage qanaryMessage) { try { - return new QanaryUtils(qanaryMessage, new QanaryTripleStoreConnectorQanaryInternal(qanaryMessage.getEndpoint())); + return new QanaryUtils(qanaryMessage, new QanaryTripleStoreConnectorQanaryInternal(qanaryMessage.getEndpoint(),this.getApplicationName())); } catch (Exception e) { throw new RuntimeException(e); // TODO: not needed --> replace } @@ -84,7 +88,7 @@ public QanaryUtils getUtils(QanaryMessage qanaryMessage, QanaryTripleStoreConnec */ public QanaryQuestion getQanaryQuestion(QanaryMessage qanaryMessage) { try { - return new QanaryQuestion(qanaryMessage, new QanaryTripleStoreConnectorQanaryInternal(qanaryMessage.getEndpoint())); + return new QanaryQuestion(qanaryMessage, new QanaryTripleStoreConnectorQanaryInternal(qanaryMessage.getEndpoint(), this.getApplicationName())); } catch (Exception e) { throw new RuntimeException(e); // TODO: not needed --> replace } From a2ce96b372e6f575282ecde446a82394f9357f50 Mon Sep 17 00:00:00 2001 From: Dennis Schiese Date: Tue, 21 May 2024 15:16:51 +0200 Subject: [PATCH 06/10] Increment version for commons, adjusted range for component-template and pipeline-template --- qanary_component-template/pom.xml | 2 +- qanary_pipeline-template/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/qanary_component-template/pom.xml b/qanary_component-template/pom.xml index bff4940a..de17f2c4 100644 --- a/qanary_component-template/pom.xml +++ b/qanary_component-template/pom.xml @@ -93,7 +93,7 @@ eu.wdaqua.qanary qa.commons - [3.11.2,4.0.0) + [3.13.0,4.0.0) diff --git a/qanary_pipeline-template/pom.xml b/qanary_pipeline-template/pom.xml index f6ac216c..4acb7703 100644 --- a/qanary_pipeline-template/pom.xml +++ b/qanary_pipeline-template/pom.xml @@ -27,7 +27,7 @@ eu.wdaqua.qanary qa.commons - ${qanary.version} + [3.13.0,4.0.0) de.codecentric From 7cf416bbab84c621b507450d98e0654f8ec06933 Mon Sep 17 00:00:00 2001 From: Dennis Schiese Date: Tue, 21 May 2024 15:17:14 +0200 Subject: [PATCH 07/10] Increment version for commons, adjusted range for component-template and pipeline-template --- qanary_commons/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qanary_commons/pom.xml b/qanary_commons/pom.xml index c46c3413..79fe46cc 100644 --- a/qanary_commons/pom.xml +++ b/qanary_commons/pom.xml @@ -2,7 +2,7 @@ 4.0.0 eu.wdaqua.qanary qa.commons - 3.12.1 + 3.13.0 org.springframework.boot spring-boot-starter-parent From 4cab6f97ac19702522142e100a2b214161c28e1a Mon Sep 17 00:00:00 2001 From: Dennis Schiese Date: Tue, 21 May 2024 15:24:31 +0200 Subject: [PATCH 08/10] Adjusted code --- .../QanaryTripleStoreConnectorQanaryInternal.java | 15 ++------------- .../QanaryTripleStoreConnectorVirtuoso.java | 6 +++++- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorQanaryInternal.java b/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorQanaryInternal.java index 374c857c..2c5cc754 100644 --- a/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorQanaryInternal.java +++ b/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorQanaryInternal.java @@ -55,7 +55,7 @@ public String getApplicationName() { } private void setApplicationName(String applicationName) { - this.applicationName = applicationName; // set to "urn:qanary:" + name // Check vulnerabilities + this.applicationName = "urn:qanary:" + applicationName; } private URI getEndpoint() { @@ -66,17 +66,6 @@ private URI getEndpoint() { public void connect() { org.apache.jena.query.ARQ.init(); // maybe it helps to prevent problems? this.connection = RDFConnection.connect(this.getEndpoint().toASCIIString()); - /* TODO; RDFConnectionRemote doesn't accept org.apache.jena.HttpClient/ClosedHttpClient anymore, instead it uses java.HttpClient - TODO; ClosedHttpClient cannot be casted into HttpClient. Therefore, it is not possible to pass the Header as - TODO; java.HttpClient doesn't consist a header, but a HttpRequest does. - TODO; QueryExecution (Jena) instead still accept a org.jena.HttpClient where a header can be added. - Header header = new BasicHeader("QANARY_COMPONENT_LOGGING", String.valueOf(dataLogging)); - List
headers = new ArrayList<>() {{add(header);}}; - org.apache.http.client.HttpClient httpClient = HttpClients.custom().setDefaultHeaders(headers).build(); - - RDFConnection rdfConnection = RDFConnectionRemote.newBuilder().destination(this.getEndpoint().toASCIIString()).httpClient((HttpClient) httpClient).build(); - this.connection = rdfConnection; - */ } @Override @@ -92,7 +81,7 @@ private void logData(String sparql) { QuerySolutionMap querySolutionMap = new QuerySolutionMap(); Query query = QueryFactory.create(sparql); querySolutionMap.add("graph",ResourceFactory.createResource(query.getGraphURIs().get(0))); - querySolutionMap.add("component", ResourceFactory.createResource("urn:qanary:" + this.applicationName)); + querySolutionMap.add("component", ResourceFactory.createResource(this.applicationName)); querySolutionMap.add("questionID", ResourceFactory.createResource("urn:qanary:currentQuestion")); querySolutionMap.add("body", ResourceFactory.createPlainLiteral(sparql)); try { diff --git a/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorVirtuoso.java b/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorVirtuoso.java index 593cadfe..6c35b791 100644 --- a/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorVirtuoso.java +++ b/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorVirtuoso.java @@ -3,7 +3,11 @@ import java.net.URI; import java.util.concurrent.TimeUnit; -import org.apache.jena.query.*; +import org.apache.jena.query.Query; +import org.apache.jena.query.QueryFactory; +import org.apache.jena.query.ResultSet; +import org.apache.jena.query.ResultSetFactory; +import org.apache.jena.query.ResultSetRewindable; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; From 7b17df420c720775f79589a5ff60d2f4d7b77c7e Mon Sep 17 00:00:00 2001 From: Dennis Schiese Date: Wed, 22 May 2024 08:21:28 +0200 Subject: [PATCH 09/10] Adjusted query Annotation type to LogQuery, removed unused imports --- ...aryTripleStoreConnectorQanaryInternal.java | 159 ++++++++---------- .../insert_explanation_data_sparql_query.rq | 2 +- 2 files changed, 69 insertions(+), 92 deletions(-) diff --git a/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorQanaryInternal.java b/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorQanaryInternal.java index 2c5cc754..0cf90410 100644 --- a/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorQanaryInternal.java +++ b/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/triplestoreconnectors/QanaryTripleStoreConnectorQanaryInternal.java @@ -1,116 +1,93 @@ package eu.wdaqua.qanary.commons.triplestoreconnectors; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.http.HttpClient; -import java.net.http.HttpRequest; -import java.util.ArrayList; -import java.util.List; - -import com.google.api.client.util.Lists; -import com.stardog.stark.vocabs.RDF; -import org.apache.http.Header; -import org.apache.http.HttpHeaders; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.message.BasicHeader; +import eu.wdaqua.qanary.exceptions.SparqlQueryFailed; import org.apache.jena.query.*; import org.apache.jena.rdf.model.ResourceFactory; import org.apache.jena.rdfconnection.RDFConnection; -import org.apache.jena.rdfconnection.RDFConnectionRemote; -import org.apache.jena.rdfconnection.RDFConnectionRemoteBuilder; -import org.apache.jena.sparql.exec.QueryExecBuilder; // QueryExecBuilder is required for RDFConnection -import org.apache.jena.update.UpdateFactory; -import org.apache.jena.update.UpdateRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import eu.wdaqua.qanary.exceptions.SparqlQueryFailed; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpEntity; +import java.net.URI; +import java.net.URISyntaxException; /** * simple connection to open endpoint without authorization using the Apache Jena library - * - * @author AnBo * + * @author AnBo */ public class QanaryTripleStoreConnectorQanaryInternal extends QanaryTripleStoreConnector { - private static final Logger logger = LoggerFactory.getLogger(QanaryTripleStoreConnectorQanaryInternal.class); - private URI endpoint; - private RDFConnection connection; - private String applicationName; - @Value("${data.logging") - private boolean dataLogging; - - public QanaryTripleStoreConnectorQanaryInternal(URI endpoint, String applicationName) throws URISyntaxException { - this.setApplicationName(applicationName); - this.endpoint = endpoint; - this.connect(); - } + private static final Logger logger = LoggerFactory.getLogger(QanaryTripleStoreConnectorQanaryInternal.class); + private URI endpoint; + private RDFConnection connection; + private String applicationName; + + public QanaryTripleStoreConnectorQanaryInternal(URI endpoint, String applicationName) throws URISyntaxException { + this.setApplicationName(applicationName); + this.endpoint = endpoint; + this.connect(); + } + + public String getApplicationName() { + return applicationName; + } - public String getApplicationName() { - return applicationName; - } + private void setApplicationName(String applicationName) { + this.applicationName = "urn:qanary:" + applicationName; + } - private void setApplicationName(String applicationName) { - this.applicationName = "urn:qanary:" + applicationName; - } + private URI getEndpoint() { + return this.endpoint; + } - private URI getEndpoint() { - return this.endpoint; - } - - @Override - public void connect() { - org.apache.jena.query.ARQ.init(); // maybe it helps to prevent problems? - this.connection = RDFConnection.connect(this.getEndpoint().toASCIIString()); - } + @Override + public void connect() { + org.apache.jena.query.ARQ.init(); // maybe it helps to prevent problems? + this.connection = RDFConnection.connect(this.getEndpoint().toASCIIString()); + } - @Override - public ResultSet select(String sparql) throws SparqlQueryFailed { - QueryExecution queryExecution = this.connection.query(sparql); - logData(sparql); - ResultSet myResultSet = queryExecution.execSelect(); - ResultSetRewindable resultSet = ResultSetFactory.makeRewindable(myResultSet); - return resultSet; - } + @Override + public ResultSet select(String sparql) throws SparqlQueryFailed { + QueryExecution queryExecution = this.connection.query(sparql); + logData(sparql); + ResultSet myResultSet = queryExecution.execSelect(); + ResultSetRewindable resultSet = ResultSetFactory.makeRewindable(myResultSet); + return resultSet; + } - private void logData(String sparql) { - QuerySolutionMap querySolutionMap = new QuerySolutionMap(); - Query query = QueryFactory.create(sparql); - querySolutionMap.add("graph",ResourceFactory.createResource(query.getGraphURIs().get(0))); - querySolutionMap.add("component", ResourceFactory.createResource(this.applicationName)); - querySolutionMap.add("questionID", ResourceFactory.createResource("urn:qanary:currentQuestion")); - querySolutionMap.add("body", ResourceFactory.createPlainLiteral(sparql)); - try { - this.update(QanaryTripleStoreConnector.readFileFromResourcesWithMap("/queries/insert_explanation_data_sparql_query.rq", querySolutionMap)); - } catch(Exception e) { - getLogger().error("Logging failed, {}", e); - } + private void logData(String sparql) { + QuerySolutionMap querySolutionMap = new QuerySolutionMap(); + Query query = QueryFactory.create(sparql); + querySolutionMap.add("graph", ResourceFactory.createResource(query.getGraphURIs().get(0))); + querySolutionMap.add("component", ResourceFactory.createResource(this.applicationName)); + querySolutionMap.add("questionID", ResourceFactory.createResource("urn:qanary:currentQuestion")); + querySolutionMap.add("body", ResourceFactory.createPlainLiteral(sparql)); + try { + this.update(QanaryTripleStoreConnector.readFileFromResourcesWithMap("/queries/insert_explanation_data_sparql_query.rq", querySolutionMap)); + } catch (Exception e) { + getLogger().error("Logging failed, {}", e); + } - } + } - @Override - public void update(String sparql, URI graph) throws SparqlQueryFailed { - this.update(sparql); - } + @Override + public void update(String sparql, URI graph) throws SparqlQueryFailed { + this.update(sparql); + } - @Override - public void update(String sparql) throws SparqlQueryFailed { - logger.debug("UPDATE on {}: {}", this.getEndpoint().toASCIIString(), sparql); - this.connection.update(sparql); - } + @Override + public void update(String sparql) throws SparqlQueryFailed { + logger.debug("UPDATE on {}: {}", this.getEndpoint().toASCIIString(), sparql); + this.connection.update(sparql); + } - @Override - public boolean ask(String sparql) throws SparqlQueryFailed { - logData(sparql); - return this.connection.queryAsk(sparql); - } + @Override + public boolean ask(String sparql) throws SparqlQueryFailed { + logData(sparql); + return this.connection.queryAsk(sparql); + } - @Override - public String getFullEndpointDescription() { - return "simple open endpoint without authorization: " + this.getEndpoint().toASCIIString(); - } + @Override + public String getFullEndpointDescription() { + return "simple open endpoint without authorization: " + this.getEndpoint().toASCIIString(); + } } diff --git a/qanary_commons/src/main/resources/queries/insert_explanation_data_sparql_query.rq b/qanary_commons/src/main/resources/queries/insert_explanation_data_sparql_query.rq index f38bee3d..270351cd 100644 --- a/qanary_commons/src/main/resources/queries/insert_explanation_data_sparql_query.rq +++ b/qanary_commons/src/main/resources/queries/insert_explanation_data_sparql_query.rq @@ -5,7 +5,7 @@ PREFIX rdfs: INSERT { GRAPH ?graph { - ?newAnnotation rdf:type qa:AnnotationOfLog . + ?newAnnotation rdf:type qa:AnnotationOfLogQuery . ?newAnnotation oa:hasBody ?body . ?newAnnotation oa:annotatedAt ?time . ?newAnnotation oa:annotatedBy ?component . From ce3f89ef2ee204d86ad1d2a16d777401a6f321b7 Mon Sep 17 00:00:00 2001 From: Dennis Schiese Date: Wed, 22 May 2024 08:32:05 +0200 Subject: [PATCH 10/10] Increment version due to new commons version --- qanary_component-template/pom.xml | 624 +++++++++++++++--------------- qanary_pipeline-template/pom.xml | 22 +- 2 files changed, 323 insertions(+), 323 deletions(-) diff --git a/qanary_component-template/pom.xml b/qanary_component-template/pom.xml index de17f2c4..3b421ab3 100644 --- a/qanary_component-template/pom.xml +++ b/qanary_component-template/pom.xml @@ -1,327 +1,327 @@ - - 4.0.0 - eu.wdaqua.qanary - qa.component - 3.9.3 + + 4.0.0 + eu.wdaqua.qanary + qa.component + 3.10.0 - - org.springframework.boot - spring-boot-starter-parent - 2.6.15 - - - 11 - 2.6.11 - + + org.springframework.boot + spring-boot-starter-parent + 2.6.15 + + + 11 + 2.6.11 + - - - org.springframework.boot - spring-boot - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.boot - spring-boot-devtools - true - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - de.codecentric - spring-boot-admin-starter-client - ${spring-boot-admin.version} - - - net.sf.json-lib - json-lib-ext-spring - 1.0.2 - - - servlet-api - javax.servlet - - - com.vaadin.external.google - android-json - - - log4j - log4j - - - - - net.minidev - json-smart - - - org.slf4j - jcl-over-slf4j - - - - org.junit.jupiter - junit-jupiter-engine - test - - - junit - junit - - - javax.inject - javax.inject - - - org.apache.httpcomponents - httpclient - - - eu.wdaqua.qanary - qa.commons - [3.13.0,4.0.0) - - - - org.apache.logging.log4j - log4j-to-slf4j - [2.19.0,3.) - - - org.apache.logging.log4j - log4j-api - - - - - - org.reflections - reflections - 0.10.2 - - - - org.apache.jena - jena-arq - 4.10.0 - - - - org.apache.jena - jena-core - 4.10.0 - - + + + org.springframework.boot + spring-boot + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-devtools + true + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + de.codecentric + spring-boot-admin-starter-client + ${spring-boot-admin.version} + + + net.sf.json-lib + json-lib-ext-spring + 1.0.2 + + + servlet-api + javax.servlet + + + com.vaadin.external.google + android-json + + + log4j + log4j + + + + + net.minidev + json-smart + + + org.slf4j + jcl-over-slf4j + + + + org.junit.jupiter + junit-jupiter-engine + test + + + junit + junit + + + javax.inject + javax.inject + + + org.apache.httpcomponents + httpclient + + + eu.wdaqua.qanary + qa.commons + [3.13.0,4.0.0) + + + + org.apache.logging.log4j + log4j-to-slf4j + [2.19.0,3.) + + + org.apache.logging.log4j + log4j-api + + + + + + org.reflections + reflections + 0.10.2 + + + + org.apache.jena + jena-arq + 4.10.0 + + + + org.apache.jena + jena-core + 4.10.0 + + - + - - ${project.groupId}:${project.artifactId} - Qanary component template package - https://github.com/WDAqua/Qanary/ + + ${project.groupId}:${project.artifactId} + Qanary component template package + https://github.com/WDAqua/Qanary/ - - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots/ - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots/ + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + - - - scm:git:git://github.com/WDAqua/Qanary.git - scm:git:ssh://github.com/WDAqua/Qanary.git - https://github.com/WDAqua/Qanary - + + + scm:git:git://github.com/WDAqua/Qanary.git + scm:git:ssh://github.com/WDAqua/Qanary.git + https://github.com/WDAqua/Qanary + - - - - Andreas Both - andreas.both@htwk-leipzig.de - WDAqua - http://wdaqua.eu/ - - + + + + Andreas Both + andreas.both@htwk-leipzig.de + WDAqua + http://wdaqua.eu/ + + - - - - The Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - - + + + + The Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + - - + + - - - - - org.apache.maven.plugins - maven-enforcer-plugin - - - enforce-banned-dependencies - - enforce - - - - - - org.apache.logging.log4j:log4j-to-slf4j - - - org.apache.logging.log4j:log4j-to-slf4j:2.15.0 - - - - true - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - true - true - - - - - - - maven-release-plugin - 3.0.1 - - @{project.artifactId}-@{project.version} - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.13 - true - - ossrh - https://oss.sonatype.org - true - - + + + + + org.apache.maven.plugins + maven-enforcer-plugin + + + enforce-banned-dependencies + + enforce + + + + + + org.apache.logging.log4j:log4j-to-slf4j + + + org.apache.logging.log4j:log4j-to-slf4j:2.15.0 + + + + true + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + true + true + + + + + + + maven-release-plugin + 3.0.1 + + @{project.artifactId}-@{project.version} + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.13 + true + + ossrh + https://oss.sonatype.org + true + + - - - org.apache.maven.plugins - maven-gpg-plugin - 3.2.0 - - - --pinentry-mode - loopback - - - - - sign-artifacts - verify - - sign - - - - + + + org.apache.maven.plugins + maven-gpg-plugin + 3.2.0 + + + --pinentry-mode + loopback + + + + + sign-artifacts + verify + + sign + + + + - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - attach-javadocs - - jar - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - test-jar - - - - - - + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadocs + + jar + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + test-jar + + + + + + - - - - net.sf.json-lib - json-lib - 2.4 - - - org.springframework.boot - spring-boot-dependencies - 2.6.7 - pom - import - - - org.springframework.cloud - spring-cloud-starter-parent - 1.0.1.RELEASE - pom - import - - - + + + + net.sf.json-lib + json-lib + 2.4 + + + org.springframework.boot + spring-boot-dependencies + 2.6.7 + pom + import + + + org.springframework.cloud + spring-cloud-starter-parent + 1.0.1.RELEASE + pom + import + + + diff --git a/qanary_pipeline-template/pom.xml b/qanary_pipeline-template/pom.xml index 4acb7703..c576b8e9 100644 --- a/qanary_pipeline-template/pom.xml +++ b/qanary_pipeline-template/pom.xml @@ -1,11 +1,11 @@ - 4.0.0 qa.pipeline eu.wdaqua.qanary - 3.8.5 + 3.9.0 org.springframework.boot spring-boot-starter-parent @@ -14,7 +14,7 @@ 11 2.7.15 - [3.11.3,4.0.0) + [3.13.0,4.0.0) 1.4.13 qanary qanary-pipeline @@ -27,7 +27,7 @@ eu.wdaqua.qanary qa.commons - [3.13.0,4.0.0) + ${qanary.version} de.codecentric @@ -373,12 +373,12 @@ - - - - - - + + + + + +