use of com.evolveum.midpoint.xml.ns._public.common.common_3.FunctionLibraryType in project midpoint by Evolveum.
the class FunctionExpressionEvaluator method getFunctionExpressionBean.
private ExpressionType getFunctionExpressionBean(ObjectReferenceType functionLibraryRef, ExpressionEvaluationContext context, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
Task task = context.getTask();
OperationResult result = parentResult.createMinorSubresult(OP_GET_FUNCTION_TO_EXECUTE);
try {
FunctionLibraryType functionLibrary = objectResolver.resolve(functionLibraryRef, FunctionLibraryType.class, null, "resolving value policy reference in generateExpressionEvaluator", task, result);
List<ExpressionType> allFunctions = functionLibrary.getFunction();
if (CollectionUtils.isEmpty(allFunctions)) {
throw new ObjectNotFoundException("No functions defined in referenced function library: " + functionLibrary + " used in " + context.getContextDescription());
}
String functionName = expressionEvaluatorBean.getName();
if (StringUtils.isEmpty(functionName)) {
throw new SchemaException("Missing function name in " + shortDebugDump() + " in " + context.getContextDescription());
}
List<ExpressionType> functionsMatchingName = allFunctions.stream().filter(expression -> functionName.equals(expression.getName())).collect(Collectors.toList());
if (functionsMatchingName.isEmpty()) {
String allFunctionNames = allFunctions.stream().map(ExpressionType::getName).collect(Collectors.joining(", "));
throw new ObjectNotFoundException("No function with name " + functionName + " found in " + shortDebugDump() + ". Function defined are: " + allFunctionNames + ". In " + context.getContextDescription());
}
return selectFromMatchingFunctions(functionsMatchingName, context);
} catch (Throwable t) {
result.recordFatalError(t);
throw t;
} finally {
result.computeStatusIfUnknown();
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.FunctionLibraryType in project midpoint by Evolveum.
the class ScriptExpressionFactory method initializeCustomFunctionsLibraryCache.
private void initializeCustomFunctionsLibraryCache(ExpressionFactory expressionFactory, OperationResult result) throws ExpressionSyntaxException {
if (repositoryService != null) {
OperationResult subResult = result.createMinorSubresult(ScriptExpressionFactory.class.getName() + ".searchCustomFunctions");
ResultHandler<FunctionLibraryType> functionLibraryHandler = (object, parentResult) -> {
// TODO: determine profile from function library archetype
ExpressionProfile expressionProfile = MiscSchemaUtil.getExpressionProfile();
FunctionLibrary customLibrary = new FunctionLibrary();
customLibrary.setVariableName(object.getName().getOrig());
customLibrary.setGenericFunctions(new CustomFunctions(object.asObjectable(), expressionFactory, expressionProfile));
customLibrary.setNamespace(MidPointConstants.NS_FUNC_CUSTOM);
customFunctionLibraryCache.put(object.getName().getOrig(), customLibrary);
return true;
};
try {
repositoryService.searchObjectsIterative(FunctionLibraryType.class, null, functionLibraryHandler, createReadOnlyCollection(), true, subResult);
subResult.recordSuccessIfUnknown();
} catch (SchemaException | RuntimeException e) {
subResult.recordFatalError("Failed to initialize custom functions", e);
throw new ExpressionSyntaxException("An error occurred during custom libraries initialization. " + e.getMessage(), e);
}
} else {
LOGGER.warn("No repository service set for ScriptExpressionFactory; custom functions will not be loaded. This" + " can occur during low-level testing; never during standard system execution.");
}
}
Aggregations