Search in sources :

Example 1 with ServerException

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;
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) ServerException(com.inova8.intelligentgraph.exceptions.ServerException) IRI(org.eclipse.rdf4j.model.IRI) NullValueReturnedException(com.inova8.intelligentgraph.exceptions.NullValueReturnedException) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) ScriptException(javax.script.ScriptException) ServerException(com.inova8.intelligentgraph.exceptions.ServerException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) PathPatternException(com.inova8.pathql.processor.PathPatternException) RecognitionException(org.antlr.v4.runtime.RecognitionException)

Example 2 with ServerException

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);
    }
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) IRI(org.eclipse.rdf4j.model.IRI) ServerException(com.inova8.intelligentgraph.exceptions.ServerException) NullValueReturnedException(com.inova8.intelligentgraph.exceptions.NullValueReturnedException) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) ScriptException(javax.script.ScriptException) ServerException(com.inova8.intelligentgraph.exceptions.ServerException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) PathPatternException(com.inova8.pathql.processor.PathPatternException) RecognitionException(org.antlr.v4.runtime.RecognitionException)

Example 3 with ServerException

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;
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) IRI(org.eclipse.rdf4j.model.IRI) ServerException(com.inova8.intelligentgraph.exceptions.ServerException) Resource(org.eclipse.rdf4j.model.Resource) NullValueReturnedException(com.inova8.intelligentgraph.exceptions.NullValueReturnedException) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) ScriptException(javax.script.ScriptException) ServerException(com.inova8.intelligentgraph.exceptions.ServerException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) PathPatternException(com.inova8.pathql.processor.PathPatternException) RecognitionException(org.antlr.v4.runtime.RecognitionException)

Example 4 with ServerException

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);
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) ServerException(com.inova8.intelligentgraph.exceptions.ServerException) ContextAwareConnection(org.eclipse.rdf4j.repository.contextaware.ContextAwareConnection) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Date(java.util.Date) NullValueReturnedException(com.inova8.intelligentgraph.exceptions.NullValueReturnedException) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) ScriptException(javax.script.ScriptException) ServerException(com.inova8.intelligentgraph.exceptions.ServerException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) PathPatternException(com.inova8.pathql.processor.PathPatternException) RecognitionException(org.antlr.v4.runtime.RecognitionException)

Example 5 with ServerException

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);
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) IRI(org.eclipse.rdf4j.model.IRI) ServerException(com.inova8.intelligentgraph.exceptions.ServerException) NullValueReturnedException(com.inova8.intelligentgraph.exceptions.NullValueReturnedException) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) ScriptException(javax.script.ScriptException) ServerException(com.inova8.intelligentgraph.exceptions.ServerException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) PathPatternException(com.inova8.pathql.processor.PathPatternException) RecognitionException(org.antlr.v4.runtime.RecognitionException)

Aggregations

NullValueReturnedException (com.inova8.intelligentgraph.exceptions.NullValueReturnedException)5 ServerException (com.inova8.intelligentgraph.exceptions.ServerException)5 PathPatternException (com.inova8.pathql.processor.PathPatternException)5 ScriptException (javax.script.ScriptException)5 RecognitionException (org.antlr.v4.runtime.RecognitionException)5 IRI (org.eclipse.rdf4j.model.IRI)5 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)5 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)5 RepositoryConnection (org.eclipse.rdf4j.repository.RepositoryConnection)4 Date (java.util.Date)1 Model (org.eclipse.rdf4j.model.Model)1 Resource (org.eclipse.rdf4j.model.Resource)1 LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)1 ContextAwareConnection (org.eclipse.rdf4j.repository.contextaware.ContextAwareConnection)1