Search in sources :

Example 16 with ExpressionProfile

use of com.evolveum.midpoint.schema.expression.ExpressionProfile 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

ExpressionProfile (com.evolveum.midpoint.schema.expression.ExpressionProfile)16 VariablesMap (com.evolveum.midpoint.schema.expression.VariablesMap)7 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)6 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)3 ExpressionFactory (com.evolveum.midpoint.repo.common.expression.ExpressionFactory)3 ScriptExpressionProfile (com.evolveum.midpoint.schema.expression.ScriptExpressionProfile)3 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)3 Trace (com.evolveum.midpoint.util.logging.Trace)3 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)3 NotNull (org.jetbrains.annotations.NotNull)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 ExpressionSyntaxException (com.evolveum.midpoint.repo.common.expression.ExpressionSyntaxException)2 ExpressionUtil (com.evolveum.midpoint.repo.common.expression.ExpressionUtil)2 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)2 ExpressionEvaluatorProfile (com.evolveum.midpoint.schema.expression.ExpressionEvaluatorProfile)2 MiscSchemaUtil (com.evolveum.midpoint.schema.util.MiscSchemaUtil)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)2 Collection (java.util.Collection)2 List (java.util.List)2