Groovy DSL Framework

This feature is available only in Enterprise Edition.

This section explains how to create your own scripts using the Groovy DSL. See the following sections (Connect to a Repository, Manage Data Sources, etc.) for information on how to use built-in functions to perform common administrative tasks.

Run a Script

To run a script against a running server, use the following Docker command:

Example 1. Run a script on a running server
docker run --rm -v /local/directory/path/file.groovy:/arbitrary/container/path/file.groovy ghcr.io/inetsoft-technology/stylebi-enterprise:latest dsl /arbitrary/container/path/file.groovy

where:

/local/directory/path/file.groovy

Path to a .groovy file on local machine to run (e.g. C:\temp\sample.groovy).

/arbitrary/container/path/file.groovy

Arbitrary path of a temporary directory and file to which the .groovy file should be mapped in the container.

Access Command Line Arguments

You can access command line arguments passed to the script runner by using the commandLine property.

Example 2. Command line arguments

Run the following script:

docker run --rm -v /local/directory/path/file.groovy:/arbitrary/container/path/file.groovy ghcr.io/inetsoft-technology/stylebi-enterprise:latest dsl /arbitrary/container/path/file.groovy arg1 arg2

Access the command line arguments (arg1, arg2) with the commandLine property as follows:

inetsoft {
    def scriptFile = commandLine[0]
    def firstArg = commandLine[1]
    def secondArg = commandLine[2]
    println "Running script: $scriptFile"
    println "First argument: $firstArg"
    println "Second argument: $secondArg"
}

Output:

Running script: test.groovy
First argument: arg1
Second argument: arg2

Connect to a Running Repository (Recommended)

This section explains how to connect to a repository for a server that is currently running. This is the recommended approach.

The outermost function in the DSL is inetsoft. Use this closure to define the connection parameters and to pass a closure to the connect function. See Connect to a Repository for additional information.

inetsoft {
  path 'http://example.com'
  username 'admin'
  password 'admin'
  connect {
    // code using the client API goes here
  }
  // no longer connected to the repository here
  connect {
    // this is a new connection
  }
}
The path property should designate a running server (e.g., http://example.com).

The DSL script above is the same as the following Groovy script that uses the client API directly:

import inetsoft.client.Client
import inetsoft.client.ClientFactory
String path = 'http://example.com'
String username = 'admin'
String password = 'admin'
ClientFactory factory = new ClientFactory()
Client client = factory.createLocalClient(path, username, password)
try {
  // code using the client API goes here
}
finally {
  client.close()
}
// no longer connected to the repository here
client = factory.createLocalClient(path, username, password)
try {
  // this is a new connection
}
finally {
  client.close()
}

Connect to a Non-Running Repository

This section explains how to connect to a repository for a server that is not currently running.

This is not the preferred approach. See Connect to a Running Repository (Recommended) for the recommended approach.

To connect to a non-running repository, use the following command, where -v is mounting the persistent storage volumes.

docker run --rm -v /local/directory/path/file.groovy:/arbitrary/container/path/file.groovy -v inetsoft_blob:/var/lib/inetsoft/blob -v inetsoft_kv:/var/lib/inetsoft/kv ghcr.io/inetsoft-technology/stylebi-enterprise:latest dsl /arbitrary/container/path/file.groovy
Volume names inetsoft_blob and inetsoft_kv may vary based on the host environment.

Use the Client Service APIs

In the connect closure, the DSL provides shorthand functions for accessing the client service APIs. The following functions are available:

Function Accesses…​

dataSource

inetsoft.enterprise.client.DataSourceClientService

file

inetsoft.enterprise.client.FileClientService

schedule

inetsoft.enterprise.client.ScheduleClientService

security

inetsoft.enterprise.client.SecurityClientService

Create a Data Structure with the DSL

In the connect closure, the DSL provides shorthand functions for creating the data structures required by the client APIs. The following functions are available:

Function Accesses…​

jdbc

inetsoft.enterprise.web.api.datasource.JdbcDataSourceProperties

tabular

inetsoft.enterprise.web.api.datasource.TabularDataSourceProperties

parameter

inetsoft.enterprise.web.api.report.ReportParameter

permission

inetsoft.enterprise.web.api.report.PermissionGrant

task

inetsoft.enterprise.web.api.schedule.ScheduleTask

timeCondition

inetsoft.enterprise.web.api.schedule.TimeCondition

completionCondition

inetsoft.enterprise.web.api.schedule.CompletionCondition

viewsheetAction

inetsoft.enterprise.web.api.schedule.ViewsheetAction

Example 3. Data structure (DSL)

Within the service closure, all methods of the service can be called directly, as shown below.

inetsoft {
  path 'http://www.example.com'
  username 'admin'
  password 'admin'
  connect {
    def t = task {
      name 'My Task'
      enabled false
    }
    schedule {
      updateScheduleTask('My Task',t)
    }
  }
}
The path property should designate a running server (e.g., http://example.com).
Example 4. Data structure (API)

The previous DSL script is the same as the following Groovy script that uses the client API directly:

import inetsoft.client.Client
import inetsoft.client.ClientFactory
import inetsoft.client.ScheduleClientService
import inetsoft.web.api.schedule.ScheduleTask
String path = 'http://www.example.com'
String username = 'admin'
String password = 'admin'
ClientFactory factory = new ClientFactory()
Client client = factory.createLocalClient(path, username, password)
try {
  ScheduleTask task = new ScheduleTask()
  task.setName('My Task')
  task.setEnabled(false)
  ScheduleClientService schedule = client.getScheduleService()
  schedule.updateScheduleTask('My Task', task)
}
finally {
  client.close()
}
The path property should designate a running server (e.g., http://example.com).

More examples of the DSL data structure functions can be found in Manage Data Sources and Manage Scheduled Tasks.