|
@@ -2,17 +2,25 @@ package in.ocsf.report.app.controller;/* kpmy 05.03.2017 */
|
|
|
|
|
|
import com.querydsl.collections.CollQueryFactory;
|
|
|
import com.querydsl.core.Tuple;
|
|
|
+import com.querydsl.core.types.Predicate;
|
|
|
import com.querydsl.jpa.impl.JPAQueryFactory;
|
|
|
+import groovy.lang.Binding;
|
|
|
+import groovy.lang.GroovyShell;
|
|
|
import in.ocsf.report.api.ReportPrototype;
|
|
|
import in.ocsf.report.api.StagePrototype;
|
|
|
import in.ocsf.report.api.TablePrototype;
|
|
|
import in.ocsf.report.app.object.Address;
|
|
|
import in.ocsf.report.app.repo.AddressRepository;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.util.ResourceUtils;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.lang.reflect.InvocationHandler;
|
|
|
+import java.lang.reflect.Method;
|
|
|
+import java.lang.reflect.Proxy;
|
|
|
import java.util.List;
|
|
|
|
|
|
import static in.ocsf.report.app.object.QAddress.address;
|
|
@@ -40,8 +48,21 @@ public class TestController {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ private Processor proxify(Object obj) {
|
|
|
+ return (Processor) Proxy.newProxyInstance(obj.getClass().getClassLoader(),
|
|
|
+ new Class[]{Processor.class},
|
|
|
+ new InvocationHandler() {
|
|
|
+ @Override
|
|
|
+ public Object invoke(Object proxy, Method method, Object[] args)
|
|
|
+ throws Throwable {
|
|
|
+ Method m = obj.getClass().getMethod(method.getName());
|
|
|
+ return m.invoke(obj, args);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
@RequestMapping("test/repo/address")
|
|
|
- public List<Address> addr() {
|
|
|
+ public List<Address> addr() throws Exception {
|
|
|
List<Address> top = addrRepo.findActualTop();
|
|
|
for (Address address : top) {
|
|
|
List<Address> next = addrRepo.findAll(where(hasParent(address.getGuid())).and(isActual()));
|
|
@@ -60,6 +81,17 @@ public class TestController {
|
|
|
Tuple yarres = jpaQueryFactory.select(address.name, address.region).from(address).where(address.region.like("76").and(address.parentGuid.isNull())).fetchFirst();
|
|
|
|
|
|
String yarName2 = yarres.get(address.name);
|
|
|
+
|
|
|
+ Binding binding = new Binding();
|
|
|
+ binding.setVariable("address", address);
|
|
|
+
|
|
|
+ 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());
|
|
|
return top;
|
|
|
}
|
|
|
+
|
|
|
+ public interface Processor {
|
|
|
+ Predicate process();
|
|
|
+ }
|
|
|
}
|