use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class TestExpressionProfileSafe method test130Const.
@Test
@Override
public void test130Const() throws Exception {
given();
OperationResult result = createOperationResult();
rememberScriptExecutionCount();
ExpressionType expressionType = parseExpression(EXPRESSION_CONST_FILE);
Collection<Source<?, ?>> sources = prepareStringSources();
VariablesMap variables = prepareBasicVariables();
ExpressionEvaluationContext expressionContext = new ExpressionEvaluationContext(sources, variables, getTestNameShort(), null);
when();
evaluatePropertyExpressionRestricted(expressionType, PrimitiveType.STRING, expressionContext, result);
then();
assertScriptExecutionIncrement(0);
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class ModelInteractionServiceImpl method createLocalizableMessageType.
@Override
@NotNull
public LocalizableMessageType createLocalizableMessageType(LocalizableMessageTemplateType template, VariablesMap variables, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
VariablesMap vars = new VariablesMap();
vars.putAll(variables);
return LensUtil.interpretLocalizableMessageTemplate(template, vars, expressionFactory, prismContext, task, result);
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class DeltaExecution method prepareScripts.
// endregion
// region Provisioning scripts
/**
* TODO clarify the role of `object` parameter and why it is used only as a second choice (after ctx.objectAny).
*/
private OperationProvisioningScriptsType prepareScripts(PrismObject<E> object, ProvisioningOperationTypeType operation, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
if (resource == null) {
LOGGER.warn("Resource does not exist. Skipping processing scripts.");
return null;
}
OperationProvisioningScriptsType resourceScripts = resource.getScripts();
LensProjectionContext projCtx = (LensProjectionContext) elementContext;
PrismObject<ShadowType> shadow = getShadow(projCtx, object);
PrismObject<O> focus = getFocus();
ResourceShadowDiscriminator rsd = projCtx.getResourceShadowDiscriminator();
VariablesMap variables = ModelImplUtils.getDefaultVariablesMap(focus, shadow, rsd, resource.asPrismObject(), context.getSystemConfiguration(), elementContext, b.prismContext);
// Having delta in provisioning scripts may be very useful. E.g. the script can optimize execution of expensive operations.
variables.put(ExpressionConstants.VAR_DELTA, projCtx.getCurrentDelta(), ObjectDelta.class);
ExpressionProfile expressionProfile = MiscSchemaUtil.getExpressionProfile();
ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment<>(context, projCtx, task, result));
try {
ScriptExecutor<O> scriptExecutor = new ScriptExecutor<>(context, projCtx, task, b);
return scriptExecutor.prepareScripts(resourceScripts, rsd, operation, null, variables, expressionProfile, result);
} finally {
ModelExpressionThreadLocalHolder.popExpressionEnvironment();
}
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class ProjectionValuesProcessor method formatIterationToken.
private <F extends ObjectType> String formatIterationToken(LensContext<F> context, LensProjectionContext accountContext, int iteration, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
ResourceObjectTypeDefinitionType accDef = accountContext.getResourceObjectTypeDefinitionType();
if (accDef == null) {
return LensUtil.formatIterationTokenDefault(iteration);
}
IterationSpecificationType iterationType = accDef.getIteration();
VariablesMap variables = createVariablesMap(context, accountContext);
return LensUtil.formatIterationToken(context, accountContext, iterationType, iteration, expressionFactory, variables, task, result);
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class ConstructionResourceResolver method resolveResourceRefFilter.
@SuppressWarnings("SameParameterValue")
@NotNull
private ResourceType resolveResourceRefFilter(String sourceDescription, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
VariablesMap variables = ModelImplUtils.getDefaultVariablesMap(construction.getFocusOdoAbsolute().getNewObject().asObjectable(), null, null, null, PrismContext.get());
ModelImplUtils.addAssignmentPathVariables(construction.getAssignmentPathVariables(), variables, PrismContext.get());
LOGGER.debug("Expression variables for filter evaluation: {}", variables);
assert construction.constructionBean != null;
ObjectFilter origFilter = PrismContext.get().getQueryConverter().parseFilter(construction.constructionBean.getResourceRef().getFilter(), ResourceType.class);
LOGGER.debug("Orig filter {}", origFilter);
ObjectFilter evaluatedFilter = ExpressionUtil.evaluateFilterExpressions(origFilter, variables, construction.expressionProfile, ModelBeans.get().commonBeans.expressionFactory, PrismContext.get(), " evaluating resource filter expression ", task, result);
LOGGER.debug("evaluatedFilter filter {}", evaluatedFilter);
if (evaluatedFilter == null) {
throw new SchemaException("The OID is null and filter could not be evaluated in assignment targetRef in " + construction.source);
}
ObjectQuery query = PrismContext.get().queryFactory().createQuery(evaluatedFilter);
Collection<PrismObject<ResourceType>> matchingResources = ModelBeans.get().modelObjectResolver.searchObjects(ResourceType.class, query, createReadOnlyCollection(), task, result);
// TODO consider referential integrity settings
if (CollectionUtils.isEmpty(matchingResources)) {
throw new ObjectNotFoundException("Got no target from repository, filter:" + evaluatedFilter + ", class:" + ResourceType.class + " in " + sourceDescription);
}
if (matchingResources.size() > 1) {
throw new IllegalArgumentException("Got more than one target from repository, filter:" + evaluatedFilter + ", class:" + ResourceType.class + " in " + sourceDescription);
}
return matchingResources.iterator().next().asObjectable();
}
Aggregations