use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class ContainerableListPanel method evaluateExpression.
protected Collection<String> evaluateExpression(C rowValue, Item<?, ?> columnItem, ExpressionType expression, GuiObjectColumnType customColumn) {
Task task = getPageBase().createSimpleTask(OPERATION_EVALUATE_EXPRESSION);
OperationResult result = task.getResult();
try {
VariablesMap variablesMap = new VariablesMap();
variablesMap.put(ExpressionConstants.VAR_OBJECT, rowValue, rowValue.getClass());
if (columnItem != null) {
variablesMap.put(ExpressionConstants.VAR_INPUT, columnItem, columnItem.getDefinition());
}
return ExpressionUtil.evaluateStringExpression(variablesMap, getPageBase().getPrismContext(), expression, MiscSchemaUtil.getExpressionProfile(), getPageBase().getExpressionFactory(), "evaluate column expression", task, result);
} catch (Exception e) {
LOGGER.error("Couldn't execute expression for {} column. Reason: {}", customColumn, e.getMessage(), e);
result.recomputeStatus();
OperationResultStatusPresentationProperties props = OperationResultStatusPresentationProperties.parseOperationalResultStatus(result.getStatus());
// TODO: this is not entirely correct
return Collections.singletonList(getPageBase().createStringResource(props.getStatusLabelKey()).getString());
}
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class ObjectNameColumn method evaluateExpression.
private String evaluateExpression(Item<ICellPopulator<SelectableBean<O>>> cellItem, ItemPath itemPath, O value) {
Task task = pageBase.createSimpleTask("evaluate column expression");
try {
com.evolveum.midpoint.prism.Item<?, ?> item = value.asPrismObject().findItem(itemPath);
VariablesMap variablesMap = new VariablesMap();
variablesMap.put(ExpressionConstants.VAR_OBJECT, value, value.getClass());
if (item != null) {
variablesMap.put(ExpressionConstants.VAR_INPUT, item, item.getDefinition().getTypeClass());
}
Collection<String> evaluatedValues = ExpressionUtil.evaluateStringExpression(variablesMap, pageBase.getPrismContext(), expression, MiscSchemaUtil.getExpressionProfile(), pageBase.getExpressionFactory(), "evaluate column expression", task, task.getResult());
if (evaluatedValues != null) {
return evaluatedValues.iterator().next();
}
return null;
} catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException | CommunicationException | ConfigurationException | SecurityViolationException e) {
LOGGER.error("Couldn't execute expression for name column");
OperationResult result = task.getResult();
OperationResultStatusPresentationProperties props = OperationResultStatusPresentationProperties.parseOperationalResultStatus(result.getStatus());
return cellItem.getString(props.getStatusLabelKey());
}
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class DirectAssignmentCertificationHandler method itemSelectionExpressionAccepts.
@SuppressWarnings("unused")
private boolean itemSelectionExpressionAccepts(AssignmentType assignment, boolean isInducement, ObjectType object, AccessCertificationCampaignType campaign, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
AccessCertificationObjectBasedScopeType scope = null;
if (campaign.getScopeDefinition() instanceof AccessCertificationObjectBasedScopeType) {
scope = (AccessCertificationObjectBasedScopeType) (campaign.getScopeDefinition());
}
if (scope == null || scope.getItemSelectionExpression() == null) {
// no expression, no rejections
return true;
}
ExpressionType selectionExpression = scope.getItemSelectionExpression();
VariablesMap variables = new VariablesMap();
variables.put(ExpressionConstants.VAR_ASSIGNMENT, assignment, AssignmentType.class);
if (object instanceof FocusType) {
variables.putObject(ExpressionConstants.VAR_FOCUS, (FocusType) object, FocusType.class);
}
if (object instanceof UserType) {
variables.putObject(ExpressionConstants.VAR_USER, (UserType) object, UserType.class);
}
return expressionHelper.evaluateBooleanExpression(selectionExpression, variables, "item selection for assignment " + ObjectTypeUtil.toShortString(assignment), task, result);
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class PrimaryChangeAspectHelper method evaluateApplicabilityCondition.
// endregion
// region ========================================================================== Expression evaluation
public boolean evaluateApplicabilityCondition(PcpAspectConfigurationType config, ModelContext modelContext, Serializable itemToApprove, VariablesMap additionalVariables, PrimaryChangeAspect aspect, Task task, OperationResult result) {
if (config == null || config.getApplicabilityCondition() == null) {
return true;
}
ExpressionType expressionType = config.getApplicabilityCondition();
QName resultName = new QName(SchemaConstants.NS_C, "result");
PrismPropertyDefinition<Boolean> resultDef = prismContext.definitionFactory().createPropertyDefinition(resultName, DOMUtil.XSD_BOOLEAN);
VariablesMap variablesMap = new VariablesMap();
variablesMap.put(ExpressionConstants.VAR_MODEL_CONTEXT, modelContext, ModelContext.class);
variablesMap.put(ExpressionConstants.VAR_ITEM_TO_APPROVE, itemToApprove, itemToApprove.getClass());
if (additionalVariables != null) {
variablesMap.addVariableDefinitions(additionalVariables);
}
PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> exprResultTriple;
try {
Expression<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> expression = expressionFactory.makeExpression(expressionType, resultDef, MiscSchemaUtil.getExpressionProfile(), "applicability condition expression", task, result);
ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, variablesMap, "applicability condition expression", task);
exprResultTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, params, task, result);
} catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException | RuntimeException | CommunicationException | ConfigurationException | SecurityViolationException e) {
// TODO report as a specific exception?
throw new SystemException("Couldn't evaluate applicability condition in aspect " + aspect.getClass().getSimpleName() + ": " + e.getMessage(), e);
}
Collection<PrismPropertyValue<Boolean>> exprResult = exprResultTriple.getZeroSet();
if (exprResult.size() == 0) {
return false;
} else if (exprResult.size() > 1) {
throw new IllegalStateException("Applicability condition expression should return exactly one boolean value; it returned " + exprResult.size() + " ones");
}
Boolean boolResult = exprResult.iterator().next().getValue();
return boolResult != null ? boolResult : false;
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class CaseStageOpening method computeAdditionalInformation.
private void computeAdditionalInformation(CaseWorkItemType workItem, OperationResult result) {
if (stageDef.getAdditionalInformation() != null) {
try {
VariablesMap variables = beans.caseMiscHelper.getDefaultVariables(currentCase, approvalContext, task.getChannel(), result);
workItem.getAdditionalInformation().addAll(beans.expressionEvaluationHelper.evaluateExpression(stageDef.getAdditionalInformation(), variables, "additional information expression", InformationType.class, InformationType.COMPLEX_TYPE, true, this::createInformationType, operation.getTask(), result));
} catch (Throwable t) {
throw new SystemException("Couldn't evaluate additional information expression in " + operation, t);
}
}
}
Aggregations