Kaynağa Gözat

nashorn stuff

kpmy 8 yıl önce
ebeveyn
işleme
de9bdc7f1b

+ 11 - 0
src/main/java/in/ocsf/report/app/controller/TestController.java

@@ -17,7 +17,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.script.Invocable;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
 import java.io.File;
+import java.io.FileReader;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
@@ -88,6 +92,13 @@ public class TestController {
         GroovyShell groovyShell = new GroovyShell(binding);
         Processor p = proxify(groovyShell.evaluate(new File(ResourceUtils.getURL("classpath:/groovy/fias/address/QueryAddress.groovy").getFile())));
         Iterable<Address> yars0 = addrRepo.findAll(p.process());
+
+        ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
+        engine.eval(new FileReader(ResourceUtils.getURL("classpath:/js/QueryAddress.js").getFile()));
+        Invocable inv = (Invocable) engine;
+
+        Iterable<Address> yars1 = addrRepo.findAll((Predicate) inv.invokeFunction("process"));
+
         return top;
     }
 

+ 9 - 0
src/main/resources/js/QueryAddress.js

@@ -0,0 +1,9 @@
+/**
+ * Created by petry_000 on 13.03.2017.
+ */
+var QAddress = Java.type("in.ocsf.report.app.object.QAddress");
+var address = QAddress.address;
+
+var process = function () {
+    return address.region.like("76").and(address.parentGuid.isNull());
+};