Fix compile due to upstream elasticsearch changes.
Original commit: elastic/x-pack-elasticsearch@18033465c9
This commit is contained in:
parent
a569951187
commit
fec6ab7c22
|
@ -57,36 +57,6 @@ public class XMustacheScriptEngineService extends AbstractComponent implements S
|
|||
return (new XMustacheFactory(xContentType)).compile(new FastStringReader(template), "query-template");
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a compiled template object (as retrieved from the compile method)
|
||||
* and fill potential place holders with the variables given.
|
||||
*
|
||||
* @param compiledScript
|
||||
* compiled template object.
|
||||
* @param vars
|
||||
* map of variables to use during substitution.
|
||||
*
|
||||
* @return the processed string with all given variables substitued.
|
||||
* */
|
||||
@Override
|
||||
public Object execute(CompiledScript compiledScript, Map<String, Object> vars) {
|
||||
BytesStreamOutput result = new BytesStreamOutput();
|
||||
UTF8StreamWriter writer = utf8StreamWriter().setOutput(result);
|
||||
((Mustache) compiledScript.compiled()).execute(writer, vars);
|
||||
try {
|
||||
writer.flush();
|
||||
} catch (IOException e) {
|
||||
logger.error("Could not execute query template (failed to flush writer): ", e);
|
||||
} finally {
|
||||
try {
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
logger.error("Could not execute query template (failed to close writer): ", e);
|
||||
}
|
||||
}
|
||||
return result.bytes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] types() {
|
||||
return new String[] { NAME };
|
||||
|
|
|
@ -40,7 +40,7 @@ public class XMustacheScriptEngineTests extends ESTestCase {
|
|||
Map<String, Object> vars = new HashMap<>();
|
||||
vars.put("boost_val", "0.3");
|
||||
CompiledScript compiledScript = new CompiledScript(ScriptService.ScriptType.INLINE, "inline", "mustache", engine.compile(template));
|
||||
BytesReference o = (BytesReference) engine.execute(compiledScript, vars);
|
||||
BytesReference o = (BytesReference) engine.executable(compiledScript, vars).run();
|
||||
assertEquals("GET _search {\"query\": {\"boosting\": {\"positive\": {\"match\": {\"body\": \"gift\"}},"
|
||||
+ "\"negative\": {\"term\": {\"body\": {\"value\": \"solr\"}}}, \"negative_boost\": 0.3 } }}",
|
||||
new String(o.toBytes(), Charset.forName("UTF-8")));
|
||||
|
@ -52,7 +52,7 @@ public class XMustacheScriptEngineTests extends ESTestCase {
|
|||
vars.put("boost_val", "0.3");
|
||||
vars.put("body_val", "\"quick brown\"");
|
||||
CompiledScript compiledScript = new CompiledScript(ScriptService.ScriptType.INLINE, "inline", "mustache", engine.compile(template));
|
||||
BytesReference o = (BytesReference) engine.execute(compiledScript, vars);
|
||||
BytesReference o = (BytesReference) engine.executable(compiledScript, vars).run();
|
||||
assertEquals("GET _search {\"query\": {\"boosting\": {\"positive\": {\"match\": {\"body\": \"gift\"}},"
|
||||
+ "\"negative\": {\"term\": {\"body\": {\"value\": \"\\\"quick brown\\\"\"}}}, \"negative_boost\": 0.3 } }}",
|
||||
new String(o.toBytes(), Charset.forName("UTF-8")));
|
||||
|
@ -78,7 +78,7 @@ public class XMustacheScriptEngineTests extends ESTestCase {
|
|||
vars.put("test_var1", var1Writer.toString());
|
||||
vars.put("test_var2", var2Writer.toString());
|
||||
CompiledScript compiledScript = new CompiledScript(ScriptService.ScriptType.INLINE, "inline", "mustache", engine.compile(template));
|
||||
BytesReference o = (BytesReference) engine.execute(compiledScript, vars);
|
||||
BytesReference o = (BytesReference) engine.executable(compiledScript, vars).run();
|
||||
String s1 = o.toUtf8();
|
||||
String s2 = prefix + " " + var1Writer.toString() + " " + var2Writer.toString();
|
||||
assertEquals(s1, s2);
|
||||
|
|
|
@ -54,7 +54,7 @@ public class XMustacheTests extends ESTestCase {
|
|||
new String[] { "foo", "bar" },
|
||||
Arrays.asList("foo", "bar"));
|
||||
vars.put("data", data);
|
||||
Object output = engine.execute(mustache, vars);
|
||||
Object output = engine.executable(mustache, vars).run();
|
||||
assertThat(output, notNullValue());
|
||||
assertThat(output, instanceOf(BytesReference.class));
|
||||
BytesReference bytes = (BytesReference) output;
|
||||
|
@ -62,7 +62,7 @@ public class XMustacheTests extends ESTestCase {
|
|||
|
||||
// Sets can come out in any order
|
||||
vars.put("data", newHashSet("foo", "bar"));
|
||||
output = engine.execute(mustache, vars);
|
||||
output = engine.executable(mustache, vars).run();
|
||||
assertThat(output, notNullValue());
|
||||
assertThat(output, instanceOf(BytesReference.class));
|
||||
bytes = (BytesReference) output;
|
||||
|
@ -80,7 +80,7 @@ public class XMustacheTests extends ESTestCase {
|
|||
singleton(new String[] { "foo", "bar" })
|
||||
);
|
||||
vars.put("data", data);
|
||||
Object output = engine.execute(mustache, vars);
|
||||
Object output = engine.executable(mustache, vars).run();
|
||||
assertThat(output, notNullValue());
|
||||
assertThat(output, instanceOf(BytesReference.class));
|
||||
BytesReference bytes = (BytesReference) output;
|
||||
|
@ -96,7 +96,7 @@ public class XMustacheTests extends ESTestCase {
|
|||
new Map[] { ImmutableMap.<String, Object>of("key", "foo"), ImmutableMap.<String, Object>of("key", "bar") },
|
||||
Arrays.asList(ImmutableMap.<String, Object>of("key", "foo"), ImmutableMap.<String, Object>of("key", "bar")));
|
||||
vars.put("data", data);
|
||||
Object output = engine.execute(mustache, vars);
|
||||
Object output = engine.executable(mustache, vars).run();
|
||||
assertThat(output, notNullValue());
|
||||
assertThat(output, instanceOf(BytesReference.class));
|
||||
BytesReference bytes = (BytesReference) output;
|
||||
|
@ -104,7 +104,7 @@ public class XMustacheTests extends ESTestCase {
|
|||
|
||||
// HashSet iteration order isn't fixed
|
||||
vars.put("data", newHashSet(ImmutableMap.<String, Object>of("key", "foo"), ImmutableMap.<String, Object>of("key", "bar")));
|
||||
output = engine.execute(mustache, vars);
|
||||
output = engine.executable(mustache, vars).run();
|
||||
assertThat(output, notNullValue());
|
||||
assertThat(output, instanceOf(BytesReference.class));
|
||||
bytes = (BytesReference) output;
|
||||
|
@ -156,7 +156,7 @@ public class XMustacheTests extends ESTestCase {
|
|||
Map<String, Object> dataMap = new HashMap<>();
|
||||
dataMap.put("data", unescaped.toString());
|
||||
CompiledScript mustache = new CompiledScript(ScriptService.ScriptType.INLINE, "inline", "mustache", engine.compile(template));
|
||||
Object output = engine.execute(mustache, dataMap);
|
||||
Object output = engine.executable(mustache, dataMap).run();
|
||||
|
||||
assertThat(output, notNullValue());
|
||||
assertThat(output, instanceOf(BytesReference.class));
|
||||
|
|
Loading…
Reference in New Issue