use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class DashboardServiceImpl method createVariables.
private static VariablesMap createVariables(PrismObject<? extends ObjectType> object, IntegerStatType statType, Collection<String> policySituations, String storedData) {
VariablesMap variables = new VariablesMap();
if (statType != null || policySituations != null) {
VariablesMap variablesMap = new VariablesMap();
if (statType != null) {
variablesMap.put(ExpressionConstants.VAR_INPUT, statType, statType.getClass());
variablesMap.put(VAR_PROPORTIONAL, statType, statType.getClass());
variablesMap.registerAlias(VAR_PROPORTIONAL, ExpressionConstants.VAR_INPUT);
}
if (policySituations != null) {
variablesMap.put(VAR_POLICY_SITUATIONS, policySituations, EvaluatedPolicyRule.class);
}
variables.addVariableDefinitions(variablesMap);
}
if (object != null) {
variables.addVariableDefinition(ExpressionConstants.VAR_OBJECT, object, object.getDefinition());
}
if (storedData != null) {
variables.put(VAR_STORED_DATA, storedData, String.class);
}
return variables;
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class SynchronizationContext method conditionMatches.
private boolean conditionMatches(SynchronizationReactionType reaction, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
if (reaction.getCondition() != null) {
ExpressionType expression = reaction.getCondition();
String desc = "condition in synchronization reaction on " + reaction.getSituation() + (reaction.getName() != null ? " (" + reaction.getName() + ")" : "");
VariablesMap variables = ModelImplUtils.getDefaultVariablesMap(getFocus(), shadowedResourceObject, null, resource, systemConfiguration, null, prismContext);
variables.put(ExpressionConstants.VAR_RESOURCE_OBJECT_DELTA, resourceObjectDelta, ObjectDelta.class);
try {
ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment<>(task, result));
boolean value = ExpressionUtil.evaluateConditionDefaultFalse(variables, expression, expressionProfile, beans.expressionFactory, desc, task, result);
if (!value) {
LOGGER.trace("Skipping reaction {} because the condition was evaluated to false", reaction);
}
return value;
} finally {
ModelExpressionThreadLocalHolder.popExpressionEnvironment();
}
} else {
return true;
}
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class SynchronizationExpressionsEvaluator method generateTag.
// For now only used in sync service. but later can be used in outbound/assignments
@SuppressWarnings("WeakerAccess")
public String generateTag(ResourceObjectMultiplicityType multiplicity, PrismObject<ShadowType> shadow, PrismObject<ResourceType> resource, PrismObject<SystemConfigurationType> configuration, String shortDesc, Task task, OperationResult parentResult) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
if (multiplicity == null) {
return null;
}
ShadowTagSpecificationType tagSpec = multiplicity.getTag();
if (tagSpec == null) {
return shadow.getOid();
}
ExpressionType expressionType = tagSpec.getExpression();
if (expressionType == null) {
return shadow.getOid();
}
VariablesMap variables = ModelImplUtils.getDefaultVariablesMap(null, shadow, null, resource, configuration, null, prismContext);
ItemDefinition outputDefinition = prismContext.definitionFactory().createPropertyDefinition(ExpressionConstants.OUTPUT_ELEMENT_NAME, PrimitiveType.STRING.getQname());
PrismPropertyValue<String> tagProp = ExpressionUtil.evaluateExpression(variables, outputDefinition, expressionType, MiscSchemaUtil.getExpressionProfile(), expressionFactory, shortDesc, task, parentResult);
return getRealValue(tagProp);
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class SynchronizationServiceImpl method evaluateSynchronizationSorter.
private <F extends FocusType> ObjectSynchronizationDiscriminatorType evaluateSynchronizationSorter(@NotNull SynchronizationType synchronization, @NotNull SynchronizationContext<F> syncCtx, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
ObjectSynchronizationSorterType synchronizationSorter = synchronization.getObjectSynchronizationSorter();
if (synchronizationSorter == null || synchronizationSorter.getExpression() == null) {
return null;
}
ExpressionType classificationExpression = synchronizationSorter.getExpression();
String desc = "synchronization divider type ";
VariablesMap variables = ModelImplUtils.getDefaultVariablesMap(null, syncCtx.getShadowedResourceObject(), null, syncCtx.getResource(), syncCtx.getSystemConfiguration(), null, syncCtx.getPrismContext());
variables.put(ExpressionConstants.VAR_CHANNEL, syncCtx.getChannel(), String.class);
try {
ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment<>(task, result));
// noinspection unchecked
PrismPropertyDefinition<ObjectSynchronizationDiscriminatorType> discriminatorDef = prismContext.getSchemaRegistry().findPropertyDefinitionByElementName(SchemaConstantsGenerated.C_OBJECT_SYNCHRONIZATION_DISCRIMINATOR);
PrismPropertyValue<ObjectSynchronizationDiscriminatorType> discriminator = ExpressionUtil.evaluateExpression(variables, discriminatorDef, classificationExpression, syncCtx.getExpressionProfile(), expressionFactory, desc, task, result);
return getRealValue(discriminator);
} finally {
ModelExpressionThreadLocalHolder.popExpressionEnvironment();
}
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class BaseActionExecutor method createVariables.
/**
* Creates variables for script evaluation based on some externally-supplied variables,
* plus some generic ones (prism context, actor).
*/
@NotNull
protected VariablesMap createVariables(VariablesMap externalVariables) {
VariablesMap variables = new VariablesMap();
variables.put(ExpressionConstants.VAR_PRISM_CONTEXT, prismContext, PrismContext.class);
ExpressionUtil.addActorVariable(variables, securityContextManager, prismContext);
// noinspection unchecked
externalVariables.forEach((k, v) -> variables.put(k, cloneIfNecessary(k, v)));
variables.registerAliasesFrom(externalVariables);
return variables;
}
Aggregations