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;
}
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]);
}
}
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);
}
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();
}
}
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);
}
Aggregations