Example usage for org.apache.commons.jexl3 JexlException toString

List of usage examples for org.apache.commons.jexl3 JexlException toString

Introduction

In this page you can find the example usage for org.apache.commons.jexl3 JexlException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.streamsets.datacollector.antennadoctor.engine.AntennaDoctorEngine.java

private List<AntennaDoctorMessage> evaluate(AntennaDoctorContext context, AntennaDoctorRuleBean.Entity entity,
        JexlContext jexlContext) {/*w w w .  j  a  v  a  2 s  . co m*/
    // All our expressions have the sdc object available
    jexlContext.set("sdc", new SdcJexl(context));

    ImmutableList.Builder<AntennaDoctorMessage> builder = ImmutableList.builder();

    // Iterate over rules and try to match them
    for (RuntimeRule rule : this.rules) {
        // Static check to execute only relevant rules
        if (rule.getEntity() != entity) {
            continue;
        }

        // Reset the variables that the rule is keeping
        jexlContext.set("context", new HashMap<>());

        // Firstly evaluate conditions
        boolean matched = true;
        for (String condition : rule.getConditions()) {
            LOG.trace("Evaluating rule {} condition {}", rule.getUuid(), condition);
            try {
                if (!evaluateCondition(condition, jexlContext)) {
                    matched = false;
                    break;
                }
            } catch (JexlException e) {
                matched = false;
                LOG.error("Failed to evaluate rule {} condition {}: {}", rule.getUuid(), condition,
                        e.toString(), e);
                break;
            }
        }

        // If all rules succeeded, evaluate message
        if (matched) {
            LOG.trace("Rule {} matched!", rule.getUuid());
            try {
                StringWriter summaryWriter = new StringWriter();
                StringWriter descriptionWriter = new StringWriter();

                LOG.trace("Evaluating summary for rule {}: {}", rule.getUuid(), rule.getSummary());
                templateEngine.createTemplate(rule.getSummary()).evaluate(jexlContext, summaryWriter);

                LOG.trace("Evaluating description for rule {}: {}", rule.getUuid(), rule.getDescription());
                templateEngine.createTemplate(rule.getDescription()).evaluate(jexlContext, descriptionWriter);

                builder.add(new AntennaDoctorMessage(summaryWriter.toString(), descriptionWriter.toString()));
            } catch (JexlException e) {
                LOG.error("Failed to evaluate message for rule {}: {}", rule.getUuid(), e.toString(), e);
            }
        } else {
            LOG.trace("Rule {} did not match", rule.getUuid());
        }
    }

    return builder.build();
}