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

VIVO 3838: Upgrading to 4 #379

Draft
wants to merge 8 commits into
base: jena4-upgrade
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@
import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN;
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
import static javax.servlet.http.HttpServletResponse.SC_OK;
import static org.apache.jena.riot.web.HttpNames.paramUsingGraphURI;
import static org.apache.jena.riot.web.HttpNames.paramUsingNamedGraphURI;

import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AuthorizationRequest;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexer;

import java.io.IOException;
import java.io.InputStream;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
Expand All @@ -18,26 +26,16 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import static org.apache.jena.riot.web.HttpNames.paramUsingGraphURI;
import static org.apache.jena.riot.web.HttpNames.paramUsingNamedGraphURI;
import org.apache.jena.graph.Node;
import org.apache.jena.graph.NodeFactory;
import org.apache.jena.query.Dataset;
import org.apache.jena.query.ReadWrite;
import org.apache.jena.update.GraphStore;
import org.apache.jena.update.GraphStoreFactory;
import org.apache.jena.sparql.core.DatasetGraph;
import org.apache.jena.sparql.core.DatasetGraphFactory;
import org.apache.jena.sparql.modify.UsingList;
import org.apache.jena.update.UpdateAction;
import org.apache.jena.update.UpdateFactory;
import org.apache.jena.update.UpdateRequest;
import org.apache.jena.graph.Node;
import org.apache.jena.graph.NodeFactory;
import org.apache.jena.sparql.modify.UsingList;

import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AuthorizationRequest;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexer;

/**
* Process SPARQL Updates, as an API.
Expand Down Expand Up @@ -128,15 +126,15 @@ private void executeUpdate(HttpServletRequest req, UpdateRequest parsed) {
VitroRequest vreq = new VitroRequest(req);
SearchIndexer indexer = ApplicationUtils.instance().getSearchIndexer();
Dataset ds = new RDFServiceDataset(vreq.getUnfilteredRDFService());
GraphStore graphStore = GraphStoreFactory.create(ds);
DatasetGraph dg = DatasetGraphFactory.createGeneral();
try {
if(indexer != null) {
indexer.pause();
}
if(ds.supportsTransactions()) {
ds.begin(ReadWrite.WRITE);
}
UpdateAction.execute(parsed, graphStore);
UpdateAction.execute(parsed, dg);
} finally {
if(ds.supportsTransactions()) {
ds.commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

package edu.cornell.mannlib.vitro.webapp.dao.jena;

import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;

import java.util.ArrayList;
import java.util.List;

import org.apache.jena.graph.Capabilities;
import org.apache.jena.graph.Graph;
import org.apache.jena.graph.GraphEventManager;
import org.apache.jena.graph.GraphStatisticsHandler;
import org.apache.jena.graph.Node;
import org.apache.jena.graph.TransactionHandler;
import org.apache.jena.graph.Triple;
Expand All @@ -18,130 +19,139 @@
import org.apache.jena.util.iterator.ExtendedIterator;
import org.apache.jena.util.iterator.WrappedIterator;

import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;

public class BlankNodeFilteringGraph implements Graph {

private Graph graph;

public Graph getInnerGraph() {
return graph;
}

public BlankNodeFilteringGraph(Graph graph) {
/**
* Initialize, setting the passed graph as the inner graph.
*
* @param graph The internal graph to be delegated.
*/
public BlankNodeFilteringGraph(Graph graph) {
this.graph = graph;
}

@Override
public void add(Triple t) throws AddDeniedException {
graph.add(t);
}
/**
* Convert this object to a string.
*
* @return The string of the object name, hash, and other notable data.
*/
@Override
public String toString() {
return "BlankNodeFilteringGraph[" + ToString.hashHex(this) + ", inner="
+ ToString.graphToString(graph) + "]";
}

@Override
public void close() {
graph.close();
}
/**
* Get the inner graph assigned to this object.
*
* @return The inner graph.
*/
public Graph getInnerGraph() {
return graph;
}

@Override
public boolean contains(Node arg0, Node arg1, Node arg2) {
return graph.contains(arg0, arg1, arg2);
}
@Override
public void add(Triple t) throws AddDeniedException {
graph.add(t);
}

@Override
public boolean contains(Triple arg0) {
return graph.contains(arg0);
}
@Override
public void close() {
graph.close();
}

@Override
public void delete(Triple t) throws DeleteDeniedException {
graph.delete(t);
}
@Override
public boolean contains(Node arg0, Node arg1, Node arg2) {
return graph.contains(arg0, arg1, arg2);
}

@Override
public ExtendedIterator<Triple> find(Triple triple) {
return find(triple.getSubject(), triple.getPredicate(), triple.getObject());
}
@Override
public boolean contains(Triple arg0) {
return graph.contains(arg0);
}

@Override
public boolean dependsOn(Graph arg0) {
return graph.dependsOn(arg0);
}
@Override
public void delete(Triple t) throws DeleteDeniedException {
graph.delete(t);
}

@Override
public ExtendedIterator<Triple> find(Node subject, Node predicate, Node object) {
@Override
public ExtendedIterator<Triple> find(Triple triple) {
return find(triple.getSubject(), triple.getPredicate(), triple.getObject());
}

@Override
public boolean dependsOn(Graph arg0) {
return graph.dependsOn(arg0);
}

@Override
public ExtendedIterator<Triple> find(Node subject, Node predicate, Node object) {

List<Triple> nbTripList = new ArrayList<Triple>();
ExtendedIterator<Triple> triples = graph.find(subject, predicate, object);
ExtendedIterator<Triple> triples = graph.find(subject, predicate, object);

while (triples.hasNext()) {
Triple triple = triples.next();
while (triples.hasNext()) {
Triple triple = triples.next();

if (!triple.getSubject().isBlank() && !triple.getObject().isBlank()) {
nbTripList.add(triple);
}
}
if (!triple.getSubject().isBlank() && !triple.getObject().isBlank()) {
nbTripList.add(triple);
}
}

return WrappedIterator.create(nbTripList.iterator());
}

@Override
public Capabilities getCapabilities() {
return graph.getCapabilities();
}

@Override
public GraphEventManager getEventManager() {
return graph.getEventManager();
}

@Override
public PrefixMapping getPrefixMapping() {
return graph.getPrefixMapping();
}

@Override
public GraphStatisticsHandler getStatisticsHandler() {
return graph.getStatisticsHandler();
}

@Override
public TransactionHandler getTransactionHandler() {
return graph.getTransactionHandler();
}

@Override
public boolean isClosed() {
return graph.isClosed();
}

@Override
public boolean isEmpty() {
return graph.isEmpty();
}

@Override
public boolean isIsomorphicWith(Graph arg0) {
return graph.isIsomorphicWith(arg0);
}

@Override
public int size() {
return graph.size();
}

@Override
public void clear() {
graph.clear();
}

@Override
public void remove(Node arg0, Node arg1, Node arg2) {
graph.remove(arg0, arg1, arg2);
}

@Override
public String toString() {
return "BlankNodeFilteringGraph[" + ToString.hashHex(this) + ", inner="
+ ToString.graphToString(graph) + "]";
}
}

@Override
public Capabilities getCapabilities() {
return graph.getCapabilities();
}

@Override
public GraphEventManager getEventManager() {
return graph.getEventManager();
}

@Override
public PrefixMapping getPrefixMapping() {
return graph.getPrefixMapping();
}

@Override
public TransactionHandler getTransactionHandler() {
return graph.getTransactionHandler();
}

@Override
public boolean isClosed() {
return graph.isClosed();
}

@Override
public boolean isEmpty() {
return graph.isEmpty();
}

@Override
public boolean isIsomorphicWith(Graph arg0) {
return graph.isIsomorphicWith(arg0);
}

@Override
public int size() {
return graph.size();
}

@Override
public void clear() {
graph.clear();
}

@Override
public void remove(Node arg0, Node arg1, Node arg2) {
graph.remove(arg0, arg1, arg2);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public int compare (DataProperty dp1, DataProperty dp2) {
}

public DataPropertyDaoJena(RDFService rdfService,
DatasetWrapperFactory dwf,
DatasetWrapper dw,
WebappDaoFactoryJena wadf) {
super(rdfService, dwf, wadf);
super(rdfService, dw, wadf);
}

public void deleteDataProperty(DataProperty dtp) {
Expand Down
Loading