Search in sources :

Example 31 with MapContext

use of org.apache.commons.jexl3.MapContext in project opennms by OpenNMS.

the class JasperReportService method evaluateToString.

public static String evaluateToString(JasperReport report, JRExpression expression) {
    Objects.requireNonNull(report);
    Objects.requireNonNull(expression);
    SubreportExpressionVisitor visitor = new SubreportExpressionVisitor(report);
    String string = visitor.visit(expression);
    if (string != null) {
        JexlEngine engine = new JexlEngine();
        return (String) engine.createExpression(string).evaluate(new MapContext());
    }
    return null;
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) MapContext(org.apache.commons.jexl2.MapContext)

Example 32 with MapContext

use of org.apache.commons.jexl3.MapContext in project nifi by apache.

the class ExtractCCDAAttributes method onScheduled.

@OnScheduled
public void onScheduled(final ProcessContext context) throws IOException {
    getLogger().debug("Loading packages");
    final StopWatch stopWatch = new StopWatch(true);
    // Load required MDHT packages
    System.setProperty("org.eclipse.emf.ecore.EPackage.Registry.INSTANCE", "org.eclipse.emf.ecore.impl.EPackageRegistryImpl");
    CDAPackage.eINSTANCE.eClass();
    HITSPPackage.eINSTANCE.eClass();
    CCDPackage.eINSTANCE.eClass();
    ConsolPackage.eINSTANCE.eClass();
    IHEPackage.eINSTANCE.eClass();
    stopWatch.stop();
    getLogger().debug("Loaded packages in {}", new Object[] { stopWatch.getDuration(TimeUnit.MILLISECONDS) });
    // Initialize JEXL
    jexl = new JexlBuilder().cache(1024).debug(false).silent(true).strict(false).create();
    jexlCtx = new MapContext();
    getLogger().debug("Loading mappings");
    // Load CDA mappings for parser
    loadMappings();
}
Also used : JexlBuilder(org.apache.commons.jexl3.JexlBuilder) MapContext(org.apache.commons.jexl3.MapContext) StopWatch(org.apache.nifi.util.StopWatch) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Example 33 with MapContext

use of org.apache.commons.jexl3.MapContext 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 34 with MapContext

use of org.apache.commons.jexl3.MapContext in project syncope by apache.

the class LDAPMembershipPropagationActions method before.

@Transactional(readOnly = true)
@Override
public void before(final PropagationTask task, final ConnectorObject beforeObj) {
    Optional<? extends Provision> provision = task.getResource().getProvision(anyTypeDAO.findGroup());
    if (AnyTypeKind.USER == task.getAnyTypeKind() && provision.isPresent() && provision.get().getMapping() != null && StringUtils.isNotBlank(provision.get().getMapping().getConnObjectLink())) {
        User user = userDAO.find(task.getEntityKey());
        if (user != null) {
            List<String> groupConnObjectLinks = new ArrayList<>();
            userDAO.findAllGroupKeys(user).forEach(groupKey -> {
                Group group = groupDAO.find(groupKey);
                if (group != null && groupDAO.findAllResourceKeys(groupKey).contains(task.getResource().getKey())) {
                    LOG.debug("Evaluating connObjectLink for {}", group);
                    JexlContext jexlContext = new MapContext();
                    JexlUtils.addFieldsToContext(group, jexlContext);
                    JexlUtils.addPlainAttrsToContext(group.getPlainAttrs(), jexlContext);
                    JexlUtils.addDerAttrsToContext(group, jexlContext);
                    String groupConnObjectLinkLink = JexlUtils.evaluate(provision.get().getMapping().getConnObjectLink(), jexlContext);
                    LOG.debug("ConnObjectLink for {} is '{}'", group, groupConnObjectLinkLink);
                    if (StringUtils.isNotBlank(groupConnObjectLinkLink)) {
                        groupConnObjectLinks.add(groupConnObjectLinkLink);
                    }
                }
            });
            LOG.debug("Group connObjectLinks to propagate for membership: {}", groupConnObjectLinks);
            Set<Attribute> attributes = new HashSet<>(task.getAttributes());
            Set<String> groups = new HashSet<>(groupConnObjectLinks);
            Attribute ldapGroups = AttributeUtil.find(getGroupMembershipAttrName(), attributes);
            if (ldapGroups != null) {
                ldapGroups.getValue().forEach(obj -> {
                    groups.add(obj.toString());
                });
                attributes.remove(ldapGroups);
            }
            attributes.add(AttributeBuilder.build(getGroupMembershipAttrName(), groups));
            task.setAttributes(attributes);
        }
    } else {
        LOG.debug("Not about user, or group mapping missing for resource: not doing anything");
    }
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) User(org.apache.syncope.core.persistence.api.entity.user.User) Attribute(org.identityconnectors.framework.common.objects.Attribute) ArrayList(java.util.ArrayList) JexlContext(org.apache.commons.jexl3.JexlContext) MapContext(org.apache.commons.jexl3.MapContext) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 35 with MapContext

use of org.apache.commons.jexl3.MapContext in project syncope by apache.

the class NotificationManagerImpl method evaluate.

private String evaluate(final String template, final Map<String, Object> jexlVars) {
    StringWriter writer = new StringWriter();
    JexlUtils.newJxltEngine().createTemplate(template).evaluate(new MapContext(jexlVars), writer);
    return writer.toString();
}
Also used : StringWriter(java.io.StringWriter) MapContext(org.apache.commons.jexl3.MapContext)

Aggregations

MapContext (org.apache.commons.jexl2.MapContext)32 MapContext (org.apache.commons.jexl3.MapContext)26 JexlContext (org.apache.commons.jexl2.JexlContext)23 Expression (org.apache.commons.jexl2.Expression)20 JexlEngine (org.apache.commons.jexl2.JexlEngine)20 JexlContext (org.apache.commons.jexl3.JexlContext)17 Test (org.testng.annotations.Test)13 HashMap (java.util.HashMap)7 Map (java.util.Map)7 HashSet (java.util.HashSet)4 JexlException (org.apache.commons.jexl2.JexlException)4 JexlBuilder (org.apache.commons.jexl3.JexlBuilder)4 JexlExpression (org.apache.commons.jexl3.JexlExpression)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)3 JexlEngine (org.apache.commons.jexl3.JexlEngine)3 Test (org.junit.jupiter.api.Test)3 Device (org.traccar.model.Device)3 IOException (java.io.IOException)2