use of com.evolveum.midpoint.xml.ns._public.common.common_3.PopulateItemType in project midpoint by Evolveum.
the class AbstractSearchExpressionEvaluator method evaluatePopulateExpression.
private <IV extends PrismValue, ID extends ItemDefinition, C extends Containerable> ItemDelta<IV, ID> evaluatePopulateExpression(PopulateItemType populateItem, ExpressionVariables variables, ExpressionEvaluationContext params, PrismContainerDefinition<C> objectDefinition, String contextDescription, boolean evaluateMinus, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
ExpressionType expressionType = populateItem.getExpression();
if (expressionType == null) {
LOGGER.warn("No expression in populateObject in assignment expression in {}, " + "skipping. Subsequent operations will most likely fail", contextDescription);
return null;
}
VariableBindingDefinitionType targetType = populateItem.getTarget();
if (targetType == null) {
LOGGER.warn("No target in populateObject in assignment expression in {}, " + "skipping. Subsequent operations will most likely fail", contextDescription);
return null;
}
ItemPathType itemPathType = targetType.getPath();
if (itemPathType == null) {
throw new SchemaException("No path in target definition in " + contextDescription);
}
ItemPath targetPath = itemPathType.getItemPath();
ID propOutputDefinition = ExpressionUtil.resolveDefinitionPath(targetPath, variables, objectDefinition, "target definition in " + contextDescription);
if (propOutputDefinition == null) {
throw new SchemaException("No target item that would conform to the path " + targetPath + " in " + contextDescription);
}
String expressionDesc = "expression in assignment expression in " + contextDescription;
ExpressionFactory expressionFactory = params.getExpressionFactory();
Expression<IV, ID> expression = expressionFactory.makeExpression(expressionType, propOutputDefinition, expressionDesc, task, result);
ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, expressionDesc, task, result);
context.setExpressionFactory(expressionFactory);
context.setStringPolicyResolver(params.getStringPolicyResolver());
context.setDefaultTargetContext(params.getDefaultTargetContext());
context.setSkipEvaluationMinus(true);
context.setSkipEvaluationPlus(false);
PrismValueDeltaSetTriple<IV> outputTriple = expression.evaluate(context);
LOGGER.trace("output triple: {}", outputTriple.debugDump());
Collection<IV> pvalues = outputTriple.getNonNegativeValues();
// Maybe not really clean but it works. TODO: refactor later
NameItemPathSegment first = (NameItemPathSegment) targetPath.first();
if (first.isVariable()) {
targetPath = targetPath.rest();
}
ItemDelta<IV, ID> itemDelta = propOutputDefinition.createEmptyDelta(targetPath);
itemDelta.addValuesToAdd(PrismValue.cloneCollection(pvalues));
LOGGER.trace("Item delta:\n{}", itemDelta.debugDump());
return itemDelta;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.PopulateItemType in project midpoint by Evolveum.
the class AbstractSearchExpressionEvaluator method createOnDemand.
private <O extends ObjectType> String createOnDemand(Class<O> targetTypeClass, ExpressionVariables variables, ExpressionEvaluationContext params, String contextDescription, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Going to create assignment targets on demand, variables:\n{}", variables.formatVariables());
}
PrismObjectDefinition<O> objectDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(targetTypeClass);
PrismObject<O> newObject = objectDefinition.instantiate();
PopulateType populateObject = getExpressionEvaluatorType().getPopulateObject();
if (populateObject == null) {
LOGGER.warn("No populateObject in assignment expression in {}, " + "object created on demand will be empty. Subsequent operations will most likely fail", contextDescription);
} else {
for (PopulateItemType populateItem : populateObject.getPopulateItem()) {
ItemDelta<?, ?> itemDelta = evaluatePopulateExpression(populateItem, variables, params, objectDefinition, contextDescription, true, task, result);
if (itemDelta != null) {
itemDelta.applyTo(newObject);
}
}
}
LOGGER.debug("Creating object on demand from {}: {}", contextDescription, newObject);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Creating object on demand:\n{}", newObject.debugDump());
}
ObjectDelta<O> addDelta = newObject.createAddDelta();
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(addDelta);
try {
modelService.executeChanges(deltas, null, task, result);
} catch (ObjectAlreadyExistsException | CommunicationException | ConfigurationException | PolicyViolationException | SecurityViolationException e) {
throw new ExpressionEvaluationException(e.getMessage(), e);
}
return addDelta.getOid();
}
Aggregations