Search in sources :

Example 6 with InternalErrorException

use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.

the class SPARQL_QueryGeneral method datasetFromDescriptionWeb.

/**
     * Construct a Dataset based on a dataset description. Loads graph from the
     * web.
     */
protected Dataset datasetFromDescriptionWeb(HttpAction action, DatasetDescription datasetDesc) {
    try {
        if (datasetDesc == null)
            return null;
        if (datasetDesc.isEmpty())
            return null;
        List<String> graphURLs = datasetDesc.getDefaultGraphURIs();
        List<String> namedGraphs = datasetDesc.getNamedGraphURIs();
        if (graphURLs.size() == 0 && namedGraphs.size() == 0)
            return null;
        Dataset dataset = DatasetFactory.create();
        // Look in cache for loaded graphs!!
        // ---- Default graph
        {
            Model model = ModelFactory.createDefaultModel();
            for (String uri : graphURLs) {
                if (uri == null || uri.equals(""))
                    throw new InternalErrorException("Default graph URI is null or the empty string");
                try {
                    GraphLoadUtils.loadModel(model, uri, MaxTriples);
                    action.log.info(format("[%d] Load (default graph) %s", action.id, uri));
                } catch (RiotException ex) {
                    action.log.info(format("[%d] Parsing error loading %s: %s", action.id, uri, ex.getMessage()));
                    ServletOps.errorBadRequest("Failed to load URL (parse error) " + uri + " : " + ex.getMessage());
                } catch (Exception ex) {
                    action.log.info(format("[%d] Failed to load (default) %s: %s", action.id, uri, ex.getMessage()));
                    ServletOps.errorBadRequest("Failed to load URL " + uri);
                }
            }
            dataset.setDefaultModel(model);
        }
        // ---- Named graphs
        if (namedGraphs != null) {
            for (String uri : namedGraphs) {
                if (uri == null || uri.equals(""))
                    throw new InternalErrorException("Named graph URI is null or the empty string");
                try {
                    Model model = ModelFactory.createDefaultModel();
                    GraphLoadUtils.loadModel(model, uri, MaxTriples);
                    action.log.info(format("[%d] Load (named graph) %s", action.id, uri));
                    dataset.addNamedModel(uri, model);
                } catch (RiotException ex) {
                    action.log.info(format("[%d] Parsing error loading %s: %s", action.id, uri, ex.getMessage()));
                    ServletOps.errorBadRequest("Failed to load URL (parse error) " + uri + " : " + ex.getMessage());
                } catch (Exception ex) {
                    action.log.info(format("[%d] Failed to load (named graph) %s: %s", action.id, uri, ex.getMessage()));
                    ServletOps.errorBadRequest("Failed to load URL " + uri);
                }
            }
        }
        return dataset;
    } catch (ActionErrorException ex) {
        throw ex;
    } catch (Exception ex) {
        action.log.info(format("[%d] SPARQL parameter error: " + ex.getMessage(), action.id, ex));
        ServletOps.errorBadRequest("Parameter error: " + ex.getMessage());
        return null;
    }
}
Also used : RiotException(org.apache.jena.riot.RiotException) Dataset(org.apache.jena.query.Dataset) Model(org.apache.jena.rdf.model.Model) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException) RiotException(org.apache.jena.riot.RiotException) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException)

Example 7 with InternalErrorException

use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.

the class SpatialOperationPFBase method exec.

@Override
public QueryIterator exec(Binding binding, PropFuncArg argSubject, Node predicate, PropFuncArg argObject, ExecutionContext execCxt) {
    if (server == null) {
        if (!warningIssued) {
            Log.warn(getClass(), "No spatial index - no spatial search performed");
            warningIssued = true;
        }
        // Not a text dataset - no-op
        return IterLib.result(binding, execCxt);
    }
    argSubject = Substitute.substitute(argSubject, binding);
    argObject = Substitute.substitute(argObject, binding);
    if (!argSubject.isNode())
        throw new InternalErrorException("Subject is not a node (it was earlier!)");
    Node s = argSubject.getArg();
    if (s.isLiteral())
        // Does not match
        return IterLib.noResults(execCxt);
    SpatialMatch match = objectToStruct(argObject);
    if (match == null) {
        // can't match
        return IterLib.noResults(execCxt);
    }
    // ----
    QueryIterator qIter = (Var.isVar(s)) ? variableSubject(binding, s, match, execCxt) : concreteSubject(binding, s, match, execCxt);
    if (match.getLimit() >= 0)
        qIter = new QueryIterSlice(qIter, 0, match.getLimit(), execCxt);
    return qIter;
}
Also used : QueryIterSlice(org.apache.jena.sparql.engine.iterator.QueryIterSlice) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) Node(org.apache.jena.graph.Node) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException)

Example 8 with InternalErrorException

use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.

the class ExprTransformNodeElement method transform.

@Override
public Expr transform(ExprFunctionOp funcOp, ExprList args, Op opArg) {
    // Syntax phased only - ignore args and opArg
    Element elt = funcOp.getElement();
    Element elt1 = ElementTransformer.transform(elt, elementTransform, this, beforeVisitor, afterVisitor);
    if (elt == elt1)
        return funcOp;
    else {
        if (funcOp instanceof E_Exists)
            return new E_Exists(elt1);
        if (funcOp instanceof E_NotExists)
            return new E_NotExists(elt1);
        throw new InternalErrorException("Unknown ExprFunctionOp: " + funcOp.getFunctionSymbol());
    }
}
Also used : Element(org.apache.jena.sparql.syntax.Element) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException)

Example 9 with InternalErrorException

use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.

the class TransformElementLib method applyVar.

public static Var applyVar(Var v, ExprTransform exprTransform) {
    if (exprTransform == null)
        return v;
    ExprVar expr = new ExprVar(v);
    Expr e = exprTransform.transform(expr);
    if (e instanceof ExprVar)
        return ((ExprVar) e).asVar();
    throw new InternalErrorException("Managed to turn a variable " + v + " into " + e);
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) Expr(org.apache.jena.sparql.expr.Expr) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException)

Example 10 with InternalErrorException

use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.

the class CmdLangParse method createAccumulateSink.

/** Create an accumulating output stream for later pretty printing */
protected Pair<StreamRDF, PostParseHandler> createAccumulateSink() {
    final DatasetGraph dsg = DatasetGraphFactory.create();
    StreamRDF sink = StreamRDFLib.dataset(dsg);
    final RDFFormat fmt = modLangOutput.getOutputFormatted();
    PostParseHandler handler = new PostParseHandler() {

        @Override
        public void postParse() {
            // Try as dataset, then as graph.
            WriterDatasetRIOTFactory w = RDFWriterRegistry.getWriterDatasetFactory(fmt);
            if (w != null) {
                RDFDataMgr.write(outputWrite, dsg, fmt);
                return;
            }
            WriterGraphRIOTFactory wg = RDFWriterRegistry.getWriterGraphFactory(fmt);
            if (wg != null) {
                RDFDataMgr.write(System.out, dsg.getDefaultGraph(), fmt);
                return;
            }
            throw new InternalErrorException("failed to find the writer: " + fmt);
        }
    };
    return Pair.create(sink, handler);
}
Also used : InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Aggregations

InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)18 Node (org.apache.jena.graph.Node)5 Triple (org.apache.jena.graph.Triple)2 Dataset (org.apache.jena.query.Dataset)2 Model (org.apache.jena.rdf.model.Model)2 RiotException (org.apache.jena.riot.RiotException)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 Var (org.apache.jena.sparql.core.Var)2 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)2 Binding (org.apache.jena.sparql.engine.binding.Binding)2 Expr (org.apache.jena.sparql.expr.Expr)2 ExprVar (org.apache.jena.sparql.expr.ExprVar)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 StringReader (java.io.StringReader)1 CmdException (jena.cmd.CmdException)1 ContentType (org.apache.jena.atlas.web.ContentType)1 RDFDatatype (org.apache.jena.datatypes.RDFDatatype)1 DatasetDescriptionRegistry (org.apache.jena.fuseki.build.DatasetDescriptionRegistry)1 Graph (org.apache.jena.graph.Graph)1