use of org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.ModelValidator in project scheduling by ow2-proactive.
the class ModelFromURLParserValidator method createValidator.
@Override
protected Validator<String> createValidator(String model, Converter<String> converter) throws ModelSyntaxException {
String modelFromUrlRegexp = "^" + MODEL_FROM_URL_TYPE_REGEXP + LEFT_DELIMITER_REGEXP + "(.+)" + RIGHT_DELIMITER_REGEXP + "$";
String urlString = parseAndGetOneGroup(model, modelFromUrlRegexp);
URL url = null;
try {
url = new URL(urlString);
List<String> lines = IOUtils.readLines(url.openStream(), Charset.defaultCharset());
String modelReceivedFromURL = null;
modelReceivedFromURL = findFirstNonEmptyLineTrimmed(lines);
if (Strings.isNullOrEmpty(modelReceivedFromURL)) {
throw new ModelSyntaxException("In " + getType() + " expression, model received from defined url '" + urlString + "' is empty.");
}
if (modelReceivedFromURL.startsWith(MODEL_FROM_URL_TYPE)) {
throw new ModelSyntaxException("In " + getType() + " expression, model received from defined url '" + urlString + "' is recursive.");
}
return new ModelValidator(modelReceivedFromURL);
} catch (MalformedURLException e) {
throw new ModelSyntaxException("In " + getType() + " expression, defined url '" + urlString + "' is invalid: " + e.getMessage(), e);
} catch (IOException e) {
throw new ModelSyntaxException("In " + getType() + " expression, defined url '" + urlString + "' could not be reached: " + e.getMessage(), e);
}
}
Aggregations