use of org.apache.solr.util.JsonSchemaValidator in project lucene-solr by apache.
the class ApiBag method getCommandOperations.
public static List<CommandOperation> getCommandOperations(Reader reader, Map<String, JsonSchemaValidator> validators, boolean validate) {
List<CommandOperation> parsedCommands = null;
try {
parsedCommands = CommandOperation.parse(reader);
} catch (IOException e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
if (validators == null || !validate) {
// no validation possible because we do not have a spec
return parsedCommands;
}
List<CommandOperation> commandsCopy = CommandOperation.clone(parsedCommands);
for (CommandOperation cmd : commandsCopy) {
JsonSchemaValidator validator = validators.get(cmd.name);
if (validator == null) {
cmd.addError(formatString("Unknown operation ''{0}'' available ops are ''{1}''", cmd.name, validators.keySet()));
continue;
} else {
List<String> errs = validator.validateJson(cmd.getCommandData());
if (errs != null)
for (String err : errs) cmd.addError(err);
}
}
List<Map> errs = CommandOperation.captureErrors(commandsCopy);
if (!errs.isEmpty()) {
throw new ExceptionWithErrObject(SolrException.ErrorCode.BAD_REQUEST, "Error in command payload", errs);
}
return commandsCopy;
}
Aggregations