use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class ClockworkAuditHelper method evaluateAuditRecordProperty.
private <F extends ObjectType> void evaluateAuditRecordProperty(SystemConfigurationAuditEventRecordingPropertyType propertyDef, AuditEventRecord auditRecord, PrismObject<? extends ObjectType> primaryObject, LensContext<F> context, Task task, OperationResult parentResult) {
String name = propertyDef.getName();
OperationResult result = parentResult.subresult(OP_EVALUATE_AUDIT_RECORD_PROPERTY).addParam("name", name).setMinor().build();
try {
if (StringUtils.isBlank(name)) {
throw new IllegalArgumentException("Name of SystemConfigurationAuditEventRecordingPropertyType is empty or null in " + propertyDef);
}
if (!targetSelectorMatches(propertyDef.getTargetSelector(), primaryObject)) {
result.recordNotApplicable();
return;
}
ExpressionType expression = propertyDef.getExpression();
if (expression != null) {
VariablesMap variables = new VariablesMap();
variables.put(ExpressionConstants.VAR_TARGET, primaryObject, PrismObject.class);
variables.put(ExpressionConstants.VAR_AUDIT_RECORD, auditRecord, AuditEventRecord.class);
String shortDesc = "value for custom column of audit table";
Collection<String> values = ExpressionUtil.evaluateStringExpression(variables, prismContext, expression, context.getPrivilegedExpressionProfile(), expressionFactory, shortDesc, task, result);
if (values == null || values.isEmpty()) {
// nothing to do
} else if (values.size() == 1) {
auditRecord.getCustomColumnProperty().put(name, values.iterator().next());
} else {
throw new IllegalArgumentException("Collection of expression result contains more than one value");
}
}
} catch (Throwable t) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't evaluate audit record property expression {}", t, name);
// Intentionally not throwing the exception. The error is marked as partial.
// (It would be better to mark it as fatal and to derive overall result as partial, but we aren't that far yet.)
result.recordPartialError(t);
} finally {
result.recordSuccessIfUnknown();
}
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class AssignmentEvaluator method getAssignmentEvaluationVariables.
VariablesMap getAssignmentEvaluationVariables() {
VariablesMap variables = new VariablesMap();
variables.put(ExpressionConstants.VAR_LOGIN_MODE, loginMode, Boolean.class);
// e.g. AssignmentEvaluator itself, model context, etc (when needed)
return variables;
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class ClockworkHookHelper method evaluateScriptingHook.
private void evaluateScriptingHook(LensContext<?> context, ScriptExpressionEvaluatorType scriptExpressionEvaluatorType, String shortDesc, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
LOGGER.trace("Evaluating {}", shortDesc);
// TODO: it would be nice to cache this
// null output definition: this script has no output
ScriptExpression scriptExpression = scriptExpressionFactory.createScriptExpression(scriptExpressionEvaluatorType, null, context.getPrivilegedExpressionProfile(), expressionFactory, shortDesc, result);
VariablesMap variables = new VariablesMap();
variables.put(ExpressionConstants.VAR_PRISM_CONTEXT, prismContext, PrismContext.class);
variables.put(ExpressionConstants.VAR_MODEL_CONTEXT, context, ModelContext.class);
LensFocusContext<?> focusContext = context.getFocusContext();
if (focusContext != null) {
variables.put(ExpressionConstants.VAR_FOCUS, focusContext.getObjectAny(), focusContext.getObjectDefinition());
} else {
variables.put(ExpressionConstants.VAR_FOCUS, null, FocusType.class);
}
ModelImplUtils.evaluateScript(scriptExpression, context, variables, false, shortDesc, task, result);
LOGGER.trace("Finished evaluation of {}", shortDesc);
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class LensUtil method getAssignmentPathVariablesMap.
public static VariablesMap getAssignmentPathVariablesMap(AssignmentPathVariables assignmentPathVariables, PrismContext prismContext) {
VariablesMap variablesMap = new VariablesMap();
ModelImplUtils.addAssignmentPathVariables(assignmentPathVariables, variablesMap, prismContext);
return variablesMap;
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class FocalMappingSetEvaluation method createFocusMapping.
private <V extends PrismValue, D extends ItemDefinition<?>, AH extends AssignmentHolderType, T extends AssignmentHolderType> MappingImpl<V, D> createFocusMapping(LensContext<AH> context, FocalMappingEvaluationRequest<?, ?> request, ObjectDeltaObject<AH> focusOdo, @NotNull PrismObject<T> targetContext, Integer iteration, String iterationToken, PrismObject<SystemConfigurationType> configuration, XMLGregorianCalendar now, String contextDesc, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
MappingType mappingBean = request.getMapping();
MappingKindType mappingKind = request.getMappingKind();
ObjectType originObject = request.getOriginObject();
Source<V, D> defaultSource = request.constructDefaultSource(focusOdo);
AssignmentPathVariables assignmentPathVariables = request.getAssignmentPathVariables();
if (!MappingImpl.isApplicableToChannel(mappingBean, context.getChannel())) {
LOGGER.trace("Mapping {} not applicable to channel {}, skipping.", mappingBean, context.getChannel());
return null;
}
ConfigurableValuePolicySupplier valuePolicySupplier = new ConfigurableValuePolicySupplier() {
private ItemDefinition<?> outputDefinition;
@Override
public void setOutputDefinition(ItemDefinition<?> outputDefinition) {
this.outputDefinition = outputDefinition;
}
@Override
public ValuePolicyType get(OperationResult result) {
// TODO need to switch to ObjectValuePolicyEvaluator
if (outputDefinition.getItemName().equals(PasswordType.F_VALUE)) {
return beans.credentialsProcessor.determinePasswordPolicy(context.getFocusContext());
}
if (mappingBean.getExpression() != null) {
List<JAXBElement<?>> evaluators = mappingBean.getExpression().getExpressionEvaluator();
if (evaluators != null) {
for (JAXBElement jaxbEvaluator : evaluators) {
Object object = jaxbEvaluator.getValue();
if (object instanceof GenerateExpressionEvaluatorType && ((GenerateExpressionEvaluatorType) object).getValuePolicyRef() != null) {
ObjectReferenceType ref = ((GenerateExpressionEvaluatorType) object).getValuePolicyRef();
try {
ValuePolicyType valuePolicyType = beans.mappingFactory.getObjectResolver().resolve(ref, ValuePolicyType.class, null, "resolving value policy for generate attribute " + outputDefinition.getItemName() + " value", task, result);
if (valuePolicyType != null) {
return valuePolicyType;
}
} catch (CommonException ex) {
throw new SystemException(ex.getMessage(), ex);
}
}
}
}
}
return null;
}
};
VariablesMap variables = new VariablesMap();
variables.put(ExpressionConstants.VAR_FOCUS, focusOdo, focusOdo.getDefinition());
variables.put(ExpressionConstants.VAR_USER, focusOdo, focusOdo.getDefinition());
variables.registerAlias(ExpressionConstants.VAR_USER, ExpressionConstants.VAR_FOCUS);
variables.put(ExpressionConstants.VAR_ITERATION, iteration, Integer.class);
variables.put(ExpressionConstants.VAR_ITERATION_TOKEN, iterationToken, String.class);
variables.put(ExpressionConstants.VAR_CONFIGURATION, configuration, SystemConfigurationType.class);
variables.put(ExpressionConstants.VAR_OPERATION, context.getFocusContext().getOperation().getValue(), String.class);
variables.put(ExpressionConstants.VAR_SOURCE, originObject, ObjectType.class);
PrismContext prismContext = beans.prismContext;
TypedValue<PrismObject<T>> defaultTargetContext = new TypedValue<>(targetContext);
Collection<V> targetValues = ExpressionUtil.computeTargetValues(mappingBean.getTarget(), defaultTargetContext, variables, beans.mappingFactory.getObjectResolver(), contextDesc, prismContext, task, result);
MappingSpecificationType specification = new MappingSpecificationType(prismContext).mappingName(mappingBean.getName()).definitionObjectRef(ObjectTypeUtil.createObjectRef(originObject, prismContext)).assignmentId(createAssignmentId(assignmentPathVariables));
MappingBuilder<V, D> mappingBuilder = beans.mappingFactory.<V, D>createMappingBuilder(mappingBean, contextDesc).sourceContext(focusOdo).defaultSource(defaultSource).targetContext(targetContext.getDefinition()).variablesFrom(variables).variablesFrom(LensUtil.getAssignmentPathVariablesMap(assignmentPathVariables, prismContext)).originalTargetValues(targetValues).mappingKind(mappingKind).originType(OriginType.USER_POLICY).originObject(originObject).valuePolicySupplier(valuePolicySupplier).rootNode(focusOdo).mappingPreExpression(// Used to populate autoassign assignments
request.getMappingPreExpression()).mappingSpecification(specification).now(now);
MappingImpl<V, D> mapping = mappingBuilder.build();
ItemPath itemPath = mapping.getOutputPath();
if (itemPath == null) {
// no output element, i.e. this is a "validation mapping"
return mapping;
}
Item<V, D> existingTargetItem = targetContext.findItem(itemPath);
if (existingTargetItem != null && !existingTargetItem.isEmpty() && mapping.getStrength() == MappingStrengthType.WEAK) {
LOGGER.trace("Mapping {} is weak and target already has a value {}, skipping.", mapping, existingTargetItem);
return null;
}
return mapping;
}
Aggregations