Search in sources :

Example 6 with JexlException

use of org.apache.commons.jexl2.JexlException in project dbeaver by serge-rider.

the class AbstractDescriptor method parseExpression.

public static Expression parseExpression(String exprString) throws DBException {
    synchronized (AbstractDescriptor.class) {
        if (jexlEngine == null) {
            jexlEngine = new JexlEngine(null, null, null, null);
            jexlEngine.setCache(100);
        }
    }
    try {
        return jexlEngine.createExpression(exprString);
    } catch (JexlException e) {
        throw new DBException("Bad expression", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) JexlEngine(org.apache.commons.jexl2.JexlEngine) JexlException(org.apache.commons.jexl2.JexlException)

Example 7 with JexlException

use of org.apache.commons.jexl2.JexlException in project dbeaver by dbeaver.

the class AbstractDescriptor method parseExpression.

public static Expression parseExpression(String exprString) throws DBException {
    synchronized (AbstractDescriptor.class) {
        if (jexlEngine == null) {
            jexlEngine = new JexlEngine(null, null, null, null);
            jexlEngine.setCache(100);
        }
    }
    try {
        return jexlEngine.createExpression(exprString);
    } catch (JexlException e) {
        throw new DBException("Bad expression", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) JexlEngine(org.apache.commons.jexl2.JexlEngine) JexlException(org.apache.commons.jexl2.JexlException)

Example 8 with JexlException

use of org.apache.commons.jexl2.JexlException in project opennms by OpenNMS.

the class JexlIndexStorageStrategy method getResourceNameFromIndex.

/**
 * {@inheritDoc}
 */
@Override
public String getResourceNameFromIndex(CollectionResource resource) {
    String resourceName = null;
    try {
        UnifiedJEXL.Expression expr = EL.parse(m_parameters.get(PARAM_INDEX_FORMAT));
        JexlContext context = new MapContext();
        m_parameters.entrySet().forEach((entry) -> {
            context.set(entry.getKey(), entry.getValue());
        });
        updateContext(context, resource);
        resourceName = (String) expr.evaluate(new ReadonlyContext(context));
    } catch (JexlException e) {
        LOG.error("getResourceNameFromIndex(): error evaluating index-format [{}] as a Jexl Expression", m_parameters.get(PARAM_INDEX_FORMAT), e);
    } finally {
        if (resourceName == null) {
            resourceName = resource.getInstance();
        }
    }
    if ("true".equals(m_parameters.get(PARAM_CLEAN_OUTPUT)) && resourceName != null) {
        resourceName = resourceName.replaceAll("\\s+", "_").replaceAll(":", "_").replaceAll("\\\\", "_").replaceAll("[\\[\\]]", "_").replaceAll("[|/]", "_").replaceAll("=", "").replaceAll("[_]+$", "").replaceAll("___", "_");
    }
    LOG.debug("getResourceNameFromIndex(): {}", resourceName);
    return resourceName;
}
Also used : UnifiedJEXL(org.apache.commons.jexl2.UnifiedJEXL) JexlException(org.apache.commons.jexl2.JexlException) JexlContext(org.apache.commons.jexl2.JexlContext) ReadonlyContext(org.apache.commons.jexl2.ReadonlyContext) MapContext(org.apache.commons.jexl2.MapContext)

Example 9 with JexlException

use of org.apache.commons.jexl2.JexlException in project traccar by tananaev.

the class ComputedAttributesHandler method handlePosition.

@Override
protected Position handlePosition(Position position) {
    Collection<Attribute> attributes = attributesManager.getItems(attributesManager.getAllDeviceItems(position.getDeviceId()));
    for (Attribute attribute : attributes) {
        if (attribute.getAttribute() != null) {
            Object result = null;
            try {
                result = computeAttribute(attribute, position);
            } catch (JexlException error) {
                LOGGER.warn("Attribute computation error", error);
            }
            if (result != null) {
                try {
                    switch(attribute.getType()) {
                        case "number":
                            Number numberValue = (Number) result;
                            position.getAttributes().put(attribute.getAttribute(), numberValue);
                            break;
                        case "boolean":
                            Boolean booleanValue = (Boolean) result;
                            position.getAttributes().put(attribute.getAttribute(), booleanValue);
                            break;
                        default:
                            position.getAttributes().put(attribute.getAttribute(), result.toString());
                    }
                } catch (ClassCastException error) {
                    LOGGER.warn("Attribute cast error", error);
                }
            }
        }
    }
    return position;
}
Also used : Attribute(org.traccar.model.Attribute) JexlException(org.apache.commons.jexl2.JexlException)

Example 10 with JexlException

use of org.apache.commons.jexl2.JexlException in project easy-rules by j-easy.

the class JexlAction method execute.

@Override
public void execute(Facts facts) {
    Objects.requireNonNull(facts, "facts cannot be null");
    MapContext ctx = new MapContext(facts.asMap());
    try {
        compiledScript.execute(ctx);
    } catch (JexlException e) {
        LOGGER.error("Unable to execute expression: '" + expression + "' on facts: " + facts, e);
        throw e;
    }
}
Also used : JexlException(org.apache.commons.jexl3.JexlException) MapContext(org.apache.commons.jexl3.MapContext)

Aggregations

JexlException (org.apache.commons.jexl2.JexlException)9 MapContext (org.apache.commons.jexl2.MapContext)4 JexlContext (org.apache.commons.jexl2.JexlContext)3 Attribute (org.traccar.model.Attribute)3 JexlEngine (org.apache.commons.jexl2.JexlEngine)2 DBException (org.jkiss.dbeaver.DBException)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Expression (org.apache.commons.jexl2.Expression)1 ReadonlyContext (org.apache.commons.jexl2.ReadonlyContext)1 UnifiedJEXL (org.apache.commons.jexl2.UnifiedJEXL)1 JexlException (org.apache.commons.jexl3.JexlException)1 MapContext (org.apache.commons.jexl3.MapContext)1 ExpressionException (org.opennms.netmgt.measurements.api.exceptions.ExpressionException)1 Expression (org.opennms.netmgt.measurements.model.Expression)1