use of org.apache.commons.jexl3.MapContext in project syncope by apache.
the class JEXLItemTransformerImpl method beforePull.
@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 -> {
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);
}
use of org.apache.commons.jexl3.MapContext in project syncope by apache.
the class JEXLItemTransformerImpl method beforePropagation.
@Override
public List<PlainAttrValue> beforePropagation(final Item item, final Entity entity, final List<PlainAttrValue> values) {
if (StringUtils.isNotBlank(propagationJEXL) && values != null) {
values.forEach(value -> {
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;
}
use of org.apache.commons.jexl3.MapContext in project syncope by apache.
the class TemplateUtils method apply.
@Transactional(readOnly = true)
public <T extends AnyTO> void apply(final T anyTO, final AnyTO template) {
fill(anyTO, template);
MapContext jexlContext = new MapContext();
JexlUtils.addFieldsToContext(anyTO, jexlContext);
JexlUtils.addAttrTOsToContext(anyTO.getPlainAttrs(), jexlContext);
JexlUtils.addAttrTOsToContext(anyTO.getDerAttrs(), jexlContext);
JexlUtils.addAttrTOsToContext(anyTO.getVirAttrs(), jexlContext);
if (template instanceof AnyObjectTO) {
fillRelationships((GroupableRelatableTO) anyTO, ((GroupableRelatableTO) template));
fillMemberships((GroupableRelatableTO) anyTO, ((GroupableRelatableTO) template));
} else if (template instanceof UserTO) {
if (StringUtils.isNotBlank(((UserTO) template).getUsername())) {
String evaluated = JexlUtils.evaluate(((UserTO) template).getUsername(), jexlContext);
if (StringUtils.isNotBlank(evaluated)) {
((UserTO) anyTO).setUsername(evaluated);
}
}
if (StringUtils.isNotBlank(((UserTO) template).getPassword())) {
String evaluated = JexlUtils.evaluate(((UserTO) template).getPassword(), jexlContext);
if (StringUtils.isNotBlank(evaluated)) {
((UserTO) anyTO).setPassword(evaluated);
}
}
fillRelationships((GroupableRelatableTO) anyTO, ((GroupableRelatableTO) template));
fillMemberships((GroupableRelatableTO) anyTO, ((GroupableRelatableTO) template));
} else if (template instanceof GroupTO) {
if (StringUtils.isNotBlank(((GroupTO) template).getName())) {
String evaluated = JexlUtils.evaluate(((GroupTO) template).getName(), jexlContext);
if (StringUtils.isNotBlank(evaluated)) {
((GroupTO) anyTO).setName(evaluated);
}
}
if (((GroupTO) template).getUserOwner() != null) {
final User userOwner = userDAO.find(((GroupTO) template).getUserOwner());
if (userOwner != null) {
((GroupTO) anyTO).setUserOwner(userOwner.getKey());
}
}
if (((GroupTO) template).getGroupOwner() != null) {
final Group groupOwner = groupDAO.find(((GroupTO) template).getGroupOwner());
if (groupOwner != null) {
((GroupTO) anyTO).setGroupOwner(groupOwner.getKey());
}
}
}
}
use of org.apache.commons.jexl3.MapContext in project syncope by apache.
the class TemplateUtils method fill.
private void fill(final AnyTO anyTO, final AnyTO template) {
MapContext jexlContext = new MapContext();
JexlUtils.addFieldsToContext(anyTO, jexlContext);
JexlUtils.addAttrTOsToContext(anyTO.getPlainAttrs(), jexlContext);
JexlUtils.addAttrTOsToContext(anyTO.getDerAttrs(), jexlContext);
JexlUtils.addAttrTOsToContext(anyTO.getVirAttrs(), jexlContext);
if (template.getRealm() != null) {
String evaluated = JexlUtils.evaluate(template.getRealm(), jexlContext);
if (StringUtils.isNotBlank(evaluated)) {
anyTO.setRealm(evaluated);
}
}
Map<String, AttrTO> currentAttrMap = EntityTOUtils.buildAttrMap(anyTO.getPlainAttrs());
for (AttrTO templatePlainAttr : template.getPlainAttrs()) {
if (!templatePlainAttr.getValues().isEmpty() && (!currentAttrMap.containsKey(templatePlainAttr.getSchema()) || currentAttrMap.get(templatePlainAttr.getSchema()).getValues().isEmpty())) {
AttrTO evaluated = evaluateAttr(templatePlainAttr, jexlContext);
if (!evaluated.getValues().isEmpty()) {
anyTO.getPlainAttrs().add(evaluated);
jexlContext.set(evaluated.getSchema(), evaluated.getValues().get(0));
}
}
}
currentAttrMap = EntityTOUtils.buildAttrMap(anyTO.getDerAttrs());
for (AttrTO templateDerAttr : template.getDerAttrs()) {
if (!currentAttrMap.containsKey(templateDerAttr.getSchema())) {
anyTO.getDerAttrs().add(templateDerAttr);
}
}
currentAttrMap = EntityTOUtils.buildAttrMap(anyTO.getVirAttrs());
for (AttrTO templateVirAttr : template.getVirAttrs()) {
if (!templateVirAttr.getValues().isEmpty() && (!currentAttrMap.containsKey(templateVirAttr.getSchema()) || currentAttrMap.get(templateVirAttr.getSchema()).getValues().isEmpty())) {
AttrTO evaluated = evaluateAttr(templateVirAttr, jexlContext);
if (!evaluated.getValues().isEmpty()) {
anyTO.getVirAttrs().add(evaluated);
jexlContext.set(evaluated.getSchema(), evaluated.getValues().get(0));
}
}
}
anyTO.getResources().addAll(template.getResources());
anyTO.getAuxClasses().addAll(template.getAuxClasses());
}
use of org.apache.commons.jexl3.MapContext in project syncope by apache.
the class DerAttrHandlerImpl method getValues.
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));
}
return result;
}
Aggregations