Database Reference
In-Depth Information
Both the withreader and eachLine methods used here feature groovy's automatic
resource management. They create file readers for us and, more importantly, guarantee
they also will clean them up before returning.
The =~ found on two lines is a regular expression operator (see Section 9.4.10). We
use it to search within strings. We identify lines that have a “Product” member and a
“market” member by checking if their second character is a digit (\d). When we find one
of those lines, we split it apart at the double-quotes, pull out the “market” member, and
check to see if it is in the list of members we care about. The matcher object returned by
the =~ operator converts directly to a Boolean value indicating whether there is or is not
a match, and, thus, whether we should begin copying lines from file to file.
9.5.5 Sorting an Outline and Querying Attributes
Sorting the members of an outline is a common need. usually, this means doing it
alphabetically or numerically by the member name, but what about other ways? What
about sorting an employee dimension where names are the aliases and the member
names are ID numbers? What if we want to sort our sales departments by their revenue
dollars? It could happen. In this recipe, we run queries against Sample.Basic to sort its
market dimension. We sort by population size (descending), and members with identi-
cal populations are placed in alphabetical order. This is a two-in-one demonstration
because we have not as yet seen how to access member attributes.
import com.essbase.api.session.IEssbase
import com.essbase.api.datasource.IEssCube.EEssRestructureOption
essHome = IEssbase.Home.create(IEssbase.JAPI_VERSION)
essSvr = essHome.signOn('user', 'pass', false, null, 'embedded',
'ess_server')
essCube = essSvr.getApplication('Sample').getCube('Basic')
mbrSel = essCube.openMemberSelection('default')
// selecting members with calc script member set functions
mbrSel.executeQuery('<OutputType Binary <SelectMbrInfo (MemberName,
MemberAliasName)', '@DESCENDANTS("Market")')
mbrs = []
mbrSel.members.all.each {
def attrs = essCube.getAssociatedAttributes(it.name,
'Population')
mbrs << [(it.name), (attrs ? (attrs[0][3] + 'f').toFloat() :
0)]
}
mbrs = mbrs.sort{it[0]}.reverse().sort{it[1]} // sorting three ways
at once
mbrSel.close()
mbrSel = null
essOtl = essCube.openOutline(false, true, true)
// use 'collect' to make a simpler collection from the old then
iterate on that
mbrs.collect {it[0]}.each { mbrName ->
essMbr = essOtl.findMember(mbrName)
essPrnt = essOtl.findMember(essMbr.getParentMemberName())
essOtl.moveMember(essMbr, essPrnt, null)
}
Search WWH ::




Custom Search