Skip to content

Commit

Permalink
add dataPoint() and DP() for Expression's in config file, closes #410
Browse files Browse the repository at this point in the history
add DP() short cut to JSON-RPC to executeScript
  • Loading branch information
mdzio committed Apr 1, 2024
1 parent cc84d8e commit 74d9453
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions ccu-historian/src-webapp/query/jsonrpc.gy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 17 additions & 4 deletions ccu-historian/src/mdz/ccuhistorian/DatabaseSystem.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand All @@ -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
Expand Down

0 comments on commit 74d9453

Please sign in to comment.