Search in sources :

Example 1 with CustomFunctions

use of com.evolveum.midpoint.model.common.expression.functions.CustomFunctions 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.");
    }
}
Also used : GetOperationOptions.createReadOnlyCollection(com.evolveum.midpoint.schema.GetOperationOptions.createReadOnlyCollection) java.util(java.util) ExpressionEvaluatorProfile(com.evolveum.midpoint.schema.expression.ExpressionEvaluatorProfile) CacheInvalidationContext(com.evolveum.midpoint.CacheInvalidationContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) Cache(com.evolveum.midpoint.repo.api.Cache) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Trace(com.evolveum.midpoint.util.logging.Trace) PreDestroy(javax.annotation.PreDestroy) ScriptExpressionProfile(com.evolveum.midpoint.schema.expression.ScriptExpressionProfile) AccessDecision(com.evolveum.midpoint.schema.AccessDecision) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ExpressionSyntaxException(com.evolveum.midpoint.repo.common.expression.ExpressionSyntaxException) ScriptExpressionEvaluatorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionEvaluatorType) PrismContext(com.evolveum.midpoint.prism.PrismContext) MiscSchemaUtil(com.evolveum.midpoint.schema.util.MiscSchemaUtil) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) CacheRegistry(com.evolveum.midpoint.repo.api.CacheRegistry) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) FunctionLibraryType(com.evolveum.midpoint.xml.ns._public.common.common_3.FunctionLibraryType) SingleCacheStateInformationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SingleCacheStateInformationType) CustomFunctions(com.evolveum.midpoint.model.common.expression.functions.CustomFunctions) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ObjectResolver(com.evolveum.midpoint.repo.common.ObjectResolver) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) MidPointConstants(com.evolveum.midpoint.schema.constants.MidPointConstants) FunctionLibrary(com.evolveum.midpoint.model.common.expression.functions.FunctionLibrary) ExpressionProfile(com.evolveum.midpoint.schema.expression.ExpressionProfile) PostConstruct(javax.annotation.PostConstruct) NotNull(org.jetbrains.annotations.NotNull) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) FunctionLibraryType(com.evolveum.midpoint.xml.ns._public.common.common_3.FunctionLibraryType) FunctionLibrary(com.evolveum.midpoint.model.common.expression.functions.FunctionLibrary) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ScriptExpressionProfile(com.evolveum.midpoint.schema.expression.ScriptExpressionProfile) ExpressionProfile(com.evolveum.midpoint.schema.expression.ExpressionProfile) CustomFunctions(com.evolveum.midpoint.model.common.expression.functions.CustomFunctions) ExpressionSyntaxException(com.evolveum.midpoint.repo.common.expression.ExpressionSyntaxException)

Aggregations

CacheInvalidationContext (com.evolveum.midpoint.CacheInvalidationContext)1 CustomFunctions (com.evolveum.midpoint.model.common.expression.functions.CustomFunctions)1 FunctionLibrary (com.evolveum.midpoint.model.common.expression.functions.FunctionLibrary)1 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)1 PrismContext (com.evolveum.midpoint.prism.PrismContext)1 Cache (com.evolveum.midpoint.repo.api.Cache)1 CacheRegistry (com.evolveum.midpoint.repo.api.CacheRegistry)1 RepositoryService (com.evolveum.midpoint.repo.api.RepositoryService)1 ObjectResolver (com.evolveum.midpoint.repo.common.ObjectResolver)1 ExpressionFactory (com.evolveum.midpoint.repo.common.expression.ExpressionFactory)1 ExpressionSyntaxException (com.evolveum.midpoint.repo.common.expression.ExpressionSyntaxException)1 AccessDecision (com.evolveum.midpoint.schema.AccessDecision)1 GetOperationOptions.createReadOnlyCollection (com.evolveum.midpoint.schema.GetOperationOptions.createReadOnlyCollection)1 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)1 MidPointConstants (com.evolveum.midpoint.schema.constants.MidPointConstants)1 ExpressionEvaluatorProfile (com.evolveum.midpoint.schema.expression.ExpressionEvaluatorProfile)1 ExpressionProfile (com.evolveum.midpoint.schema.expression.ExpressionProfile)1 ScriptExpressionProfile (com.evolveum.midpoint.schema.expression.ScriptExpressionProfile)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 MiscSchemaUtil (com.evolveum.midpoint.schema.util.MiscSchemaUtil)1