diff --git a/webapp/lib/aduna-commons-i18n-1.0.jar b/webapp/lib/aduna-commons-i18n-1.0.jar deleted file mode 100644 index 3ad0bfec2..000000000 Binary files a/webapp/lib/aduna-commons-i18n-1.0.jar and /dev/null differ diff --git a/webapp/lib/sesame-config-2.6.6.jar b/webapp/lib/sesame-config-2.6.6.jar deleted file mode 100644 index ff3c892fd..000000000 Binary files a/webapp/lib/sesame-config-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-console-2.6.6.jar b/webapp/lib/sesame-console-2.6.6.jar deleted file mode 100644 index e1459d460..000000000 Binary files a/webapp/lib/sesame-console-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-http-client-2.6.6.jar b/webapp/lib/sesame-http-client-2.6.6.jar deleted file mode 100644 index f31173496..000000000 Binary files a/webapp/lib/sesame-http-client-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-http-protocol-2.6.6.jar b/webapp/lib/sesame-http-protocol-2.6.6.jar deleted file mode 100644 index 6191a830b..000000000 Binary files a/webapp/lib/sesame-http-protocol-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-http-server-spring-2.6.6.jar b/webapp/lib/sesame-http-server-spring-2.6.6.jar deleted file mode 100644 index e4d84da9f..000000000 Binary files a/webapp/lib/sesame-http-server-spring-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-model-2.6.6.jar b/webapp/lib/sesame-model-2.6.6.jar deleted file mode 100644 index 1584f6996..000000000 Binary files a/webapp/lib/sesame-model-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-query-2.6.6.jar b/webapp/lib/sesame-query-2.6.6.jar deleted file mode 100644 index b2d6ca6bd..000000000 Binary files a/webapp/lib/sesame-query-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-queryalgebra-evaluation-2.6.6.jar b/webapp/lib/sesame-queryalgebra-evaluation-2.6.6.jar deleted file mode 100644 index 26bc2a4b9..000000000 Binary files a/webapp/lib/sesame-queryalgebra-evaluation-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-queryalgebra-model-2.6.6.jar b/webapp/lib/sesame-queryalgebra-model-2.6.6.jar deleted file mode 100644 index 219a00591..000000000 Binary files a/webapp/lib/sesame-queryalgebra-model-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-queryparser-api-2.6.6.jar b/webapp/lib/sesame-queryparser-api-2.6.6.jar deleted file mode 100644 index f95b27d96..000000000 Binary files a/webapp/lib/sesame-queryparser-api-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-queryparser-serql-2.6.6.jar b/webapp/lib/sesame-queryparser-serql-2.6.6.jar deleted file mode 100644 index 5ad27c359..000000000 Binary files a/webapp/lib/sesame-queryparser-serql-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-queryparser-sparql-2.6.6.jar b/webapp/lib/sesame-queryparser-sparql-2.6.6.jar deleted file mode 100644 index bf7e68d59..000000000 Binary files a/webapp/lib/sesame-queryparser-sparql-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-queryresultio-api-2.6.6.jar b/webapp/lib/sesame-queryresultio-api-2.6.6.jar deleted file mode 100644 index 690591e59..000000000 Binary files a/webapp/lib/sesame-queryresultio-api-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-queryresultio-binary-2.6.6.jar b/webapp/lib/sesame-queryresultio-binary-2.6.6.jar deleted file mode 100644 index 1066601cc..000000000 Binary files a/webapp/lib/sesame-queryresultio-binary-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-queryresultio-sparqljson-2.6.6.jar b/webapp/lib/sesame-queryresultio-sparqljson-2.6.6.jar deleted file mode 100644 index c9cc19e6c..000000000 Binary files a/webapp/lib/sesame-queryresultio-sparqljson-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-queryresultio-sparqlxml-2.6.6.jar b/webapp/lib/sesame-queryresultio-sparqlxml-2.6.6.jar deleted file mode 100644 index ce8f21b5f..000000000 Binary files a/webapp/lib/sesame-queryresultio-sparqlxml-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-queryresultio-text-2.6.6.jar b/webapp/lib/sesame-queryresultio-text-2.6.6.jar deleted file mode 100644 index 1841c2228..000000000 Binary files a/webapp/lib/sesame-queryresultio-text-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-repository-api-2.6.6.jar b/webapp/lib/sesame-repository-api-2.6.6.jar deleted file mode 100644 index 226e2a78c..000000000 Binary files a/webapp/lib/sesame-repository-api-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-repository-contextaware-2.6.6.jar b/webapp/lib/sesame-repository-contextaware-2.6.6.jar deleted file mode 100644 index 8360459bb..000000000 Binary files a/webapp/lib/sesame-repository-contextaware-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-repository-dataset-2.6.6.jar b/webapp/lib/sesame-repository-dataset-2.6.6.jar deleted file mode 100644 index c1a960a1a..000000000 Binary files a/webapp/lib/sesame-repository-dataset-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-repository-event-2.6.6.jar b/webapp/lib/sesame-repository-event-2.6.6.jar deleted file mode 100644 index f5f3e9200..000000000 Binary files a/webapp/lib/sesame-repository-event-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-repository-http-2.6.6.jar b/webapp/lib/sesame-repository-http-2.6.6.jar deleted file mode 100644 index fb45ff7e9..000000000 Binary files a/webapp/lib/sesame-repository-http-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-repository-manager-2.6.6.jar b/webapp/lib/sesame-repository-manager-2.6.6.jar deleted file mode 100644 index 047bfb784..000000000 Binary files a/webapp/lib/sesame-repository-manager-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-repository-sail-2.6.6.jar b/webapp/lib/sesame-repository-sail-2.6.6.jar deleted file mode 100644 index 71987104b..000000000 Binary files a/webapp/lib/sesame-repository-sail-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-repository-sparql-2.6.6.jar b/webapp/lib/sesame-repository-sparql-2.6.6.jar deleted file mode 100644 index 9a43beb4e..000000000 Binary files a/webapp/lib/sesame-repository-sparql-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-rio-api-2.6.6.jar b/webapp/lib/sesame-rio-api-2.6.6.jar deleted file mode 100644 index 3f60b67cb..000000000 Binary files a/webapp/lib/sesame-rio-api-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-rio-binary-2.6.6.jar b/webapp/lib/sesame-rio-binary-2.6.6.jar deleted file mode 100644 index 8a0345b56..000000000 Binary files a/webapp/lib/sesame-rio-binary-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-rio-n3-2.6.6.jar b/webapp/lib/sesame-rio-n3-2.6.6.jar deleted file mode 100644 index b83d16f18..000000000 Binary files a/webapp/lib/sesame-rio-n3-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-rio-ntriples-2.6.6.jar b/webapp/lib/sesame-rio-ntriples-2.6.6.jar deleted file mode 100644 index 9ded9ccbb..000000000 Binary files a/webapp/lib/sesame-rio-ntriples-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-rio-rdfxml-2.6.6.jar b/webapp/lib/sesame-rio-rdfxml-2.6.6.jar deleted file mode 100644 index e6d0c356c..000000000 Binary files a/webapp/lib/sesame-rio-rdfxml-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-rio-trig-2.6.6.jar b/webapp/lib/sesame-rio-trig-2.6.6.jar deleted file mode 100644 index 49c88a025..000000000 Binary files a/webapp/lib/sesame-rio-trig-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-rio-trix-2.6.6.jar b/webapp/lib/sesame-rio-trix-2.6.6.jar deleted file mode 100644 index fa630c163..000000000 Binary files a/webapp/lib/sesame-rio-trix-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-rio-turtle-2.6.6.jar b/webapp/lib/sesame-rio-turtle-2.6.6.jar deleted file mode 100644 index 8a160084a..000000000 Binary files a/webapp/lib/sesame-rio-turtle-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-runtime-2.6.6.jar b/webapp/lib/sesame-runtime-2.6.6.jar deleted file mode 100644 index a63e62223..000000000 Binary files a/webapp/lib/sesame-runtime-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-sail-api-2.6.6.jar b/webapp/lib/sesame-sail-api-2.6.6.jar deleted file mode 100644 index a0343f984..000000000 Binary files a/webapp/lib/sesame-sail-api-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-sail-inferencer-2.6.6.jar b/webapp/lib/sesame-sail-inferencer-2.6.6.jar deleted file mode 100644 index dec735a2d..000000000 Binary files a/webapp/lib/sesame-sail-inferencer-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-sail-memory-2.6.6.jar b/webapp/lib/sesame-sail-memory-2.6.6.jar deleted file mode 100644 index 0d7be35e5..000000000 Binary files a/webapp/lib/sesame-sail-memory-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-sail-nativerdf-2.6.6.jar b/webapp/lib/sesame-sail-nativerdf-2.6.6.jar deleted file mode 100644 index 91c90722c..000000000 Binary files a/webapp/lib/sesame-sail-nativerdf-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-sail-rdbms-2.6.6.jar b/webapp/lib/sesame-sail-rdbms-2.6.6.jar deleted file mode 100644 index b88993585..000000000 Binary files a/webapp/lib/sesame-sail-rdbms-2.6.6.jar and /dev/null differ diff --git a/webapp/lib/sesame-util-2.6.6.jar b/webapp/lib/sesame-util-2.6.6.jar deleted file mode 100644 index cec6c51ee..000000000 Binary files a/webapp/lib/sesame-util-2.6.6.jar and /dev/null differ diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/BaseResourceBean.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/BaseResourceBean.java index 02771a834..d9d0158d2 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/BaseResourceBean.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/BaseResourceBean.java @@ -112,6 +112,14 @@ public class BaseResourceBean implements ResourceBean { } } + public BaseResourceBean() { + // default constructor + } + + public BaseResourceBean(String uri) { + buildLocalAndNS(uri); + } + @Override public boolean isAnonymous() { return (this.URI==null || VitroVocabulary.PSEUDO_BNODE_NS.equals(this.getNamespace())); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/ObjectProperty.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/ObjectProperty.java index 26a84c601..0f9005dae 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/ObjectProperty.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/ObjectProperty.java @@ -14,7 +14,6 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.joda.time.DateTime; -import org.openrdf.model.impl.URIImpl; import com.hp.hpl.jena.datatypes.xsd.XSDDatatype; @@ -184,7 +183,7 @@ public class ObjectProperty extends Property implements Comparable */ public VClass( String uriString ) { - // The URIImpl class can be used to parse a URI string into its component parts - URIImpl uri = new URIImpl(uriString); - - // Use the URIImpl to obtain parts of this URI for local storage - myName = uri.getLocalName(); - URI = uriString; - namespace = uri.getNamespace(); - localName = uri.getLocalName(); + super(uriString); + myName = getLocalName(); } /** diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/VClassGroup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/VClassGroup.java index 8a975ff3f..893deeb76 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/VClassGroup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/VClassGroup.java @@ -12,7 +12,6 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.openrdf.model.impl.URIImpl; public class VClassGroup extends LinkedList implements Comparable { @@ -56,7 +55,7 @@ public class VClassGroup extends LinkedList implements Comparable listNames() { - ArrayList nameList = new ArrayList(); - Iterator nodeIt = g.listGraphNodes(); - while (nodeIt.hasNext()) { - Node n = nodeIt.next(); - nameList.add(n.getURI()); - } - return nameList.iterator(); - } - -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/SparqlDatasetGraph.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/SparqlDatasetGraph.java deleted file mode 100644 index 7cd6f8822..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/SparqlDatasetGraph.java +++ /dev/null @@ -1,266 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.dao.jena; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import org.openrdf.model.Resource; -import org.openrdf.repository.Repository; -import org.openrdf.repository.RepositoryConnection; -import org.openrdf.repository.RepositoryException; -import org.openrdf.repository.RepositoryResult; -import org.openrdf.repository.http.HTTPRepository; - -import com.hp.hpl.jena.graph.Graph; -import com.hp.hpl.jena.graph.Node; -import com.hp.hpl.jena.graph.Triple; -import com.hp.hpl.jena.query.Query; -import com.hp.hpl.jena.query.QueryExecution; -import com.hp.hpl.jena.query.QueryExecutionFactory; -import com.hp.hpl.jena.query.QueryFactory; -import com.hp.hpl.jena.query.QuerySolution; -import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.shared.Lock; -import com.hp.hpl.jena.shared.LockMRSW; -import com.hp.hpl.jena.sparql.core.DatasetGraph; -import com.hp.hpl.jena.sparql.core.Quad; -import com.hp.hpl.jena.sparql.resultset.ResultSetMem; -import com.hp.hpl.jena.sparql.util.Context; -import com.hp.hpl.jena.util.iterator.SingletonIterator; -import com.hp.hpl.jena.util.iterator.WrappedIterator; - -public class SparqlDatasetGraph implements DatasetGraph { - - private String endpointURI; - private Repository repository; - private Lock lock = new LockMRSW(); - - public SparqlDatasetGraph(String endpointURI) { - this.endpointURI = endpointURI; - this.repository = new HTTPRepository(endpointURI); - } - - private Graph getGraphFor(Quad q) { - return getGraphFor(q.getGraph()); - } - - private Graph getGraphFor(Node g) { - return (g == Node.ANY) - ? new SparqlGraph(endpointURI) - : new SparqlGraph(endpointURI, g.getURI()); - } - - @Override - public void add(Quad arg0) { - getGraphFor(arg0).add(new Triple(arg0.getSubject(), arg0.getPredicate(), arg0.getObject())); - } - - @Override - public void addGraph(Node arg0, Graph arg1) { - // TODO Auto-generated method stub - } - - @Override - public void close() { - // TODO Auto-generated method stub - } - - @Override - public boolean contains(Quad arg0) { - return getGraphFor(arg0).contains(new Triple(arg0.getSubject(), arg0.getPredicate(), arg0.getObject())); - } - - @Override - public boolean contains(Node arg0, Node arg1, Node arg2, Node arg3) { - return getGraphFor(arg0).contains(arg1, arg2, arg3); - } - - @Override - public boolean containsGraph(Node arg0) { - // TODO Auto-generated method stub - return true; - } - - @Override - public void delete(Quad arg0) { - getGraphFor(arg0).delete(new Triple(arg0.getSubject(), arg0.getPredicate(), arg0.getObject())); - } - - @Override - public void deleteAny(Node arg0, Node arg1, Node arg2, Node arg3) { - // TODO check this - getGraphFor(arg0).delete(new Triple(arg1, arg2, arg3)); - } - - @Override - public Iterator find() { - return find(Node.ANY, Node.ANY, Node.ANY, Node.ANY); - } - - @Override - public Iterator find(Quad arg0) { - return find(arg0.getSubject(), arg0.getPredicate(), arg0.getObject(), arg0.getGraph()); - } - - @Override - public Iterator find(Node graph, Node subject, Node predicate, Node object) { - if (!isVar(subject) && !isVar(predicate) && !isVar(object) &&!isVar(graph)) { - if (contains(subject, predicate, object, graph)) { - return new SingletonIterator(new Triple(subject, predicate, object)); - } else { - return WrappedIterator.create(Collections.EMPTY_LIST.iterator()); - } - } - StringBuffer findQuery = new StringBuffer("SELECT * WHERE { \n"); - String graphURI = !isVar(graph) ? graph.getURI() : null; - findQuery.append(" GRAPH "); - if (graphURI != null) { - findQuery.append(" <" + graphURI + ">"); - } else { - findQuery.append("?g"); - } - findQuery.append(" { "); - findQuery.append(SparqlGraph.sparqlNode(subject, "?s")) - .append(" ") - .append(SparqlGraph.sparqlNode(predicate, "?p")) - .append(" ") - .append(SparqlGraph.sparqlNode(object, "?o")); - findQuery.append(" } "); - findQuery.append("\n}"); - - //log.info(findQuery.toString()); - ResultSet rs = execSelect(findQuery.toString()); - //rs = execSelect(findQuery.toString()); - //rs = execSelect(findQuery.toString()); - - List quadlist = new ArrayList(); - while (rs.hasNext()) { - QuerySolution soln = rs.nextSolution(); - Quad q = new Quad(isVar(graph) ? soln.get("?g").asNode() : graph, - isVar(subject) ? soln.get("?s").asNode() : subject, - isVar(predicate) ? soln.get("?p").asNode() : predicate, - isVar(object) ? soln.get("?o").asNode() : object); - //log.info(t); - quadlist.add(q); - } - //log.info(triplist.size() + " results"); - return WrappedIterator.create(quadlist.iterator()); } - - @Override - public Iterator findNG(Node arg0, Node arg1, Node arg2, Node arg3) { - // TODO check this - return find(arg0, arg1, arg2, arg3); - } - - @Override - public Context getContext() { - // TODO Auto-generated method stub - return null; - } - - @Override - public Graph getDefaultGraph() { - return new SparqlGraph(endpointURI); - } - - @Override - public Graph getGraph(Node arg0) { - return new SparqlGraph(endpointURI, arg0.getURI()); - } - - @Override - public Lock getLock() { - return lock; - } - - @Override - public boolean isEmpty() { - // TODO Auto-generated method stub - return false; - } - - @Override - public Iterator listGraphNodes() { - List graphNodeList = new ArrayList(); - try { - RepositoryConnection conn = getConnection(); - try { - RepositoryResult conResult = conn.getContextIDs(); - while (conResult.hasNext()) { - Resource con = conResult.next(); - graphNodeList.add(Node.createURI(con.stringValue())); - } - } finally { - conn.close(); - } - } catch (RepositoryException re) { - throw new RuntimeException(re); - } - return graphNodeList.iterator(); - } - - private RepositoryConnection getConnection() { - try { - return this.repository.getConnection(); - } catch (RepositoryException e) { - throw new RuntimeException(e); - } - } - - @Override - public void removeGraph(Node arg0) { - // TODO Auto-generated method stub - - } - - @Override - public void setDefaultGraph(Graph arg0) { - // TODO Auto-generated method stub - - } - - @Override - public long size() { - // TODO Auto-generated method stub - return 0; - } - - private boolean isVar(Node node) { - return (node == null || node.isVariable() || node == Node.ANY); - } - - private ResultSet execSelect(String queryStr) { - -// long startTime1 = System.currentTimeMillis(); -// try { -// -// RepositoryConnection conn = getConnection(); -// try { -// GraphQuery q = conn.prepareGraphQuery(QueryLanguage.SPARQL, queryStr); -// q.evaluate(); -// } catch (MalformedQueryException e) { -// throw new RuntimeException(e); -// } finally { -// conn.close(); -// } -// } catch (Exception re) { -// //log.info(re,re); -// } - -// log.info((System.currentTimeMillis() - startTime1) + " to execute via sesame"); - - long startTime = System.currentTimeMillis(); - Query askQuery = QueryFactory.create(queryStr); - QueryExecution qe = QueryExecutionFactory.sparqlService(endpointURI, askQuery); - try { - return new ResultSetMem(qe.execSelect()); - } finally { - //log.info((System.currentTimeMillis() - startTime) + " to execute via Jena"); - qe.close(); - } - } - -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/SparqlGraph.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/SparqlGraph.java index d3988bc66..00ca0c550 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/SparqlGraph.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/SparqlGraph.java @@ -3,19 +3,12 @@ package edu.cornell.mannlib.vitro.webapp.dao.jena; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.openrdf.query.MalformedQueryException; -import org.openrdf.query.QueryLanguage; -import org.openrdf.query.Update; -import org.openrdf.query.UpdateExecutionException; -import org.openrdf.repository.Repository; -import org.openrdf.repository.RepositoryConnection; -import org.openrdf.repository.RepositoryException; -import org.openrdf.repository.http.HTTPRepository; import com.hp.hpl.jena.graph.BulkUpdateHandler; import com.hp.hpl.jena.graph.Capabilities; @@ -46,10 +39,23 @@ import com.hp.hpl.jena.util.iterator.ExtendedIterator; import com.hp.hpl.jena.util.iterator.SingletonIterator; import com.hp.hpl.jena.util.iterator.WrappedIterator; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.utils.URIBuilder; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.message.BasicNameValuePair; + +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException; + public class SparqlGraph implements GraphWithPerform { private String endpointURI; private String graphURI; + private CloseableHttpClient httpClient; private static final Log log = LogFactory.getLog(SparqlGraph.class); private BulkUpdateHandler bulkUpdateHandler; @@ -60,8 +66,6 @@ public class SparqlGraph implements GraphWithPerform { private TransactionHandler transactionHandler; private QueryHandler queryHandler; - private Repository repository; - /** * Returns a SparqlGraph for the union of named graphs in a remote repository * @param endpointURI @@ -78,7 +82,10 @@ public class SparqlGraph implements GraphWithPerform { public SparqlGraph(String endpointURI, String graphURI) { this.endpointURI = endpointURI; this.graphURI = graphURI; - this.repository = new HTTPRepository(endpointURI); + + PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); + cm.setDefaultMaxPerRoute(50); + this.httpClient = HttpClients.custom().setConnectionManager(cm).build(); } public String getEndpointURI() { @@ -88,14 +95,6 @@ public class SparqlGraph implements GraphWithPerform { public String getGraphURI() { return graphURI; } - - public RepositoryConnection getConnection() { - try { - return this.repository.getConnection(); - } catch (RepositoryException e) { - throw new RuntimeException(e); - } - } @Override public void add(Triple arg0) throws AddDeniedException { @@ -104,22 +103,24 @@ public class SparqlGraph implements GraphWithPerform { public void executeUpdate(String updateString) { try { - RepositoryConnection conn = getConnection(); + HttpPost meth = new HttpPost(endpointURI); + meth.addHeader("Content-Type", "application/x-www-form-urlencoded"); + meth.setEntity(new UrlEncodedFormEntity(Arrays.asList( + new BasicNameValuePair("update", updateString)))); + CloseableHttpResponse response = httpClient.execute(meth); try { - Update u = conn.prepareUpdate(QueryLanguage.SPARQL, updateString); - u.execute(); - } catch (MalformedQueryException e) { - throw new RuntimeException(e); - } catch (UpdateExecutionException e) { - log.error(e,e); - log.error("Update command: \n" + updateString); - throw new RuntimeException(e); + int statusCode = response.getStatusLine().getStatusCode(); + if (statusCode > 399) { + log.error("response " + statusCode + " to update. \n"); + throw new RuntimeException("Unable to perform SPARQL UPDATE: \n" + + updateString); + } } finally { - conn.close(); - } - } catch (RepositoryException re) { - throw new RuntimeException(re); - } + response.close(); + } + } catch (Exception e) { + throw new RuntimeException("Unable to perform SPARQL UPDATE", e); + } } @Override diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/URLRewritingHttpServletResponse.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/URLRewritingHttpServletResponse.java index 64d554c5b..ab8dccffd 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/URLRewritingHttpServletResponse.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/URLRewritingHttpServletResponse.java @@ -14,9 +14,8 @@ import javax.servlet.http.HttpServletResponseWrapper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.openrdf.model.URI; -import org.openrdf.model.impl.URIImpl; +import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl; import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper; @@ -136,7 +135,7 @@ public class URLRewritingHttpServletResponse extends HttpServletResponseWrapper/ qpIndex++; if ( ("uri".equals(keyAndValue[0])) && (keyAndValue.length>1) && (keyAndValue[1] != null) ) { try { - URI uri = new URIImpl(keyAndValue[1]); + IndividualImpl uri = new IndividualImpl(keyAndValue[1]); String namespace = uri.getNamespace(); String localName = uri.getLocalName(); if ( (namespace != null) && (localName != null) ) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/ontology/update/KnowledgeBaseUpdater.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/ontology/update/KnowledgeBaseUpdater.java index 1502179c7..de9837b16 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/ontology/update/KnowledgeBaseUpdater.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/ontology/update/KnowledgeBaseUpdater.java @@ -19,7 +19,6 @@ import javax.servlet.ServletContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.openrdf.model.impl.URIImpl; import com.hp.hpl.jena.iri.IRI; import com.hp.hpl.jena.iri.IRIFactory; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/sparql/RDFServiceSparql.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/sparql/RDFServiceSparql.java index e7875a341..ebe60e02d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/sparql/RDFServiceSparql.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/sparql/RDFServiceSparql.java @@ -26,11 +26,6 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.message.BasicNameValuePair; -import org.openrdf.model.Resource; -import org.openrdf.repository.RepositoryConnection; -import org.openrdf.repository.RepositoryException; -import org.openrdf.repository.RepositoryResult; -import org.openrdf.repository.http.HTTPRepository; import com.hp.hpl.jena.graph.Triple; import com.hp.hpl.jena.query.Query; @@ -44,6 +39,7 @@ import com.hp.hpl.jena.query.ResultSetFormatter; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.RDFNode; +import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.Statement; import com.hp.hpl.jena.rdf.model.StmtIterator; @@ -67,10 +63,7 @@ public class RDFServiceSparql extends RDFServiceImpl implements RDFService { private static final Log log = LogFactory.getLog(RDFServiceImpl.class); protected String readEndpointURI; protected String updateEndpointURI; - private HTTPRepository readRepository; - private HTTPRepository updateRepository; private CloseableHttpClient httpClient; - private boolean useSesameContextQuery = true; // the number of triples to be private static final int CHUNK_SIZE = 1000; // added/removed in a single // SPARQL UPDATE @@ -89,8 +82,6 @@ public class RDFServiceSparql extends RDFServiceImpl implements RDFService { public RDFServiceSparql(String readEndpointURI, String updateEndpointURI, String defaultWriteGraphURI) { this.readEndpointURI = readEndpointURI; this.updateEndpointURI = updateEndpointURI; - this.readRepository = new HTTPRepository(readEndpointURI); - this.updateRepository = new HTTPRepository(updateEndpointURI); PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); cm.setDefaultMaxPerRoute(50); @@ -135,12 +126,7 @@ public class RDFServiceSparql extends RDFServiceImpl implements RDFService { } public void close() { - try { - this.readRepository.shutDown(); - this.updateRepository.shutDown(); - } catch (RepositoryException re) { - log.error(re, re); - } + // nothing for now } /** @@ -234,6 +220,8 @@ public class RDFServiceSparql extends RDFServiceImpl implements RDFService { try { qe.execConstruct(model); + } catch (Exception e) { + log.error("Error executing CONSTRUCT against remote endpoint: " + queryStr); } finally { qe.close(); } @@ -359,47 +347,40 @@ public class RDFServiceSparql extends RDFServiceImpl implements RDFService { * * @return List - list of all the graph URIs in the RDF store */ - //TODO - need to verify that the sesame getContextIDs method is implemented - // in such a way that it works with all triple stores that support the - // graph update API @Override public List getGraphURIs() throws RDFServiceException { - if (!this.useSesameContextQuery) { - return getGraphURIsFromSparqlQuery(); - } else { - try { - return getGraphURIsFromSesameContexts(); - } catch (RepositoryException re) { - this.useSesameContextQuery = false; - return getGraphURIsFromSparqlQuery(); - } - } + return getGraphURIsFromSparqlQuery(); } - private List getGraphURIsFromSesameContexts() throws RepositoryException { - List graphURIs = new ArrayList(); - RepositoryConnection conn = getReadConnection(); - try { - RepositoryResult conResult = conn.getContextIDs(); - while (conResult.hasNext()) { - Resource res = conResult.next(); - graphURIs.add(res.stringValue()); - } - } finally { - conn.close(); - } - return graphURIs; - } - - private List getGraphURIsFromSparqlQuery() throws RDFServiceException { + private List getGraphURIsFromSparqlQuery() throws RDFServiceException { + String fastJenaQuery = "SELECT DISTINCT ?g WHERE { GRAPH ?g {} } ORDER BY ?g"; + String standardQuery = "SELECT DISTINCT ?g WHERE { GRAPH ?g { ?s ?p ?o } } ORDER BY ?g"; List graphURIs = new ArrayList(); try { - String graphURIString = "SELECT DISTINCT ?g WHERE { GRAPH ?g { ?s ?p ?o } } ORDER BY ?g"; + graphURIs = getGraphURIsFromSparqlQuery(fastJenaQuery); + } catch (Exception e) { + log.debug("Unable to use non-standard ARQ query for graph list", e); + } + if (graphURIs.isEmpty()) { + graphURIs = getGraphURIsFromSparqlQuery(standardQuery); + } + return graphURIs; + } + + private List getGraphURIsFromSparqlQuery(String queryString) throws RDFServiceException { + List graphURIs = new ArrayList(); + try { + ResultSet rs = ResultSetFactory.fromJSON( - sparqlSelectQuery(graphURIString, RDFService.ResultFormat.JSON)); + sparqlSelectQuery(queryString, RDFService.ResultFormat.JSON)); while (rs.hasNext()) { QuerySolution qs = rs.nextSolution(); - graphURIs.add(qs.getResource("g").getURI()); + if (qs != null) { // no idea how this happens, but it seems to + RDFNode n = qs.getResource("g"); + if (n != null && n.isResource()) { + graphURIs.add(((Resource) n).getURI()); + } + } } } catch (Exception e) { throw new RDFServiceException("Unable to list graph URIs", e); @@ -470,22 +451,6 @@ public class RDFServiceSparql extends RDFServiceImpl implements RDFService { return updateEndpointURI; } - protected RepositoryConnection getReadConnection() { - try { - return this.readRepository.getConnection(); - } catch (RepositoryException e) { - throw new RuntimeException(e); - } - } - - protected RepositoryConnection getWriteConnection() { - try { - return this.updateRepository.getConnection(); - } catch (RepositoryException e) { - throw new RuntimeException(e); - } - } - protected void executeUpdate(String updateString) throws RDFServiceException { try { HttpPost meth = new HttpPost(updateEndpointURI); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/sparql/GetAllPrefix.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/sparql/GetAllPrefix.java index 57ee4622d..3ddd4930d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/sparql/GetAllPrefix.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/sparql/GetAllPrefix.java @@ -15,9 +15,9 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.openrdf.model.vocabulary.OWL; -import org.openrdf.model.vocabulary.RDF; +import com.hp.hpl.jena.vocabulary.OWL; +import com.hp.hpl.jena.vocabulary.RDF; import com.hp.hpl.jena.vocabulary.RDFS; import com.hp.hpl.jena.vocabulary.XSD; @@ -99,8 +99,8 @@ public class GetAllPrefix extends BaseEditController { } // add standard namespaces - addPrefixIfNecessary("owl", OWL.NAMESPACE, prefixMap); - addPrefixIfNecessary("rdf", RDF.NAMESPACE, prefixMap); + addPrefixIfNecessary("owl", OWL.getURI(), prefixMap); + addPrefixIfNecessary("rdf", RDF.getURI(), prefixMap); addPrefixIfNecessary("rdfs", RDFS.getURI(), prefixMap); addPrefixIfNecessary("swrl", "http://www.w3.org/2003/11/swrl#", prefixMap); addPrefixIfNecessary("swrlb", "http://www.w3.org/2003/11/swrlb#", prefixMap); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/jena/SesameSyncUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/jena/SesameSyncUtils.java deleted file mode 100644 index 9875e5238..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/jena/SesameSyncUtils.java +++ /dev/null @@ -1,156 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.utils.jena; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.PipedInputStream; -import java.io.PipedOutputStream; -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.openrdf.model.Resource; -import org.openrdf.model.impl.URIImpl; -import org.openrdf.repository.Repository; -import org.openrdf.repository.RepositoryConnection; -import org.openrdf.repository.RepositoryException; -import org.openrdf.repository.http.HTTPRepository; -import org.openrdf.rio.RDFFormat; -import org.openrdf.rio.RDFParseException; - -import com.hp.hpl.jena.query.Query; -import com.hp.hpl.jena.query.QueryExecution; -import com.hp.hpl.jena.query.QueryExecutionFactory; -import com.hp.hpl.jena.query.QueryFactory; -import com.hp.hpl.jena.query.QuerySolution; -import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.rdf.model.Model; -import com.hp.hpl.jena.rdf.model.ModelFactory; -import com.hp.hpl.jena.rdf.model.RDFNode; -import com.hp.hpl.jena.vocabulary.OWL; - -public class SesameSyncUtils { - - private static final Log log = LogFactory.getLog(SesameSyncUtils.class); - - public void writeModelToSesameContext - (Model jenaModel, String serverURI, String repositoryId, String contextId) - throws RepositoryException, IOException, RDFParseException { - Repository myRepository = new HTTPRepository(serverURI, repositoryId); - myRepository.initialize(); - RepositoryConnection myConn = myRepository.getConnection(); - - myConn.setAutoCommit(false); - try { - - Resource contextRes = (contextId != null) - ? new URIImpl(contextId) : null ; - - if (contextRes != null) { - myConn.clear(contextRes); - } else { - myConn.clear(); - } - - PipedInputStream in = new PipedInputStream(); - PipedOutputStream out = new PipedOutputStream(in); - - - - try { - - new Thread(new JenaOutputter(jenaModel, out, myConn), "SesameSyncUtilities.JenaOutputter").start(); - - if (contextRes != null) { - myConn.add(in,"http://example.org/base/", RDFFormat.NTRIPLES, contextRes); - } else { - myConn.add(in,"http://example.org/base/", RDFFormat.NTRIPLES); - } - } finally { - in.close(); - } - - myConn.commit(); - - } catch (Throwable e) { - myConn.rollback(); - e.printStackTrace(); - log.error("Error writing to Sesame repository", e); - throw new RuntimeException("Error writing to Sesame repository", e); - } finally { - myConn.close(); - } - - } - - private List getIndividualURIs(Model model) { - List individualURIs = new ArrayList(); - String queryStr = "SELECT DISTINCT ?s WHERE { \n" + - " ?s a <" + OWL.Thing.getURI() + "> \n" + - "}"; - Query query = QueryFactory.create(queryStr); - QueryExecution qe = QueryExecutionFactory.create(query, model); - try { - ResultSet rs = qe.execSelect(); - while (rs.hasNext()) { - QuerySolution qsoln = rs.nextSolution(); - String individualURI = qsoln.getResource("s").getURI(); - if (individualURI != null) { - individualURIs.add(individualURI); - } - } - } finally { - qe.close(); - } - return individualURIs; - } - - private class JenaOutputter implements Runnable { - - private Model model; - private OutputStream out; - private RepositoryConnection rconn; - - public JenaOutputter(Model model, OutputStream out, RepositoryConnection rconn) { - this.model = model; - this.out = out; - this.rconn = rconn; - } - - public void run() { - Model t = ModelFactory.createDefaultModel(); - try { - List individualURIs = getIndividualURIs(model); - log.info(individualURIs.size() + " individuals to send to Sesame"); - int i = 0; - for (String individualURI : individualURIs) { - t.removeAll(); - t.add(model.listStatements( - model.getResource( - individualURI), null, (RDFNode) null)); - t.write(out, "N-TRIPLE"); - i++; - if (i % 100 == 0) { - try { - rconn.commit(); - } catch (Throwable e) { - log.error(e, e); - } - log.info(i + " individuals sent to Sesame"); - } - } - } finally { - try { - out.flush(); - out.close(); - } catch (IOException ioe) { - ioe.printStackTrace(); - } - } - } - - } - -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/NameStatementTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/NameStatementTemplateModel.java index 6166ae29c..93eb997dd 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/NameStatementTemplateModel.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/NameStatementTemplateModel.java @@ -4,8 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.openrdf.model.URI; -import org.openrdf.model.impl.URIImpl; import com.hp.hpl.jena.rdf.model.Literal; @@ -14,6 +12,8 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.RequestedAction; import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.EditDataPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl; +import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl; import edu.cornell.mannlib.vitro.webapp.beans.Property; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; @@ -51,7 +51,7 @@ public class NameStatementTemplateModel extends PropertyStatementTemplateModel { // If the individual has no rdfs:label, use the local name. It will not be editable. (This replicates previous behavior; // perhaps we would want to allow a label to be added. But such individuals do not usually have their profiles viewed or // edited directly.) - URI uri = new URIImpl(subjectUri); + Individual uri = new IndividualImpl(subjectUri); this.stringValue = uri.getLocalName(); this.editUrl = ""; } else {