Package org.apache.commons.jexl2

Examples of org.apache.commons.jexl2.ScriptTest$Tester


        return result;
    }

    public String evaluate(final String expression, final AbstractAttributable attributable) {

        final JexlContext jexlContext = new MapContext();

        if (attributable instanceof SyncopeUser) {
            SyncopeUser user = (SyncopeUser) attributable;

            jexlContext.set("username", user.getUsername() != null
                    ? user.getUsername()
                    : StringUtils.EMPTY);
            jexlContext.set("creationDate", user.getCreationDate() != null
                    ? user.getDateFormatter().format(user.getCreationDate())
                    : StringUtils.EMPTY);
            jexlContext.set("lastLoginDate", user.getLastLoginDate() != null
                    ? user.getDateFormatter().format(user.getLastLoginDate())
                    : StringUtils.EMPTY);
            jexlContext.set("failedLogins", user.getFailedLogins() != null
                    ? user.getFailedLogins()
                    : StringUtils.EMPTY);
            jexlContext.set("changePwdDate", user.getChangePwdDate() != null
                    ? user.getDateFormatter().format(user.getChangePwdDate())
                    : StringUtils.EMPTY);
        }

        addAttrsToContext(attributable.getAttributes(), jexlContext);
View Full Code Here


    }

    public JexlContext addAttrsToContext(final Collection<? extends AbstractAttr> attributes,
            final JexlContext jexlContext) {

        JexlContext context = jexlContext == null
                ? new MapContext()
                : jexlContext;

        for (AbstractAttr attribute : attributes) {
            List<String> attributeValues = attribute.getValuesAsStrings();
            String expressionValue = attributeValues.isEmpty()
                    ? StringUtils.EMPTY
                    : attributeValues.get(0);

            LOG.debug("Add attribute {} with value {}",
                    new Object[] { attribute.getSchema().getName(), expressionValue });

            context.set(attribute.getSchema().getName(), expressionValue);
        }

        return context;
    }
View Full Code Here

    }

    public JexlContext addDerAttrsToContext(final Collection<? extends AbstractDerAttr> derAttributes,
            final Collection<? extends AbstractAttr> attributes, final JexlContext jexlContext) {

        JexlContext context = jexlContext == null
                ? new MapContext()
                : jexlContext;

        for (AbstractDerAttr attribute : derAttributes) {
            String expressionValue = attribute.getValue(attributes);
            if (expressionValue == null) {
                expressionValue = StringUtils.EMPTY;
            }

            LOG.debug("Add derived attribute {} with value {}", new Object[] { attribute.getDerivedSchema().getName(),
                expressionValue });

            context.set(attribute.getDerivedSchema().getName(), expressionValue);
        }

        return context;
    }
View Full Code Here

        return context;
    }

    public String evaluate(final String expression, final AbstractAttributableTO attributableTO) {

        final JexlContext context = new MapContext();

        if (attributableTO instanceof UserTO) {
            UserTO user = (UserTO) attributableTO;

            context.set("username", user.getUsername() != null
                    ? user.getUsername()
                    : StringUtils.EMPTY);
            context.set("password", user.getPassword() != null
                    ? user.getPassword()
                    : StringUtils.EMPTY);
        }

        for (AttributeTO attribute : attributableTO.getAttributes()) {
            List<String> attributeValues = attribute.getValues();
            String expressionValue = attributeValues.isEmpty()
                    ? StringUtils.EMPTY
                    : attributeValues.get(0);

            LOG.debug("Add attribute {} with value {}", new Object[] { attribute.getSchema(), expressionValue });

            context.set(attribute.getSchema(), expressionValue);
        }
        for (AttributeTO attribute : attributableTO.getDerivedAttributes()) {
            List<String> attributeValues = attribute.getValues();
            String expressionValue = attributeValues.isEmpty()
                    ? StringUtils.EMPTY
                    : attributeValues.get(0);

            LOG.debug("Add attribute {} with value {}", new Object[] { attribute.getSchema(), expressionValue });

            context.set(attribute.getSchema(), expressionValue);
        }
        for (AttributeTO attribute : attributableTO.getVirtualAttributes()) {
            List<String> attributeValues = attribute.getValues();
            String expressionValue = attributeValues.isEmpty()
                    ? StringUtils.EMPTY
                    : attributeValues.get(0);

            LOG.debug("Add attribute {} with value {}", new Object[] { attribute.getSchema(), expressionValue });

            context.set(attribute.getSchema(), expressionValue);
        }

        // Evaluate expression using the context prepared before
        return evaluate(expression, context);
    }
View Full Code Here

    }

    private boolean evaluateMandatoryCondition(final String mandatoryCondition,
            final List<? extends AbstractAttr> attributes) {

        JexlContext jexlContext = new MapContext();
        jexlUtil.addAttrsToContext(attributes, jexlContext);

        return Boolean.parseBoolean(jexlUtil.evaluate(mandatoryCondition, jexlContext));
    }
View Full Code Here

     * {@link FeatureState#DISABLED} otherwise.
     */
    @Override
    public FeatureState process(final ContextManager contextManager)
    {
        final JexlEngine jexlEngine = new JexlEngine();
        Expression jexlExpression;
        if (expression != null) {
            jexlExpression = jexlEngine.createExpression(expression);
        } else {
            jexlExpression = getOldExpression(jexlEngine);
        }
       
        final Map<String, Object> contextMap = contextManager.getContext(context);
View Full Code Here

    public JexlExpressionParser(final Map<String, Object> vars) {
        if (vars == null) {
            throw new IllegalArgumentException("vars");
        }
       
        engine = new JexlEngine();
        context = new MapContext(vars);
        variables = vars;
       
        log.trace("Using variables: {}", vars);
    }
View Full Code Here

        Map<String, Object> sysVars = new HashMap<String, Object>();
        for (Entry<Object,Object> entry : System.getProperties().entrySet()){
            sysVars.put((String)entry.getKey(), entry.getValue());
        }
       
        engine = new JexlEngine();
        context = new MapContext(sysVars);
        variables = sysVars;
       
        log.trace("Using variables: {}", sysVars);
    }
View Full Code Here

    public JexlConditionParser(final Map<String, Object> vars) {
        if (vars == null) {
            throw new IllegalArgumentException("vars");
        }
        this.vars = vars;
        engine = new JexlEngine();
    }
View Full Code Here

    public JexlConditionParser() {
        // Setup the default vars
        vars = new HashMap<String, Object>();
        ParserUtils.addDefaultVariables(vars);
       
        engine = new JexlEngine();
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.jexl2.ScriptTest$Tester

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.