List of usage examples for org.apache.commons.jexl3 MapContext MapContext
public MapContext()
From source file:org.apache.nifi.processors.ccda.ExtractCCDAAttributes.java
@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();/*from w w w . ja v a 2 s .c o m*/ 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"); loadMappings(); // Load CDA mappings for parser }
From source file:org.apache.syncope.core.misc.utils.MappingUtils.java
/** * Build __NAME__ for propagation. First look if there ia a defined connObjectLink for the given resource (and in * this case evaluate as JEXL); otherwise, take given connObjectKey. * * @param any given any object// w ww . jav a2 s . c o m * @param provision external resource * @param connObjectKey connector object key * @return the value to be propagated as __NAME__ */ public static Name evaluateNAME(final Any<?> any, final Provision provision, final String connObjectKey) { if (StringUtils.isBlank(connObjectKey)) { // LOG error but avoid to throw exception: leave it to the external resource LOG.error("Missing ConnObjectKey for '{}': ", provision.getResource()); } // Evaluate connObjectKey expression String connObjectLink = provision == null || provision.getMapping() == null ? null : provision.getMapping().getConnObjectLink(); String evalConnObjectLink = null; if (StringUtils.isNotBlank(connObjectLink)) { JexlContext jexlContext = new MapContext(); JexlUtils.addFieldsToContext(any, jexlContext); JexlUtils.addPlainAttrsToContext(any.getPlainAttrs(), jexlContext); JexlUtils.addDerAttrsToContext(any, jexlContext); evalConnObjectLink = JexlUtils.evaluate(connObjectLink, jexlContext); } // If connObjectLink evaluates to an empty string, just use the provided connObjectKey as Name(), // otherwise evaluated connObjectLink expression is taken as Name(). Name name; if (StringUtils.isBlank(evalConnObjectLink)) { // add connObjectKey as __NAME__ attribute ... LOG.debug("Add connObjectKey [{}] as __NAME__", connObjectKey); name = new Name(connObjectKey); } else { LOG.debug("Add connObjectLink [{}] as __NAME__", evalConnObjectLink); name = new Name(evalConnObjectLink); // connObjectKey not propagated: it will be used to set the value for __UID__ attribute LOG.debug("connObjectKey will be used just as __UID__ attribute"); } return name; }
From source file:org.apache.syncope.core.provisioning.java.data.ConfigurationDataBinderImpl.java
private void fillAttr(final List<String> values, final PlainSchema schema, final CPlainAttr attr, final SyncopeClientException invalidValues) { // if schema is multivalue, all values are considered for addition; // otherwise only the fist one - if provided - is considered List<String> valuesProvided = schema.isMultivalue() ? values : (values.isEmpty() ? Collections.<String>emptyList() : Collections.singletonList(values.iterator().next())); if (valuesProvided.isEmpty()) { JexlContext jexlContext = new MapContext(); JexlUtils.addPlainAttrsToContext(confDAO.get().getPlainAttrs(), jexlContext); if (!schema.isReadonly() && Boolean.parseBoolean(JexlUtils.evaluate(schema.getMandatoryCondition(), jexlContext))) { LOG.error("Mandatory schema " + schema.getKey() + " not provided with values"); SyncopeClientException reqValMissing = SyncopeClientException .build(ClientExceptionType.RequiredValuesMissing); reqValMissing.getElements().add(schema.getKey()); throw reqValMissing; }//from w w w .j ava2 s .c o m } for (String value : valuesProvided) { if (value == null || value.isEmpty()) { LOG.debug("Null value for {}, ignoring", schema.getKey()); } else { try { PlainAttrValue attrValue; if (schema.isUniqueConstraint()) { attrValue = entityFactory.newEntity(CPlainAttrUniqueValue.class); ((PlainAttrUniqueValue) attrValue).setSchema(schema); } else { attrValue = entityFactory.newEntity(CPlainAttrValue.class); } attr.add(value, attrValue); } catch (InvalidPlainAttrValueException e) { LOG.warn("Invalid value for attribute " + schema.getKey() + ": " + value, e); invalidValues.getElements().add(schema.getKey() + ": " + value + " - " + e.getMessage()); } } } }
From source file:org.apache.syncope.core.provisioning.java.data.JEXLItemTransformerImpl.java
@Override public List<PlainAttrValue> beforePropagation(final Item item, final Entity entity, final List<PlainAttrValue> values) { if (StringUtils.isNotBlank(propagationJEXL) && values != null) { values.forEach(value -> {/* w ww . ja v a 2 s . c om*/ JexlContext jexlContext = new MapContext(); if (entity != null) { JexlUtils.addFieldsToContext(entity, jexlContext); if (entity instanceof Any) { JexlUtils.addPlainAttrsToContext(((Any<?>) entity).getPlainAttrs(), jexlContext); JexlUtils.addDerAttrsToContext(((Any<?>) entity), jexlContext); } } jexlContext.set("value", value.getValueAsString()); value.setStringValue(JexlUtils.evaluate(propagationJEXL, jexlContext)); }); return values; } return values; }
From source file:org.apache.syncope.core.provisioning.java.data.JEXLItemTransformerImpl.java
@Override public List<Object> beforePull(final Item item, final EntityTO entityTO, final List<Object> values) { if (StringUtils.isNotBlank(pullJEXL) && values != null) { List<Object> newValues = new ArrayList<>(values.size()); values.forEach(value -> {//from w w w . j a va 2 s . c om JexlContext jexlContext = new MapContext(); jexlContext.set("value", value); if (entityTO instanceof AnyTO) { JexlUtils.addFieldsToContext((AnyTO) entityTO, jexlContext); JexlUtils.addAttrTOsToContext(((AnyTO) entityTO).getPlainAttrs(), jexlContext); JexlUtils.addAttrTOsToContext(((AnyTO) entityTO).getDerAttrs(), jexlContext); JexlUtils.addAttrTOsToContext(((AnyTO) entityTO).getVirAttrs(), jexlContext); } else if (entityTO instanceof RealmTO) { JexlUtils.addFieldsToContext((RealmTO) entityTO, jexlContext); newValues.add(JexlUtils.evaluate(pullJEXL, jexlContext)); } newValues.add(JexlUtils.evaluate(pullJEXL, jexlContext)); }); return newValues; } return JEXLItemTransformer.super.beforePull(item, entityTO, values); }
From source file:org.apache.syncope.core.provisioning.java.data.JEXLMappingItemTransformerImpl.java
@Override public List<PlainAttrValue> beforePropagation(final MappingItem mappingItem, final Any<?> any, final List<PlainAttrValue> values) { if (StringUtils.isNotBlank(propagationJEXL) && values != null) { for (PlainAttrValue value : values) { JexlContext jexlContext = new MapContext(); if (any != null) { JexlUtils.addFieldsToContext(any, jexlContext); JexlUtils.addPlainAttrsToContext(any.getPlainAttrs(), jexlContext); JexlUtils.addDerAttrsToContext(any, jexlContext); }//from ww w .java 2 s.c om jexlContext.set("value", value.getValueAsString()); value.setStringValue(JexlUtils.evaluate(propagationJEXL, jexlContext)); } return values; } return super.beforePropagation(mappingItem, any, values); }
From source file:org.apache.syncope.core.provisioning.java.data.JEXLMappingItemTransformerImpl.java
@Override public List<Object> beforePull(final MappingItem mappingItem, final AnyTO anyTO, final List<Object> values) { if (StringUtils.isNotBlank(pullJEXL) && values != null) { List<Object> newValues = new ArrayList<>(values.size()); for (Object value : values) { JexlContext jexlContext = new MapContext(); jexlContext.set("value", value); if (anyTO == null) { newValues.add(JexlUtils.evaluate(pullJEXL, jexlContext)); } else { newValues.add(JexlUtils.evaluate(pullJEXL, anyTO, jexlContext)); }/*from ww w. ja va 2 s. com*/ } return newValues; } return super.beforePull(mappingItem, anyTO, values); }
From source file:org.apache.syncope.core.provisioning.java.DerAttrHandlerImpl.java
private Map<DerSchema, String> getValues(final Any<?> any, final Set<DerSchema> schemas) { Map<DerSchema, String> result = new HashMap<>(schemas.size()); for (DerSchema schema : schemas) { JexlContext jexlContext = new MapContext(); JexlUtils.addPlainAttrsToContext(any.getPlainAttrs(), jexlContext); JexlUtils.addFieldsToContext(any, jexlContext); result.put(schema, JexlUtils.evaluate(schema.getExpression(), jexlContext)); }//ww w. j av a2s. c o m return result; }
From source file:org.apache.syncope.core.provisioning.java.DerAttrHandlerImpl.java
private Map<DerSchema, String> getValues(final GroupableRelatable<?, ?, ?, ?, ?> any, final Membership<?> membership, final Set<DerSchema> schemas) { Map<DerSchema, String> result = new HashMap<>(schemas.size()); for (DerSchema schema : schemas) { JexlContext jexlContext = new MapContext(); JexlUtils.addPlainAttrsToContext(any.getPlainAttrs(membership), jexlContext); JexlUtils.addFieldsToContext(any, jexlContext); result.put(schema, JexlUtils.evaluate(schema.getExpression(), jexlContext)); }/*from w ww . j a v a2 s . c om*/ return result; }
From source file:org.apache.syncope.core.provisioning.java.jexl.JexlUtils.java
public static boolean evaluateMandatoryCondition(final String mandatoryCondition, final Any<?> any) { JexlContext jexlContext = new MapContext(); addPlainAttrsToContext(any.getPlainAttrs(), jexlContext); addDerAttrsToContext(any, jexlContext); return Boolean.parseBoolean(evaluate(mandatoryCondition, jexlContext)); }