Search in sources :

Example 1 with ModelSyntaxException

use of org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException 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);
    }
}
Also used : ModelSyntaxException(org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException) MalformedURLException(java.net.MalformedURLException) ModelValidator(org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.ModelValidator) IOException(java.io.IOException) URL(java.net.URL)

Example 2 with ModelSyntaxException

use of org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException in project scheduling by ow2-proactive.

the class BaseParserValidator method parseAndGetRegexGroups.

protected static List<String> parseAndGetRegexGroups(String valueToParse, String regexp) throws ModelSyntaxException {
    try {
        Pattern pattern = Pattern.compile(regexp);
        Matcher matcher = pattern.matcher(valueToParse);
        if (matcher.find()) {
            return getMatchedGroups(matcher, matcher.groupCount());
        } else {
            throw new ModelSyntaxException("Expression '" + valueToParse + "' does not match " + regexp);
        }
    } catch (PatternSyntaxException e) {
        throw new ModelSyntaxException("Internal error, regular expression '" + regexp + "' is invalid: " + e.getMessage(), e);
    }
}
Also used : Pattern(java.util.regex.Pattern) ModelSyntaxException(org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException) Matcher(java.util.regex.Matcher) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 3 with ModelSyntaxException

use of org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException in project scheduling by ow2-proactive.

the class RangeParserValidator method createValidator.

@Override
protected Validator<T> createValidator(String model, Converter<T> converter) throws ModelSyntaxException {
    if (model.matches(getTypeRegexp())) {
        return new RangeValidator();
    }
    String mainRangeRegexp = "^" + getTypeRegexp() + RANGE_MAIN_REGEXP + "$";
    String rangeString = parseAndGetOneGroup(model, mainRangeRegexp);
    try {
        return new RangeValidator<>(extractRange(rangeString, converter));
    } catch (IllegalArgumentException e) {
        throw new ModelSyntaxException(e.getMessage(), e);
    }
}
Also used : ModelSyntaxException(org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException) RangeValidator(org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.RangeValidator)

Example 4 with ModelSyntaxException

use of org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException in project scheduling by ow2-proactive.

the class RegexpParserValidator method createValidator.

@Override
protected Validator<String> createValidator(String model, Converter<String> converter) throws ModelSyntaxException {
    String regexpRegexp = "^" + REGEXP_TYPE_REGEXP + LEFT_DELIMITER_REGEXP + "(.+)" + RIGHT_DELIMITER_REGEXP + "$";
    String regexpString = parseAndGetOneGroup(model, regexpRegexp);
    try {
        return new RegexpValidator(regexpString);
    } catch (PatternSyntaxException e) {
        throw new ModelSyntaxException(e.getMessage(), e);
    }
}
Also used : ModelSyntaxException(org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException) RegexpValidator(org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.RegexpValidator) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 5 with ModelSyntaxException

use of org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException in project scheduling by ow2-proactive.

the class SPELParserValidator method createValidator.

@Override
protected Validator<String> createValidator(String model, Converter<String> converter) throws ModelSyntaxException {
    String spelRegexp = "^" + SPEL_TYPE_REGEXP + LEFT_DELIMITER_REGEXP + "(.+)" + RIGHT_DELIMITER_REGEXP + "$";
    String spelString = parseAndGetOneGroup(model, spelRegexp);
    try {
        return new SpelValidator(spelString);
    } catch (ParseException e) {
        throw new ModelSyntaxException(e.getMessage(), e);
    }
}
Also used : ModelSyntaxException(org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException) SpelValidator(org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.SpelValidator) ParseException(org.springframework.expression.ParseException)

Aggregations

ModelSyntaxException (org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException)5 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 ModelValidator (org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.ModelValidator)1 RangeValidator (org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.RangeValidator)1 RegexpValidator (org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.RegexpValidator)1 SpelValidator (org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.SpelValidator)1 ParseException (org.springframework.expression.ParseException)1