use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class ItemProcessingConditionEvaluator method evaluateConditionDefaultTrue.
boolean evaluateConditionDefaultTrue(@Nullable ExpressionType expression, @Nullable AdditionalVariableProvider additionalVariableProvider, OperationResult result) {
VariablesMap variables = new VariablesMap();
variables.put(ExpressionConstants.VAR_REQUEST, request, ItemProcessingRequest.class);
variables.put(ExpressionConstants.VAR_ITEM, request.getItem(), request.getItem().getClass());
if (additionalVariableProvider != null) {
additionalVariableProvider.provide(variables);
}
try {
return ExpressionUtil.evaluateConditionDefaultTrue(variables, expression, null, activityRun.getBeans().expressionFactory, "item condition expression", activityRun.getRunningTask(), result);
} catch (CommonException e) {
throw new SystemException("Couldn't evaluate 'before item' condition: " + e.getMessage(), e);
}
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class ExpressionValidator method validate.
@Override
public void validate(IValidatable<T> validatable) {
ExpressionType expressionType = expressionTypeModel.getObject();
if (expressionType == null) {
return;
}
PrismContext prismContext = serviceLocator.getPrismContext();
Object valueToValidate = getValueToValidate(validatable);
String contextDesc = " form component expression validation ";
PrismPropertyDefinition<OperationResultType> outputDefinition = prismContext.definitionFactory().createPropertyDefinition(ExpressionConstants.OUTPUT_ELEMENT_NAME, OperationResultType.COMPLEX_TYPE);
Task task = serviceLocator.createSimpleTask(OPERATION_EVALUATE_EXPRESSION);
OperationResult result = new OperationResult(OPERATION_EVALUATE_EXPRESSION);
ExpressionFactory expressionFactory = serviceLocator.getExpressionFactory();
Expression<PrismPropertyValue<OperationResultType>, PrismPropertyDefinition<OperationResultType>> expression;
try {
expression = expressionFactory.makeExpression(expressionType, outputDefinition, MiscSchemaUtil.getExpressionProfile(), contextDesc, task, result);
} catch (SchemaException | ObjectNotFoundException | SecurityViolationException e) {
ValidationError error = new ValidationError();
error.setMessage("Cannot make expression: " + e.getMessage());
validatable.error(error);
return;
}
VariablesMap variables = new VariablesMap();
Class typeClass = (valueToValidate == null ? String.class : valueToValidate.getClass());
variables.put(ExpressionConstants.VAR_INPUT, valueToValidate, typeClass);
variables.putObject(ExpressionConstants.VAR_OBJECT, (ObjectType) getObjectType(), ObjectType.class);
ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, contextDesc, task);
PrismValueDeltaSetTriple<PrismPropertyValue<OperationResultType>> outputTriple;
try {
outputTriple = expression.evaluate(context, result);
} catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException | CommunicationException | ConfigurationException | SecurityViolationException e) {
ValidationError error = new ValidationError();
error.setMessage("Cannot evaluate expression: " + e.getMessage());
validatable.error(error);
return;
}
if (outputTriple == null) {
return;
}
Collection<PrismPropertyValue<OperationResultType>> outputValues = outputTriple.getNonNegativeValues();
if (outputValues.isEmpty()) {
return;
}
if (outputValues.size() > 1) {
ValidationError error = new ValidationError();
error.setMessage("Expression " + contextDesc + " produced more than one value");
validatable.error(error);
}
OperationResultType operationResultType = outputValues.iterator().next().getRealValue();
if (operationResultType == null) {
return;
}
OperationResult returnResult = OperationResult.createOperationResult(operationResultType);
if (!returnResult.isSuccess()) {
ValidationError error = new ValidationError();
if (returnResult.getUserFriendlyMessage() != null) {
error.setMessage(WebModelServiceUtils.translateMessage(returnResult, serviceLocator));
} else {
error.setMessage(returnResult.getMessage());
}
validatable.error(error);
}
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class AccCertCaseOperationsHelper method computeDelegateTo.
private List<ObjectReferenceType> computeDelegateTo(DelegateWorkItemActionType delegateAction, AccessCertificationWorkItemType workItem, AccessCertificationCaseType aCase, AccessCertificationCampaignType campaign, Task task, OperationResult result) {
List<ObjectReferenceType> rv = CloneUtil.cloneCollectionMembers(delegateAction.getApproverRef());
if (!delegateAction.getApproverExpression().isEmpty()) {
VariablesMap variables = new VariablesMap();
variables.put(ExpressionConstants.VAR_WORK_ITEM, workItem, AccessCertificationWorkItemType.class);
variables.put(ExpressionConstants.VAR_CERTIFICATION_CASE, aCase, aCase.asPrismContainerValue().getDefinition());
variables.putObject(ExpressionConstants.VAR_CAMPAIGN, campaign, AccessCertificationCampaignType.class);
for (ExpressionType expression : delegateAction.getApproverExpression()) {
rv.addAll(expressionHelper.evaluateRefExpressionChecked(expression, variables, "computing delegates", task, result));
}
}
return rv;
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class CaseMiscHelper method getDefaultVariables.
public VariablesMap getDefaultVariables(CaseType aCase, ApprovalContextType wfContext, String requestChannel, OperationResult result) throws SchemaException {
VariablesMap variables = new VariablesMap();
variables.put(ExpressionConstants.VAR_REQUESTER, resolveTypedObjectReference(aCase.getRequestorRef(), result));
variables.put(ExpressionConstants.VAR_OBJECT, resolveTypedObjectReference(aCase.getObjectRef(), result));
// might be null
variables.put(ExpressionConstants.VAR_TARGET, resolveTypedObjectReference(aCase.getTargetRef(), result));
variables.put(ExpressionConstants.VAR_CHANNEL, requestChannel, String.class);
variables.put(ExpressionConstants.VAR_THE_CASE, aCase, List.class);
// FIXME these are specific for approvals
variables.put(ExpressionConstants.VAR_OBJECT_DELTA, getFocusPrimaryDelta(wfContext), ObjectDelta.class);
variables.put(ExpressionConstants.VAR_APPROVAL_CONTEXT, wfContext, ApprovalContextType.class);
return variables;
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class PerformerCommentsFormatterImpl method formatComment.
private String formatComment(ObjectReferenceType performerRef, AbstractWorkItemOutputType output, AbstractWorkItemType workItem, WorkItemCompletionEventType event, Task task, OperationResult result) {
if (formatting == null || formatting.getCondition() == null && formatting.getValue() == null) {
return output.getComment();
}
ObjectType performer = getPerformer(performerRef, result);
VariablesMap variables = new VariablesMap();
variables.put(ExpressionConstants.VAR_PERFORMER, performer, performer.asPrismObject().getDefinition());
variables.put(ExpressionConstants.VAR_OUTPUT, output, AbstractWorkItemOutputType.class);
variables.put(ExpressionConstants.VAR_WORK_ITEM, workItem, AbstractWorkItemType.class);
variables.put(ExpressionConstants.VAR_EVENT, event, WorkItemCompletionEventType.class);
if (formatting.getCondition() != null) {
try {
boolean condition = expressionEvaluationHelper.evaluateBooleanExpression(formatting.getCondition(), variables, "condition in performer comments formatter", task, result);
if (!condition) {
return null;
}
} catch (CommonException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't evaluate condition expression in comments formatter - continuing as if it were true; " + "performer = {}, output = {}, workItem = {}, event = {}", e, performer, output, workItem, event);
}
}
if (formatting.getValue() != null) {
try {
return expressionEvaluationHelper.evaluateStringExpression(formatting.getValue(), variables, "value in performer comments formatter", task, result);
} catch (CommonException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't evaluate value expression in comments formatter - using plain comment value; " + "performer = {}, output = {}, workItem = {}, event = {}", e, performer, output, workItem, event);
return output.getComment();
}
} else {
return output.getComment();
}
}
Aggregations