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;
}
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();
}
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;
}
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");
}
}
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();
}
Aggregations