From e737f97cb3a97385bbb2dd52f61d57f96483e20e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olov=20Ylinenp=C3=A4=C3=A4?= Date: Thu, 17 Aug 2023 20:43:58 +0200 Subject: [PATCH] Add IntelliJ GroovyDSL script for whelktool --- .../src/main/groovy/datatool/WhelkTool.gdsl | 53 +++++++++++++++++++ .../src/main/groovy/datatool/WhelkTool.groovy | 1 + 2 files changed, 54 insertions(+) create mode 100644 whelktool/src/main/groovy/datatool/WhelkTool.gdsl diff --git a/whelktool/src/main/groovy/datatool/WhelkTool.gdsl b/whelktool/src/main/groovy/datatool/WhelkTool.gdsl new file mode 100644 index 0000000000..6d48feedac --- /dev/null +++ b/whelktool/src/main/groovy/datatool/WhelkTool.gdsl @@ -0,0 +1,53 @@ +/** + * GroovyDSL script for whelktool + * + * i.e. IntelliJ autocompletion for stuff added to whelktool script context via javax.script.Bindings + * + * https://youtrack.jetbrains.com/articles/GROOVY-A-15796912 + */ + +package datatool + +String ITEM = 'whelk.datatool.DocumentItem' +String DC = "Closure<$ITEM>" + +def ctx = context(scope:scriptScope(), pathRegexp:'.*whelktool/scripts/.*') + +contributor(ctx) { + property name:"scriptDir", type:String + property name:"baseUri", type:URI + method name:"asList", params:['':Object], type:List + method name:"create", params:['data':Map], type:ITEM + method name:"findCanonicalId", params:['id':String], type:String + // Seems like the only way to have optional arguments is to list all combinations + method name:"getAtPath", params:['item':Object, 'path':Iterable, 'defaultTo':Object], type:Object + method name:"getAtPath", params:['item':Object, 'path':Iterable], type:Object + method name:"getReportWriter", params:['reportName':String], type:PrintWriter + method name:"getWhelk", type:'whelk.Whelk' + method name:"incrementStats", params:['category':String, 'name':Object, 'example':Object] + method name:"incrementStats", params:['category':String, 'name':Object] + method name:"isInstanceOf", params:['entity':Map, 'baseType':String], type:boolean + method name:"load", params:['id':String], type:Map + method name:"queryDocs", params:['parameters':Map>], type:Iterable + method name:"queryIds", params:['parameters':Map>], type:Iterable + method name:"script", params:['scriptPath':String], type:Closure + method name:"selectByCollection", params:['collection':String, 'process':DC, 'batchSize':int, 'silent':boolean], type:void + method name:"selectByCollection", params:['collection':String, 'process':DC, 'batchSize':int], type:void + method name:"selectByCollection", params:['collection':String, 'process':DC, 'silent':boolean], type:void + method name:"selectByCollection", params:['collection':String, 'process':DC], type:void + method name:"selectByIds", params:['ids':Collection, 'process':DC, 'batchSize':int, 'silent':boolean], type:void + method name:"selectByIds", params:['ids':Collection, 'process':DC, 'batchSize':int], type:void + method name:"selectByIds", params:['ids':Collection, 'process':DC, 'silent':boolean], type:void + method name:"selectByIds", params:['ids':Collection, 'process':DC], type:void + method name:"selectBySqlWhere", params:['whereClause':String, 'batchSize':int, 'silent':boolean, 'process':DC], type:void + method name:"selectBySqlWhere", params:['whereClause':String, 'batchSize':int, 'process':DC], type:void + method name:"selectBySqlWhere", params:['whereClause':String, 'silent':boolean, 'process':DC], type:void + method name:"selectBySqlWhere", params:['whereClause':String, 'process':DC], type:void + method name:"selectBySqlWhere", + params:[params:[ + parameter(name:'silent', type:Boolean, doc:''), + parameter(name:'batchSize', type:int)], + 'whereClause':String, 'process':DC], + type:void + method name:"selectFromIterable", params:['docs':Iterable, 'process':DC] +} diff --git a/whelktool/src/main/groovy/datatool/WhelkTool.groovy b/whelktool/src/main/groovy/datatool/WhelkTool.groovy index 2c62b15296..fc789bcab8 100644 --- a/whelktool/src/main/groovy/datatool/WhelkTool.groovy +++ b/whelktool/src/main/groovy/datatool/WhelkTool.groovy @@ -627,6 +627,7 @@ class WhelkTool { } private Bindings createMainBindings() { + // Update Whelktool.gdsl when adding new bindings Bindings bindings = createDefaultBindings() bindings.put("scriptDir", scriptFile.parent) bindings.put("baseUri", Document.BASE_URI)