Search in sources :

Example 1 with GroovyScriptEvaluator

use of com.evolveum.midpoint.model.common.expression.script.groovy.GroovyScriptEvaluator in project midpoint by Evolveum.

the class ExpressionTestUtil method createInitializedExpressionFactory.

public static ExpressionFactory createInitializedExpressionFactory(ObjectResolver resolver, Protector protector, PrismContext prismContext, Clock clock, SecurityContextManager securityContextManager, RepositoryService repositoryService) {
    ExpressionFactory expressionFactory = new ExpressionFactory(securityContextManager, prismContext, LocalizationTestUtil.getLocalizationService());
    expressionFactory.setObjectResolver(resolver);
    // NOTE: we need to register the evaluator factories to expressionFactory manually here
    // this is not spring-wired test. PostConstruct methods are not invoked here
    // asIs
    AsIsExpressionEvaluatorFactory asIsFactory = new AsIsExpressionEvaluatorFactory(prismContext, protector);
    expressionFactory.registerEvaluatorFactory(asIsFactory);
    expressionFactory.setDefaultEvaluatorFactory(asIsFactory);
    // value
    LiteralExpressionEvaluatorFactory valueFactory = new LiteralExpressionEvaluatorFactory(prismContext);
    expressionFactory.registerEvaluatorFactory(valueFactory);
    // const
    ConstantsManager constManager = new ConstantsManager(createConfiguration());
    ConstExpressionEvaluatorFactory constFactory = new ConstExpressionEvaluatorFactory(protector, constManager, prismContext);
    expressionFactory.registerEvaluatorFactory(constFactory);
    // path
    PathExpressionEvaluatorFactory pathFactory = new PathExpressionEvaluatorFactory(expressionFactory, prismContext, protector, null);
    pathFactory.setObjectResolver(resolver);
    expressionFactory.registerEvaluatorFactory(pathFactory);
    // generate
    ValuePolicyProcessor valuePolicyGenerator = new ValuePolicyProcessor();
    valuePolicyGenerator.setExpressionFactory(expressionFactory);
    GenerateExpressionEvaluatorFactory generateFactory = new GenerateExpressionEvaluatorFactory(expressionFactory, protector, valuePolicyGenerator, prismContext, null);
    generateFactory.setObjectResolver(resolver);
    expressionFactory.registerEvaluatorFactory(generateFactory);
    // script
    Collection<FunctionLibrary> functions = new ArrayList<>();
    functions.add(FunctionLibraryUtil.createBasicFunctionLibrary(prismContext, protector, clock));
    functions.add(FunctionLibraryUtil.createLogFunctionLibrary(prismContext));
    ScriptExpressionFactory scriptExpressionFactory = new ScriptExpressionFactory(prismContext, repositoryService);
    scriptExpressionFactory.setObjectResolver(resolver);
    scriptExpressionFactory.setFunctions(functions);
    GroovyScriptEvaluator groovyEvaluator = new GroovyScriptEvaluator(prismContext, protector, LocalizationTestUtil.getLocalizationService());
    scriptExpressionFactory.registerEvaluator(groovyEvaluator.getLanguageUrl(), groovyEvaluator);
    Jsr223ScriptEvaluator jsEvaluator = new Jsr223ScriptEvaluator("ECMAScript", prismContext, protector, LocalizationTestUtil.getLocalizationService());
    if (jsEvaluator.isInitialized()) {
        scriptExpressionFactory.registerEvaluator(jsEvaluator.getLanguageUrl(), jsEvaluator);
    }
    ScriptExpressionEvaluatorFactory scriptExpressionEvaluatorFactory = new ScriptExpressionEvaluatorFactory(scriptExpressionFactory, securityContextManager, prismContext);
    expressionFactory.registerEvaluatorFactory(scriptExpressionEvaluatorFactory);
    return expressionFactory;
}
Also used : ScriptExpressionFactory(com.evolveum.midpoint.model.common.expression.script.ScriptExpressionFactory) Jsr223ScriptEvaluator(com.evolveum.midpoint.model.common.expression.script.jsr223.Jsr223ScriptEvaluator) ScriptExpressionFactory(com.evolveum.midpoint.model.common.expression.script.ScriptExpressionFactory) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) GroovyScriptEvaluator(com.evolveum.midpoint.model.common.expression.script.groovy.GroovyScriptEvaluator) ConstantsManager(com.evolveum.midpoint.model.common.ConstantsManager) ArrayList(java.util.ArrayList) FunctionLibrary(com.evolveum.midpoint.model.common.expression.functions.FunctionLibrary) AsIsExpressionEvaluatorFactory(com.evolveum.midpoint.repo.common.expression.evaluator.AsIsExpressionEvaluatorFactory) LiteralExpressionEvaluatorFactory(com.evolveum.midpoint.repo.common.expression.evaluator.LiteralExpressionEvaluatorFactory) ValuePolicyProcessor(com.evolveum.midpoint.model.common.stringpolicy.ValuePolicyProcessor) ConstExpressionEvaluatorFactory(com.evolveum.midpoint.model.common.expression.evaluator.ConstExpressionEvaluatorFactory) GenerateExpressionEvaluatorFactory(com.evolveum.midpoint.model.common.expression.evaluator.GenerateExpressionEvaluatorFactory) ScriptExpressionEvaluatorFactory(com.evolveum.midpoint.model.common.expression.script.ScriptExpressionEvaluatorFactory) PathExpressionEvaluatorFactory(com.evolveum.midpoint.model.common.expression.evaluator.path.PathExpressionEvaluatorFactory)

Aggregations

ConstantsManager (com.evolveum.midpoint.model.common.ConstantsManager)1 ConstExpressionEvaluatorFactory (com.evolveum.midpoint.model.common.expression.evaluator.ConstExpressionEvaluatorFactory)1 GenerateExpressionEvaluatorFactory (com.evolveum.midpoint.model.common.expression.evaluator.GenerateExpressionEvaluatorFactory)1 PathExpressionEvaluatorFactory (com.evolveum.midpoint.model.common.expression.evaluator.path.PathExpressionEvaluatorFactory)1 FunctionLibrary (com.evolveum.midpoint.model.common.expression.functions.FunctionLibrary)1 ScriptExpressionEvaluatorFactory (com.evolveum.midpoint.model.common.expression.script.ScriptExpressionEvaluatorFactory)1 ScriptExpressionFactory (com.evolveum.midpoint.model.common.expression.script.ScriptExpressionFactory)1 GroovyScriptEvaluator (com.evolveum.midpoint.model.common.expression.script.groovy.GroovyScriptEvaluator)1 Jsr223ScriptEvaluator (com.evolveum.midpoint.model.common.expression.script.jsr223.Jsr223ScriptEvaluator)1 ValuePolicyProcessor (com.evolveum.midpoint.model.common.stringpolicy.ValuePolicyProcessor)1 ExpressionFactory (com.evolveum.midpoint.repo.common.expression.ExpressionFactory)1 AsIsExpressionEvaluatorFactory (com.evolveum.midpoint.repo.common.expression.evaluator.AsIsExpressionEvaluatorFactory)1 LiteralExpressionEvaluatorFactory (com.evolveum.midpoint.repo.common.expression.evaluator.LiteralExpressionEvaluatorFactory)1 ArrayList (java.util.ArrayList)1