// Get the MdmMeasure for the measure.
MdmMeasure mdmUnits = getMdmMeasure("UNITS_AW");
MdmMeasure mdmSales = getMdmMeasure("SALES_AW");
// Get the Sources for the measures.
Source units = mdmUnits.getSource();
Source sales = mdmSales.getSource();
// Get the MdmPrimaryDimension objects for the dimensions of the measure.
MdmPrimaryDimension mdmCustDim = getMdmPrimaryDimension("CUSTOMER_AW");
MdmPrimaryDimension mdmProdDim = getMdmPrimaryDimension("PRODUCT_AW");
MdmPrimaryDimension mdmChanDim = getMdmPrimaryDimension("CHANNEL_AW");
MdmPrimaryDimension mdmTimeDim = getMdmPrimaryDimension("TIME_AW");
// Get the default hierarchy of the Product dimension.
MdmLevelHierarchy mdmProdHier = (MdmLevelHierarchy)
mdmProdDim.getDefaultHierarchy();
// Get the detail level of the hierarchy.
MdmLevel mdmItemLevel = getContext().getLevelByName(mdmProdHier, "ITEM_AW");
// Get the Source for the level.
Source itemLevel = mdmItemLevel.getSource();
// Get the short description attribute for the Product dimension and
// the Source for the attribute.
MdmAttribute mdmProdShortDescrAttr =
mdmProdDim.getShortValueDescriptionAttribute();
Source prodShortDescrAttr = mdmProdShortDescrAttr.getSource();
// Create a SingleSelectionTemplate to produce a Source that
// represents the measure values specified by single members of each of
// the dimensions of the measure other than the base dimension.
SingleSelectionTemplate singleSelections =
new SingleSelectionTemplate(units, dp);
// Create MdmDimensionMemberInfo objects for single members of the
// other dimensions of the measure.
MdmDimensionMemberInfo timeMemInfo =
new MdmDimensionMemberInfo(mdmTimeDim,
"CALENDAR_YEAR_AW::YEAR_AW::4");
MdmDimensionMemberInfo custMemInfo =
new MdmDimensionMemberInfo(mdmCustDim,
"SHIPMENTS_AW::REGION_AW::8");
MdmDimensionMemberInfo chanMemInfo =
new MdmDimensionMemberInfo(mdmChanDim,
"CHANNEL_PRIMARY_AW::CHANNEL_AW::2");
// Add the dimension member information objects to the
// SingleSelectionTemplate.
singleSelections.addDimMemberInfo(custMemInfo);
singleSelections.addDimMemberInfo(chanMemInfo);
singleSelections.addDimMemberInfo(timeMemInfo);
// Create a TopBottomTemplate specifying, as the base, the Source for a
// level of a hierarchy.
TopBottomTemplate topNBottom = new TopBottomTemplate(itemLevel, dp);
// Specify whether to retrieve the elements from the beginning (top) or the
// end (bottom) of the selected elements of the base dimension.
topNBottom.setTopBottomType(TopBottomTemplate.TOP_BOTTOM_TYPE_TOP);
// Set the number of elements of the base dimension to retrieve.
topNBottom.setN(10);
// Get the Source produced by the SingleSelectionTemplate and specify it as
// the criterion object.
topNBottom.setCriterion(singleSelections.getSource());
// Get the short value descriptions of the dimension members from the
// SingleSelectionTemplate.
StringBuffer shortDescrsForMemberVals =
singleSelections.getMemberShortDescrs(dp, tp);
println("\nThe " + Math.round(topNBottom.getN()) +
" products with the most units sold \nfor" +
shortDescrsForMemberVals +" are:\n");
// Get the Source produced by the TopBottomTemplate.
Source topNBottomResult = topNBottom.getSource();
// Join the Source produced by the TopBottomTemplate with the short
// value descriptions. Use the joinHidden method so that the
// dimension member values do not appear in the result.
Source result = prodShortDescrAttr.joinHidden(topNBottomResult);
// Prepare and commit the current Transaction.
prepareAndCommit(); // Method of ContextExample.
// Create a Cursor for the result and display the values of the Cursor.