use of org.apache.jena.shared.OperationDeniedException in project jena by apache.
the class UploadRDF method quadsPutPostNonTxn.
/**
* Load data, without assuming the dataset of an action is transactional -
* specifically, whether it supports "abort". This requires loading the data into
* a temporary dataset, which means we check the data is legal RDF, then copying
* it into the finally destination.
* <p>
* Delayed choice of dataset via a function so that the decision is made inside the transaction updating the data.
*/
public static UploadDetails quadsPutPostNonTxn(HttpAction action, Function<HttpAction, DatasetGraph> decideDataset, boolean replaceOperation) {
DatasetGraph dsgTmp = DatasetGraphFactory.create();
StreamRDF dest = StreamRDFLib.dataset(dsgTmp);
UploadDetails details;
try {
details = DataUploader.incomingData(action, dest);
} catch (RiotException ex) {
ServletOps.errorBadRequest(ex.getMessage());
return null;
}
// Now insert into dataset
action.beginWrite();
try {
DatasetGraph dsg = decideDataset.apply(action);
if (replaceOperation)
dsg.clear();
FusekiNetLib.addDataInto(dsgTmp, dsg);
action.commit();
} catch (OperationDeniedException ex) {
action.abortSilent();
throw ex;
} catch (Exception ex) {
// We're in a non-transactional upload so this probably will not
// work but there still may be transaction state tracking.
// There is no harm safely trying.
action.abortSilent();
ServletOps.errorOccurred(ex.getMessage());
} finally {
action.end();
}
return details;
}
use of org.apache.jena.shared.OperationDeniedException in project jena by apache.
the class UploadRDF method quadsPutPostTxn.
/**
* Load data using a transaction into the dataset of an action. if the data is bad,
* abort the transaction.
* <p>
* Delayed choice of dataset via a function so that the decision is made inside the transaction.
*/
public static UploadDetails quadsPutPostTxn(HttpAction action, Function<HttpAction, DatasetGraph> decideDataset, boolean replaceOperation) {
UploadDetails details = null;
action.beginWrite();
try {
DatasetGraph dsg = decideDataset.apply(action);
if (replaceOperation)
dsg.clear();
StreamRDF dest = StreamRDFLib.dataset(dsg);
details = DataUploader.incomingData(action, dest);
action.commit();
} catch (RiotException ex) {
// Parse error
action.abortSilent();
if (ex.getMessage() != null)
action.log.info(format("[%d] Data error: %s", action.id, ex.getMessage()));
else
action.log.info(format("[%d] Data error", action.id), ex);
ServletOps.errorBadRequest(ex.getMessage());
} catch (OperationDeniedException ex) {
action.abortSilent();
throw ex;
} catch (ActionErrorException ex) {
action.abortSilent();
if (ex.getMessage() != null)
action.log.info(format("[%d] Upload error: %s", action.id, ex.getMessage()));
else
action.log.info(format("[%d] Upload error", action.id), ex);
throw ex;
} catch (Exception ex) {
// Something else went wrong. Backout.
action.abortSilent();
ServletOps.errorOccurred(ex.getMessage());
} finally {
action.end();
}
return details;
}
use of org.apache.jena.shared.OperationDeniedException in project jena by apache.
the class GSP_RW method triplesPutPostNonTxn.
/**
* Add data where the destination does not support full transactions.
* In particular, with no abort, and actions probably going to the real storage
* parse errors can lead to partial updates. Instead, parse to a temporary
* graph, then insert that data.
*/
private UploadDetails triplesPutPostNonTxn(HttpAction action, boolean replaceOperation) {
Graph graphTmp = GraphFactory.createGraphMem();
StreamRDF dest = StreamRDFLib.graph(graphTmp);
UploadDetails details;
try {
details = DataUploader.incomingData(action, dest);
} catch (RiotParseException ex) {
ServletOps.errorParseError(ex);
return null;
}
// Now insert into dataset
action.beginWrite();
try {
DatasetGraph dsg = decideDataset(action);
GraphTarget target = determineTargetGSP(dsg, action);
if (action.log.isDebugEnabled())
action.log.debug(" ->" + target);
if (target.isUnion())
ServletOps.errorBadRequest("Can't load into the union graph");
boolean existedBefore = target.exists();
if (replaceOperation && existedBefore)
clearGraph(target);
FusekiNetLib.addDataInto(graphTmp, target.dataset(), target.graphName());
details.setExistedBefore(existedBefore);
action.commit();
return details;
} catch (OperationDeniedException ex) {
action.abortSilent();
throw ex;
} catch (Exception ex) {
// We parsed into a temporary graph so an exception at this point
// is not because of a parse error.
// We're in the non-transactional branch, this probably will not work
// but it might and there is no harm safely trying.
action.abortSilent();
ServletOps.errorOccurred(ex.getMessage());
return null;
} finally {
action.end();
}
}
Aggregations