// If a sort order was specified, we need to wrap the inclusions in an
// Order() mdx function.
List<ParseTreeNode> orderedList = new ArrayList<ParseTreeNode>();
if (dimension.getSortOrder() != null) {
CallNode currentMemberNode = new CallNode(
null,
"CurrentMember",
Syntax.Property,
new DimensionNode(null, dimension.getDimension()));
CallNode currentMemberNameNode = new CallNode(
null,
"Name",
Syntax.Property,
currentMemberNode);
orderedList.add(
new CallNode(
null,
"Order",
Syntax.Function,
generateListSetCall(includeList),
currentMemberNameNode,
LiteralNode.createSymbol(
null, dimension.getSortOrder().name())));
} else {
orderedList.addAll(includeList);
}
// We're not done yet. We might have to exclude members from the
// inclusion, so we might have to wrap the list in a mdx Except()
// function call.
List<ParseTreeNode> listWithExclusions =
new ArrayList<ParseTreeNode>();
if (dimension.getExclusions().size() > 0) {
List<ParseTreeNode> excludedMembers =
new ArrayList<ParseTreeNode>();
for (Selection selection : dimension.getExclusions()) {
excludedMembers.add(toOlap4j(selection));
}
listWithExclusions.add(
new CallNode(
null,
"Except",
Syntax.Function,
generateListSetCall(orderedList),
generateListSetCall(excludedMembers)));
} else {
listWithExclusions.addAll(orderedList);
}
// Do we need to wrap it all in a Hierarchize function?
List<ParseTreeNode> listWithHierarchy =
new ArrayList<ParseTreeNode>();
if (dimension.getHierarchizeMode() != null) {
CallNode hierarchyNode;
// There are two modes available, PRE and POST.
if (dimension.getHierarchizeMode().equals(
QueryDimension.HierarchizeMode.PRE))
{
// In pre mode, we don't add the "POST" literal.
hierarchyNode = new CallNode(
null,
"Hierarchize",
Syntax.Function,
generateListSetCall(listWithExclusions));
} else if (dimension.getHierarchizeMode().equals(
QueryDimension.HierarchizeMode.POST))
{
hierarchyNode = new CallNode(
null,
"Hierarchize",
Syntax.Function,
generateListSetCall(listWithExclusions),
LiteralNode.createSymbol(