All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.elasticsearch.index.mapper.TestScriptEngine Maven / Gradle / Ivy

There is a newer version: 8.16.0
Show newest version
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0 and the Server Side Public License, v 1; you may not use this file except
 * in compliance with, at your election, the Elastic License 2.0 or the Server
 * Side Public License, v 1.
 */

package org.elasticsearch.index.mapper;

import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.script.ScriptContext;
import org.elasticsearch.script.ScriptEngine;
import org.elasticsearch.script.ScriptService;

import java.util.Map;
import java.util.Set;

public abstract class TestScriptEngine implements ScriptEngine {
    public static  ScriptService scriptService(ScriptContext context, F factory) {
        return new ScriptService(Settings.EMPTY, Map.of("test", new TestScriptEngine() {
            @Override
            protected Object buildScriptFactory(ScriptContext context) {
                return factory;
            }

            @Override
            public Set> getSupportedContexts() {
                return Set.of(context);
            }
        }), Map.of(context.name, context), () -> 1L);
    }

    @Override
    public final String getType() {
        return "test";
    }

    @Override
    public final  FactoryType compile(
        String name,
        String code,
        ScriptContext context,
        Map params
    ) {
        @SuppressWarnings("unchecked")
        FactoryType castFactory = (FactoryType) buildScriptFactory(context);
        return castFactory;
    }

    protected abstract Object buildScriptFactory(ScriptContext context);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy