Search in sources :

Example 1 with InternalErrorException

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

the class Eval method evalGraph.

static Table evalGraph(OpGraph opGraph, Evaluator evaluator) {
    ExecutionContext execCxt = evaluator.getExecContext();
    if (!Var.isVar(opGraph.getNode())) {
        DatasetGraph dsg = execCxt.getDataset();
        Node graphNode = opGraph.getNode();
        if (!dsg.containsGraph(graphNode))
            return new TableEmpty();
        Graph graph = execCxt.getDataset().getGraph(opGraph.getNode());
        if (// But contains was true?!!
        graph == null)
            throw new InternalErrorException("Graph was present, now it's not");
        ExecutionContext execCxt2 = new ExecutionContext(execCxt, graph);
        Evaluator e2 = EvaluatorFactory.create(execCxt2);
        return eval(e2, opGraph.getSubOp());
    }
    // Graph node is a variable.
    Var gVar = Var.alloc(opGraph.getNode());
    Table current = null;
    for (Iterator<Node> iter = execCxt.getDataset().listGraphNodes(); iter.hasNext(); ) {
        Node gn = iter.next();
        Graph graph = execCxt.getDataset().getGraph(gn);
        ExecutionContext execCxt2 = new ExecutionContext(execCxt, graph);
        Evaluator e2 = EvaluatorFactory.create(execCxt2);
        Table tableVarURI = TableFactory.create(gVar, gn);
        // Evaluate the pattern, join with this graph node possibility.
        // XXX If Var.ANON then no-opt.
        Table patternTable = eval(e2, opGraph.getSubOp());
        Table stepResult = evaluator.join(patternTable, tableVarURI);
        if (current == null)
            current = stepResult;
        else
            current = evaluator.union(current, stepResult);
    }
    if (current == null)
        // Nothing to loop over
        return new TableEmpty();
    return current;
}
Also used : ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) OpGraph(org.apache.jena.sparql.algebra.op.OpGraph) Graph(org.apache.jena.graph.Graph) Table(org.apache.jena.sparql.algebra.Table) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) TableEmpty(org.apache.jena.sparql.algebra.table.TableEmpty) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 2 with InternalErrorException

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

the class FusekiServer method configFromTemplate.

private static DataAccessPoint configFromTemplate(String templateFile, String datasetPath, boolean allowUpdate, Map<String, String> params) {
    DatasetDescriptionRegistry registry = FusekiServer.registryForBuild();
    // ---- Setup
    if (params == null) {
        params = new HashMap<>();
        params.put(Template.NAME, datasetPath);
    } else {
        if (!params.containsKey(Template.NAME)) {
            Fuseki.configLog.warn("No NAME found in template parameters (added)");
            params.put(Template.NAME, datasetPath);
        }
    }
    //-- Logging
    Fuseki.configLog.info("Template file: " + templateFile);
    String dir = params.get(Template.DIR);
    if (dir != null) {
        if (Objects.equals(dir, Names.memName)) {
            Fuseki.configLog.info("TDB dataset: in-memory");
        } else {
            if (!FileOps.exists(dir))
                throw new CmdException("Directory not found: " + dir);
            Fuseki.configLog.info("TDB dataset: directory=" + dir);
        }
    }
    //-- Logging
    datasetPath = DataAccessPoint.canonical(datasetPath);
    // DRY -- ActionDatasets (and others?)
    addGlobals(params);
    String str = TemplateFunctions.templateFile(templateFile, params, Lang.TTL);
    Lang lang = RDFLanguages.filenameToLang(str, Lang.TTL);
    StringReader sr = new StringReader(str);
    Model model = ModelFactory.createDefaultModel();
    RDFDataMgr.read(model, sr, datasetPath, lang);
    // ---- DataAccessPoint
    Statement stmt = getOne(model, null, FusekiVocab.pServiceName, null);
    if (stmt == null) {
        StmtIterator sIter = model.listStatements(null, FusekiVocab.pServiceName, (RDFNode) null);
        if (!sIter.hasNext())
            ServletOps.errorBadRequest("No name given in description of Fuseki service");
        sIter.next();
        if (sIter.hasNext())
            ServletOps.errorBadRequest("Multiple names given in description of Fuseki service");
        throw new InternalErrorException("Inconsistent: getOne didn't fail the second time");
    }
    Resource subject = stmt.getSubject();
    if (!allowUpdate) {
    // Opportunity for more sophisticated "read-only" mode.
    //  1 - clean model, remove "fu:serviceUpdate", "fu:serviceUpload", "fu:serviceReadGraphStore", "fu:serviceReadWriteGraphStore"
    //  2 - set a flag on DataAccessPoint
    }
    DataAccessPoint dap = FusekiBuilder.buildDataAccessPoint(subject, registry);
    return dap;
}
Also used : CmdException(jena.cmd.CmdException) StringReader(java.io.StringReader) Lang(org.apache.jena.riot.Lang) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException)

Example 3 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 4 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 5 with InternalErrorException

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

the class BaseSetupRDFS method execCheck.

// Calculate using SPARQL and see if we get the same answer.
private void execCheck(String path, Graph vocab, Map<X, Set<X>> supers, Map<X, Set<X>> subs) {
    Map<X, Set<X>> mSupers = new HashMap<>();
    Map<X, Set<X>> mSubs = new HashMap<>();
    String queryString = "SELECT ?x ?y { ?x " + path + " ?y }";
    exec(queryString, vocab, mSupers, mSubs);
    if (!mSupers.equals(supers) || !mSubs.equals(subs))
        throw new InternalErrorException(path);
}
Also used : InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException)

Aggregations

InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)48 Node (org.apache.jena.graph.Node)14 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)4 AccessStep (org.apache.jena.dboe.trans.bplustree.AccessPath.AccessStep)3 Graph (org.apache.jena.graph.Graph)3 Triple (org.apache.jena.graph.Triple)3 Var (org.apache.jena.sparql.core.Var)3 StringReader (java.io.StringReader)2 DataAccessPoint (org.apache.jena.fuseki.server.DataAccessPoint)2 Dataset (org.apache.jena.query.Dataset)2 Model (org.apache.jena.rdf.model.Model)2 Lang (org.apache.jena.riot.Lang)2 RiotException (org.apache.jena.riot.RiotException)2 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)2 Table (org.apache.jena.sparql.algebra.Table)2 OpGraph (org.apache.jena.sparql.algebra.op.OpGraph)2 TableEmpty (org.apache.jena.sparql.algebra.table.TableEmpty)2 ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)2 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)2 Binding (org.apache.jena.sparql.engine.binding.Binding)2