use of com.evolveum.midpoint.repo.common.expression.ExpressionVariables in project midpoint by Evolveum.
the class ChangeExecutor method executeReconciliationScript.
private <T extends ObjectType, F extends ObjectType> void executeReconciliationScript(LensProjectionContext projContext, LensContext<F> context, BeforeAfterType order, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException, ObjectAlreadyExistsException {
if (!projContext.isDoReconciliation()) {
return;
}
ResourceType resource = projContext.getResource();
if (resource == null) {
LOGGER.warn("Resource does not exist. Skipping processing reconciliation scripts.");
return;
}
OperationProvisioningScriptsType resourceScripts = resource.getScripts();
if (resourceScripts == null) {
return;
}
PrismObject<F> user = null;
PrismObject<ShadowType> shadow = null;
if (context.getFocusContext() != null) {
if (context.getFocusContext().getObjectNew() != null) {
user = context.getFocusContext().getObjectNew();
} else if (context.getFocusContext().getObjectOld() != null) {
user = context.getFocusContext().getObjectOld();
}
// if (order == ProvisioningScriptOrderType.BEFORE) {
// user = context.getFocusContext().getObjectOld();
// } else if (order == ProvisioningScriptOrderType.AFTER) {
// user = context.getFocusContext().getObjectNew();
// } else {
// throw new IllegalArgumentException("Unknown order "+order);
// }
}
if (order == BeforeAfterType.BEFORE) {
shadow = (PrismObject<ShadowType>) projContext.getObjectOld();
} else if (order == BeforeAfterType.AFTER) {
shadow = (PrismObject<ShadowType>) projContext.getObjectNew();
} else {
throw new IllegalArgumentException("Unknown order " + order);
}
ExpressionVariables variables = Utils.getDefaultExpressionVariables(user, shadow, projContext.getResourceShadowDiscriminator(), resource.asPrismObject(), context.getSystemConfiguration(), projContext);
OperationProvisioningScriptsType evaluatedScript = evaluateScript(resourceScripts, projContext.getResourceShadowDiscriminator(), ProvisioningOperationTypeType.RECONCILE, order, variables, context, projContext, task, parentResult);
for (OperationProvisioningScriptType script : evaluatedScript.getScript()) {
Utils.setRequestee(task, context);
provisioning.executeScript(resource.getOid(), script, task, parentResult);
Utils.clearRequestee(task);
}
}
use of com.evolveum.midpoint.repo.common.expression.ExpressionVariables in project midpoint by Evolveum.
the class ObjectMerger method evaluateValueExpression.
private <O extends ObjectType> Collection<PrismValue> evaluateValueExpression(PrismObject<O> objectLeft, PrismObject<O> objectRight, String side, PrismValue origValue, Expression<PrismValue, ItemDefinition> valueExpression, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
ExpressionVariables variables = new ExpressionVariables();
variables.addVariableDefinition(ExpressionConstants.VAR_SIDE, side);
variables.addVariableDefinition(ExpressionConstants.VAR_OBJECT_LEFT, side);
variables.addVariableDefinition(ExpressionConstants.VAR_OBJECT_RIGHT, side);
variables.addVariableDefinition(ExpressionConstants.VAR_INPUT, origValue);
variables.addVariableDefinition(ExpressionConstants.VAR_VALUE, origValue);
ExpressionEvaluationContext exprContext = new ExpressionEvaluationContext(null, variables, "for value " + origValue, task, result);
PrismValueDeltaSetTriple<PrismValue> triple = valueExpression.evaluate(exprContext);
if (triple == null) {
return null;
}
return triple.getNonNegativeValues();
}
use of com.evolveum.midpoint.repo.common.expression.ExpressionVariables in project midpoint by Evolveum.
the class PageRepositoryQuery method updateRequestWithMidpointQuery.
private void updateRequestWithMidpointQuery(RepositoryQueryDiagRequest request, QName objectType, String queryText, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
PrismContext prismContext = getPrismContext();
if (objectType == null) {
objectType = ObjectType.COMPLEX_TYPE;
}
@SuppressWarnings("unchecked") Class<? extends ObjectType> clazz = (Class<? extends ObjectType>) prismContext.getSchemaRegistry().getCompileTimeClassForObjectType(objectType);
if (clazz == null) {
throw new SchemaException("Couldn't find compile-time class for object type of " + objectType);
}
QueryType queryType = prismContext.parserFor(queryText).xml().parseRealValue(QueryType.class);
request.setType(clazz);
ObjectQuery objectQuery = QueryJaxbConvertor.createObjectQuery(clazz, queryType, prismContext);
ObjectQuery queryWithExprEvaluated = ExpressionUtil.evaluateQueryExpressions(objectQuery, new ExpressionVariables(), getExpressionFactory(), getPrismContext(), "evaluate query expressions", task, result);
request.setQuery(queryWithExprEvaluated);
}
use of com.evolveum.midpoint.repo.common.expression.ExpressionVariables in project midpoint by Evolveum.
the class GenerateExpressionEvaluator method getObject.
// determine object from the variables
@SuppressWarnings("unchecked")
private <O extends ObjectType> PrismObject<O> getObject(ExpressionEvaluationContext params) throws SchemaException {
ExpressionVariables variables = params.getVariables();
if (variables == null) {
return null;
}
PrismObject<O> object = variables.getObjectNew(ExpressionConstants.VAR_PROJECTION);
if (object != null) {
return object;
}
object = variables.getObjectNew(ExpressionConstants.VAR_FOCUS);
return object;
}
use of com.evolveum.midpoint.repo.common.expression.ExpressionVariables in project midpoint by Evolveum.
the class AbstractValueTransformationExpressionEvaluator method evaluateScriptExpression.
private Collection<V> evaluateScriptExpression(Collection<Source<?, ?>> sources, ExpressionVariables variables, String contextDescription, boolean useNew, ExpressionEvaluationContext params, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
ExpressionVariables scriptVariables = new ExpressionVariables();
if (useNew) {
scriptVariables.addVariableDefinitionsNew(variables);
} else {
scriptVariables.addVariableDefinitionsOld(variables);
}
if (sources != null) {
// Add sources to variables
for (Source<?, ?> source : sources) {
LOGGER.trace("source: {}", source);
QName name = source.getName();
if (name == null) {
if (sources.size() == 1) {
name = ExpressionConstants.VAR_INPUT;
} else {
throw new ExpressionSyntaxException("No name definition for source in " + contextDescription);
}
}
Object value = null;
if (useNew) {
value = getRealContent(source.getItemNew(), source.getResidualPath());
} else {
value = getRealContent(source.getItemOld(), source.getResidualPath());
}
scriptVariables.addVariableDefinition(name, value);
}
}
List<V> scriptResults = transformSingleValue(scriptVariables, null, useNew, params, (useNew ? "(new) " : "(old) ") + contextDescription, task, result);
if (scriptResults == null || scriptResults.isEmpty()) {
return null;
}
Collection<V> outputSet = new ArrayList<V>(scriptResults.size());
for (V pval : scriptResults) {
if (pval instanceof PrismPropertyValue<?>) {
if (((PrismPropertyValue<?>) pval).getValue() == null) {
continue;
}
Object realValue = ((PrismPropertyValue<?>) pval).getValue();
if (realValue instanceof String) {
if (((String) realValue).isEmpty()) {
continue;
}
}
if (realValue instanceof PolyString) {
if (((PolyString) realValue).isEmpty()) {
continue;
}
}
}
outputSet.add(pval);
}
return outputSet;
}
Aggregations