diff --git a/ccu-historian/src-webapp/query/jsonrpc.gy b/ccu-historian/src-webapp/query/jsonrpc.gy index 573068b..fb72c54 100644 --- a/ccu-historian/src-webapp/query/jsonrpc.gy +++ b/ccu-historian/src-webapp/query/jsonrpc.gy @@ -208,6 +208,7 @@ def executeScript(script, writeAccess) { binding.database=writeAccess ? database : new ReadOnlyDecorator(database) def exprAdapter=new DatabaseExpressionAdapter(storage: database) binding.dataPoint=exprAdapter.&dataPoint + binding.DP=exprAdapter.&dataPoint binding.version=Main.version // create shell and execute script diff --git a/ccu-historian/src/mdz/ccuhistorian/DatabaseSystem.groovy b/ccu-historian/src/mdz/ccuhistorian/DatabaseSystem.groovy index 2519b79..b7f5d5b 100644 --- a/ccu-historian/src/mdz/ccuhistorian/DatabaseSystem.groovy +++ b/ccu-historian/src/mdz/ccuhistorian/DatabaseSystem.groovy @@ -65,6 +65,15 @@ public class DatabaseSystem extends BaseSystem { public ExtendedStorage getDatabase() { extendedStorage } + // Unfortunately, the Binding class cannot be used. Function calls to properties that + // contain Closure's can only be forwarded with a separate class. + private static class Delegate { + def log + def database + def DP + def dataPoint + } + private startTasks() { def cparser=new CronParser(CronDefinitionBuilder.instanceDefinitionFor(QUARTZ)) config.databaseConfig.tasks.each { String name, DatabaseConfig.Task task -> @@ -77,11 +86,15 @@ public class DatabaseSystem extends BaseSystem { throw new Exception("Task $name has no script") } - def binding=new Binding() + def delegate=new Delegate() def scriptLog=Logger.getLogger("mdz.task.$name") - binding.setVariable("log", scriptLog) - binding.setVariable("database", extendedStorage) - task.script.delegate=binding + def exprAdapter=new DatabaseExpressionAdapter(storage: extendedStorage) + delegate.log=scriptLog + delegate.database=extendedStorage + // dataPoint() has several overloads that will be resolved dynamically! + delegate.dataPoint=exprAdapter.&dataPoint + delegate.DP=exprAdapter.&dataPoint + task.script.delegate=delegate task.script.resolveStrategy=Closure.DELEGATE_ONLY // schedule task