Database Reference
In-Depth Information
ant = new AntBuilder()
ant.exec(executable:"groovy", outputproperty:"cmdOut",
resultproperty:"cmdExit", errorproperty:"cmdErr") {
arg(value:"QueryData")
}
sts = ant.project.properties.cmdExit as Integer
here we have accessed the exit status in a different way. We also capture the output
and error streams from the executed script. The Ant exec task is very flexible, allow-
ing fine control of the arguments to the child process and the environment in which it
runs. We use an AntBuilder to set those up with code, in a manner similar to using the
markupBuilder in our outline extractor demonstration.
A third technique to execute an external script illustrates a way to actually share vari-
ables among the calling and called scripts through a Binding. This technique does not
use the exit code from the called script. In fact, the called script runs in the same process
as the calling script, so a System.exit call will end both scripts. The following code only
works if the exit line is commented out of QueryData.groovy.
gse = new GroovyScriptEngine('.')
bnd = new Binding()
gse.run('QueryData.groovy', bnd)
ret = bnd.getVariable('allmatch')
sts = ret ? 0 : 1
Through the binding, we can peek into the called script and access its variables. We
pull back allmatch and use its value instead of an exit code to determine success or
failure. This brings up an important point: Any script variable that is not originally
declared with a type or the “def ” keyword is included in that script's binding, mak-
ing it global within its own script and available to outside scripts. Production scripts
should use def frequently to introduce untyped variables that are not needed by exter-
nal scripts. Large scripts should likewise use def to avoid variable name conflicts in the
global scope.
9.5.8 Adding Members to an Outline
In this recipe, we imagine an outline with a unified time dimension, having years, quar-
ters, months, and weeks all in the same dimension. Weeks are organized in a 4-5-4
fiscal calendar configuration. We have the associated year appended to the names of
lower-level members (like “Q1 Fy12”) to keep names unique in the dimension. There
are aliases at various levels in the default table and an extra alias table (“Close Dates”)
for week-level members, which stores Friday's date for that week. At year end, we need to
add 52 (sometimes 53) weeks, 12 months, 4 quarters, and 1 year member to the outline
to make room for the coming year's data. We need to assign aliases in both tables. We
could manage (with a few spreadsheets, text files, and Load rules) to avoid doing all of
that manually, but it would still feel like work. This code adds the members and aliases
directly to the outline.
import com.essbase.api.session.IEssbase
import com.essbase.api.datasource.IEssCube.EEssRestructureOption
import groovy.time.TimeCategory
essHome = IEssbase.Home.create(IEssbase.JAPI_VERSION)
Search WWH ::




Custom Search