use of org.apache.commons.jexl2.JexlContext in project syncope by apache.
the class MappingUtils method evaluateNAME.
/**
* Build __NAME__ for propagation.
* First look if there is a defined connObjectLink for the given resource (and in
* this case evaluate as JEXL); otherwise, take given connObjectKey.
*
* @param any given any object
* @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.warn("Missing ConnObjectKey value 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);
}
return getName(evalConnObjectLink, connObjectKey);
}
use of org.apache.commons.jexl2.JexlContext in project syncope by apache.
the class MappingUtils method evaluateNAME.
/**
* Build __NAME__ for propagation.
* First look if there is a defined connObjectLink for the given resource (and in
* this case evaluate as JEXL); otherwise, take given connObjectKey.
*
* @param realm given any object
* @param orgUnit external resource
* @param connObjectKey connector object key
* @return the value to be propagated as __NAME__
*/
public static Name evaluateNAME(final Realm realm, final OrgUnit orgUnit, final String connObjectKey) {
if (StringUtils.isBlank(connObjectKey)) {
// LOG error but avoid to throw exception: leave it to the external resource
LOG.warn("Missing ConnObjectKey value for {}: ", orgUnit.getResource());
}
// Evaluate connObjectKey expression
String connObjectLink = orgUnit == null ? null : orgUnit.getConnObjectLink();
String evalConnObjectLink = null;
if (StringUtils.isNotBlank(connObjectLink)) {
JexlContext jexlContext = new MapContext();
JexlUtils.addFieldsToContext(realm, jexlContext);
evalConnObjectLink = JexlUtils.evaluate(connObjectLink, jexlContext);
}
return getName(evalConnObjectLink, connObjectKey);
}
use of org.apache.commons.jexl2.JexlContext in project syncope by apache.
the class DerAttrHandlerImpl method getValues.
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));
}
return result;
}
use of org.apache.commons.jexl2.JexlContext in project syncope by apache.
the class JexlUtils method evaluateMandatoryCondition.
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));
}
use of org.apache.commons.jexl2.JexlContext in project syncope by apache.
the class ConfigurationDataBinderImpl method fillAttr.
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;
}
}
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());
}
}
}
}
Aggregations