Skip to content

Commit

Permalink
Add IntelliJ GroovyDSL script for whelktool (#1287)
Browse files Browse the repository at this point in the history
  • Loading branch information
olovy authored Aug 18, 2023
1 parent dac3242 commit 9049542
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
53 changes: 53 additions & 0 deletions whelktool/src/main/groovy/datatool/WhelkTool.gdsl
Original file line number Diff line number Diff line change
@@ -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<String, List<String>>], type:Iterable<Map>
method name:"queryIds", params:['parameters':Map<String, List<String>>], type:Iterable<String>
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<String>, 'process':DC, 'batchSize':int, 'silent':boolean], type:void
method name:"selectByIds", params:['ids':Collection<String>, 'process':DC, 'batchSize':int], type:void
method name:"selectByIds", params:['ids':Collection<String>, 'process':DC, 'silent':boolean], type:void
method name:"selectByIds", params:['ids':Collection<String>, '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]
}
1 change: 1 addition & 0 deletions whelktool/src/main/groovy/datatool/WhelkTool.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9049542

Please sign in to comment.