Search in sources :

Example 16 with CmdException

use of jena.cmd.CmdException 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 17 with CmdException

use of jena.cmd.CmdException in project jena by apache.

the class DBTest method setParams.

private void setParams(List<String> args) {
    for (String s : args) {
        String[] frags = s.split("=", 2);
        if (frags.length != 2)
            throw new CmdException("Can't split '" + s + "'");
        params.put(frags[0], frags[1]);
    }
}
Also used : CmdException(jena.cmd.CmdException)

Example 18 with CmdException

use of jena.cmd.CmdException in project jena by apache.

the class spatialindexdump method processModulesAndArgs.

@Override
protected void processModulesAndArgs() {
    super.processModulesAndArgs();
    // Two forms : with and without arg.
    // Maximises similarity with other tools.
    String file;
    if (super.contains(assemblerDescDecl)) {
        if (getValues(assemblerDescDecl).size() != 1)
            throw new CmdException("Multiple assembler descriptions given");
        if (getPositional().size() != 0)
            throw new CmdException("Additional assembler descriptions given");
        file = getValue(assemblerDescDecl);
    } else {
        if (getNumPositional() != 1)
            throw new CmdException("Multiple assembler descriptions given");
        file = getPositionalArg(0);
    }
    spatialIndex = (SpatialIndex) AssemblerUtils.build(file, SpatialVocab.spatialIndex);
}
Also used : CmdException(jena.cmd.CmdException)

Example 19 with CmdException

use of jena.cmd.CmdException in project jena by apache.

the class CmdLangParse method exec$.

protected void exec$() {
    if (modLangParse.getRDFSVocab() != null)
        setup = new InferenceSetupRDFS(modLangParse.getRDFSVocab());
    if (modLangOutput.compressedOutput()) {
        try {
            outputWrite = new GZIPOutputStream(outputWrite, true);
        } catch (IOException e) {
            IO.exception(e);
        }
    }
    outputStream = null;
    PostParseHandler postParse = null;
    outputStream = createStreamSink();
    if (outputStream == null) {
        Pair<StreamRDF, PostParseHandler> p = createAccumulateSink();
        outputStream = p.getLeft();
        postParse = p.getRight();
    }
    try {
        // The actual parsing ... 
        if (super.getPositional().isEmpty()) {
            ParseRecord parseRec = parseFile("-");
            outcome(parseRec);
        } else {
            boolean b = super.getPositional().size() > 1;
            for (String fn : super.getPositional()) {
                if (b && !super.isQuiet())
                    SysRIOT.getLogger().info("File: " + fn);
                ParseRecord parseRec = parseFile(fn);
                outcome(parseRec);
            }
        }
        if (postParse != null)
            postParse.postParse();
        // Total if more than one file.
        if (super.getPositional().size() > 1 && modTime.timingEnabled()) {
            long totalMillis = 0;
            long totalTriples = 0;
            long totalQuads = 0;
            long totalTuples = 0;
            boolean allSuccessful = true;
            for (ParseRecord pRec : outcomes) {
                if (pRec.timeMillis >= 0)
                    totalMillis += pRec.timeMillis;
                totalTriples += pRec.triples;
                totalQuads += pRec.quads;
                totalTuples += pRec.tuples;
                allSuccessful = allSuccessful & pRec.success;
            }
            output("Total", true, totalTriples, totalQuads, totalTuples, totalMillis);
        }
    } finally {
        if (outputWrite != System.out)
            IO.close(outputWrite);
        else
            IO.flush(outputWrite);
        System.err.flush();
    }
    // exit(1) if there were any errors.
    for (ParseRecord pr : outcomes) {
        if (!pr.success)
            throw new CmdException();
    }
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) CmdException(jena.cmd.CmdException) IOException(java.io.IOException) InferenceSetupRDFS(org.apache.jena.riot.process.inf.InferenceSetupRDFS)

Example 20 with CmdException

use of jena.cmd.CmdException in project jena by apache.

the class infer method processModulesAndArgs.

@Override
protected void processModulesAndArgs() {
    if (!contains(argRDFS))
        throw new CmdException("Required argument missing: --" + argRDFS.getKeyName());
    String fn = getValue(argRDFS);
    vocab = FileManager.get().loadModel(fn);
}
Also used : CmdException(jena.cmd.CmdException)

Aggregations

CmdException (jena.cmd.CmdException)32 Lang (org.apache.jena.riot.Lang)8 Dataset (org.apache.jena.query.Dataset)6 Node (org.apache.jena.graph.Node)3 Model (org.apache.jena.rdf.model.Model)3 JenaException (org.apache.jena.shared.JenaException)3 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)3 ArgDecl (jena.cmd.ArgDecl)2 TerminationException (jena.cmd.TerminationException)2 IndentedWriter (org.apache.jena.atlas.io.IndentedWriter)2 Graph (org.apache.jena.graph.Graph)2 RiotException (org.apache.jena.riot.RiotException)2 PrefixMapping (org.apache.jena.shared.PrefixMapping)2 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)2 Transactional (org.apache.jena.sparql.core.Transactional)2 TransactionalNull (org.apache.jena.sparql.core.TransactionalNull)2 ResultSetException (org.apache.jena.sparql.resultset.ResultSetException)2 UpdateRequest (org.apache.jena.update.UpdateRequest)2 ModDataset (arq.cmdline.ModDataset)1 IOException (java.io.IOException)1