use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class OperationRequestTransformer method transformOperationRequested.
@NotNull
public AsyncProvisioningRequest transformOperationRequested(@NotNull OperationRequested operationRequested, Task task, OperationResult result) {
try {
PredefinedOperationRequestTransformationType predefinedTransformation = connectorInstance.getPredefinedTransformation();
if (predefinedTransformation != null) {
return transformerHelper.applyPredefinedTransformation(operationRequested, predefinedTransformation);
}
ExpressionType transformExpression = connectorInstance.getTransformExpression();
if (transformExpression != null) {
VariablesMap variables = new VariablesMap();
variables.put(VAR_OPERATION_REQUESTED, operationRequested, operationRequested.getClass());
variables.put(VAR_TRANSFORMER_HELPER, transformerHelper, TransformerHelper.class);
variables.put(VAR_REQUEST_FORMATTER, transformerHelper.jsonRequestFormatter(operationRequested), JsonRequestFormatter.class);
List<?> list = connectorInstance.getUcfExpressionEvaluator().evaluate(transformExpression, variables, SchemaConstantsGenerated.C_ASYNC_PROVISIONING_REQUEST, "creating asynchronous provisioning request", task, result);
if (list.isEmpty()) {
throw new IllegalStateException("Transformational script returned no value");
}
if (list.size() > 1) {
throw new IllegalStateException("Transformational script returned more than single value: " + list);
}
Object o = list.get(0);
if (o == null) {
// In the future we can call e.g. default request creator here
throw new IllegalStateException("Transformational script returned no value");
} else if (o instanceof AsyncProvisioningRequest) {
return (AsyncProvisioningRequest) o;
} else if (o instanceof String) {
return StringAsyncProvisioningRequest.of((String) o);
} else {
throw new IllegalStateException("Transformational script should provide an AsyncProvisioningRequest but created " + MiscUtil.getClass(o) + " instead");
}
} else {
return transformerHelper.applyPredefinedTransformation(operationRequested, SIMPLIFIED_JSON);
}
} catch (RuntimeException | SchemaException | ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException | IOException e) {
throw new SystemException("Couldn't evaluate message transformation expression: " + e.getMessage(), e);
}
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class IterativeActivityRun method shouldProcessBucket.
private boolean shouldProcessBucket(OperationResult result) {
ExpressionType condition = getActivity().getControlFlowDefinition().getBucketProcessingCondition();
if (condition == null) {
return true;
}
VariablesMap variables = new VariablesMap();
variables.put(ExpressionConstants.VAR_BUCKET, bucket, WorkBucketType.class);
try {
return ExpressionUtil.evaluateConditionDefaultTrue(variables, condition, null, beans.expressionFactory, "bucket condition expression", getRunningTask(), result);
} catch (CommonException e) {
throw new SystemException("Couldn't evaluate bucket processing condition: " + e.getMessage(), e);
}
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class ResourceObjectReferenceResolver method resolve.
/**
* Resolves a {@link ResourceObjectReferenceType}.
*
* @param useRawDefinition If true, object class definition is used (instead of object type definition).
* This is to avoid endless recursion when resolving the base context for object type.
*/
@Nullable
PrismObject<ShadowType> resolve(@NotNull ProvisioningContext ctx, @NotNull ResourceObjectReferenceType resourceObjectReference, boolean useRawDefinition, @NotNull String desc, @NotNull OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
ObjectReferenceType shadowRef = resourceObjectReference.getShadowRef();
if (shadowRef != null && shadowRef.getOid() != null) {
if (resourceObjectReference.getResolutionFrequency() == null || resourceObjectReference.getResolutionFrequency() == ResourceObjectReferenceResolutionFrequencyType.ONCE) {
PrismObject<ShadowType> shadow = repositoryService.getObject(ShadowType.class, shadowRef.getOid(), null, result);
shadowsFacade.applyDefinition(shadow, ctx.getTask(), result);
return shadow;
}
} else if (resourceObjectReference.getResolutionFrequency() == ResourceObjectReferenceResolutionFrequencyType.NEVER) {
throw new ObjectNotFoundException("No shadowRef OID in " + desc + " and resolution frequency set to NEVER");
}
argCheck(resourceObjectReference.getObjectClass() != null, "No object class name in object reference in %s", desc);
QName objectClassName = QNameUtil.qualifyIfNeeded(resourceObjectReference.getObjectClass(), MidPointConstants.NS_RI);
ProvisioningContext subCtx = useRawDefinition ? ctx.spawnForObjectClassWithRawDefinition(objectClassName) : ctx.spawnForObjectClass(objectClassName);
subCtx.assertDefinition();
ObjectQuery refQuery = prismContext.getQueryConverter().createObjectQuery(ShadowType.class, resourceObjectReference.getFilter());
// No variables. At least not now. We expect that mostly constants will be used here.
VariablesMap variables = new VariablesMap();
ObjectQuery evaluatedRefQuery = ExpressionUtil.evaluateQueryExpressions(refQuery, variables, MiscSchemaUtil.getExpressionProfile(), expressionFactory, prismContext, desc, ctx.getTask(), result);
ObjectFilter baseFilter = ObjectQueryUtil.createResourceAndObjectClassFilter(ctx.getResource().getOid(), objectClassName, prismContext);
ObjectFilter filter = prismContext.queryFactory().createAnd(baseFilter, evaluatedRefQuery.getFilter());
ObjectQuery query = prismContext.queryFactory().createQuery(filter);
// TODO: implement "repo" search strategies, don't forget to apply definitions
Holder<PrismObject<ShadowType>> shadowHolder = new Holder<>();
ResultHandler<ShadowType> handler = (shadow, objResult) -> {
if (shadowHolder.getValue() != null) {
throw new IllegalStateException("More than one search results for " + desc);
}
shadowHolder.setValue(shadow);
return true;
};
shadowsFacade.searchObjectsIterative(subCtx, query, null, handler, result);
return shadowHolder.getValue();
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class UcfExpressionEvaluatorImpl method evaluate.
@NotNull
@Override
public <O> List<O> evaluate(ExpressionType expressionBean, VariablesMap variables, QName outputPropertyName, String ctxDesc, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
OperationResult result = parentResult.subresult(OP_EVALUATE).setMinor().build();
try {
Expression<PrismPropertyValue<O>, PrismPropertyDefinition<O>> expression = expressionFactory.makePropertyExpression(expressionBean, outputPropertyName, MiscSchemaUtil.getExpressionProfile(), ctxDesc, task, result);
VariablesMap exprVariables = new VariablesMap();
exprVariables.putAll(variables);
ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, exprVariables, ctxDesc, task);
PrismValueDeltaSetTriple<PrismPropertyValue<O>> exprResultTriple = expression.evaluate(context, result);
List<O> list = new ArrayList<>();
for (PrismPropertyValue<O> pv : exprResultTriple.getZeroSet()) {
list.add(pv.getRealValue());
}
return list;
} catch (Throwable t) {
result.recordFatalError(t);
throw t;
} finally {
result.computeStatusIfUnknown();
}
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class AbstractReport method isRejectedByExpression.
private boolean isRejectedByExpression(@NotNull Containerable record, @NotNull RunningTask task, @NotNull OperationResult result) {
if (recordFilteringExpression == null) {
return false;
}
VariablesMap variables = new VariablesMap();
variables.put(ExpressionConstants.VAR_RECORD, record, record.getClass());
try {
return !ExpressionUtil.evaluateConditionDefaultTrue(variables, recordFilteringExpression, null, beans.expressionFactory, "record filtering expression", task, result);
} catch (CommonException e) {
// Maybe we could propagate the checked exception upwards (later!)
throw new SystemException("Couldn't evaluate record filtering expression for " + record + ": " + e.getMessage(), e);
}
}
Aggregations