use of com.inova8.intelligentgraph.exceptions.ServerException in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphRepository method prefix.
/**
* Prefix.
*
* @param prefix the prefix
* @param IRI the iri
* @return the intelligent graph repository
*/
public IntelligentGraphRepository prefix(String prefix, String IRI) {
org.eclipse.rdf4j.model.IRI iri = Utilities.trimAndCheckIRIString(IRI);
if (iri != null) {
// } else {
try {
RepositoryConnection connection = this.getRepository().getConnection();
connection.setNamespace(prefix, iri.stringValue());
getRepositoryContext().getPrefixes().put(prefix, iri);
logger.debug("Added prefix {} for namespace {} ", prefix, iri);
} catch (Exception qe) {
throw new ServerException(FAILEDTOREMOVEGRAPH_EXCEPTION, String.format("Failed to add prefix/namespace", prefix, iri), qe);
}
// }
} else {
logger.error("Invalid IRI specified. Ensure enclosed in <...> ", IRI);
}
return this;
}
use of com.inova8.intelligentgraph.exceptions.ServerException in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphRepository method closeGraph.
/**
* Close graph.
*
* @param graphName the graph name
* @return the boolean
*/
@SuppressWarnings("deprecation")
public Boolean closeGraph(String graphName) {
RepositoryConnection connection = this.getContextAwareConnection();
IRI graphNameIri = null;
try {
graphNameIri = PathParser.parseIriRef(getRepositoryContext(), graphName).getIri();
Boolean contextExists = connection.getContextIDs().asList().contains(graphNameIri);
if (contextExists) {
getPublicContexts().remove(graphNameIri);
return true;
} else {
return false;
}
} catch (Exception qe) {
throw new ServerException(FAILEDTOCLOSEGRAPH_EXCEPTION, String.format("Failed to close graph %s with exception %s", graphName, qe.getMessage()), qe);
}
}
use of com.inova8.intelligentgraph.exceptions.ServerException in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphRepository method removeGraph.
/**
* Removes the graph.
*
* @param graphName the graph name
* @return the iri
*/
public IRI removeGraph(String graphName) {
// RepositoryConnection connection = this.getRepository().getConnection();//.getContextAwareConnection();
IRI graphNameIri = null;
try (RepositoryConnection connection = this.getRepository().getConnection()) {
graphNameIri = PathParser.parseIriRef(getRepositoryContext(), graphName).getIri();
@SuppressWarnings("deprecation") Boolean contextExists = connection.getContextIDs().asList().contains(graphNameIri);
if (contextExists) {
Resource[] contexts = { graphNameIri };
// connection.begin(IsolationLevels.SERIALIZABLE);
// connection.clear(graphNameIri);
// connection.clear();
connection.remove((IRI) null, (IRI) null, null, contexts);
// connection.remove(graphNameIri, (IRI) null, null,contexts);//graphNameIri);
// connection.remove((Resource) null, (IRI) null, null);//graphNameIri);
// connection.commit();
logger.debug("Removed graph {} ", graphNameIri.stringValue());
} else {
logger.error("Failed to remove graph {} ", graphNameIri.stringValue());
return null;
// throw new ServerException(FAILEDTOREMOVEGRAPH_EXCEPTION, String.format("Failed to remove graph %s. Does not exist", graphName));
}
} catch (Exception qe) {
throw new ServerException(FAILEDTOREMOVEGRAPH_EXCEPTION, String.format("Failed to remove graph %s", graphName, qe.getMessage()), qe);
}
return graphNameIri;
}
use of com.inova8.intelligentgraph.exceptions.ServerException in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphRepository method addGraph.
/**
* Adds the graph.
*
* @param graphName the graph name
* @return the graph
*/
public Graph addGraph(String graphName) {
ContextAwareConnection connection = this.getContextAwareConnection();
Model result;
IRI graphNameIri = null;
try {
graphNameIri = PathParser.parseIriRef(getRepositoryContext(), graphName).getIri();
result = new LinkedHashModel();
((Model) result).add(graphNameIri, SCRIPT.CACHE_DATE_TIME, literal(new Date()), graphNameIri);
((Model) result).add(graphNameIri, SCRIPT.ISPRIVATE, literal(true), graphNameIri);
connection.add((Model) result, graphNameIri);
Graph addedGraph = new Graph(this, graphNameIri);
graphs.put(graphNameIri, addedGraph);
getPublicContexts().add(graphNameIri);
logger.debug("Added new graph {} ", graphNameIri.stringValue());
} catch (Exception qe) {
throw new ServerException(FAILEDTOADDGRAPH_EXCEPTION, String.format("Failed to add graph %s with exception %s", graphName, qe.getMessage()), qe);
}
return new Graph(this, graphNameIri);
}
use of com.inova8.intelligentgraph.exceptions.ServerException in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphRepository method openGraph.
/**
* Open graph.
*
* @param graphName the graph name
* @return the graph
*/
public Graph openGraph(String graphName) {
// .getContextAwareConnection();
RepositoryConnection connection = this.getRepository().getConnection();
IRI graphNameIri = null;
try {
graphNameIri = PathParser.parseIriRef(getRepositoryContext(), graphName).getIri();
@SuppressWarnings("deprecation") Boolean contextExists = connection.getContextIDs().asList().contains(graphNameIri);
if (!contextExists) {
addGraph(graphName);
} else {
getPublicContexts().add(graphNameIri);
}
logger.debug("Got graph {} ", graphNameIri.stringValue());
} catch (Exception qe) {
throw new ServerException(FAILEDTOOPENGRAPH_EXCEPTION, String.format("Failed to get graph %s with exception %s", graphName, qe.getMessage()), qe);
}
return new Graph(this, graphNameIri);
}
Aggregations