// Get the DataProvider.
DataProvider dp = getContext().getDataProvider();
// Get the Sales measure and the Source for it.
MdmMeasure mdmSales = getMdmMeasure("SALES_AW");
NumberSource sales = (NumberSource) mdmSales.getSource();
// Get the dimensions. Cast the Product dimension as an MdmStandardDimension
// so that it has a createCustomMember method.
MdmStandardDimension mdmProdStdDim = (MdmStandardDimension)
getMdmPrimaryDimension("PRODUCT_AW");
MdmPrimaryDimension mdmTimeDim = getMdmPrimaryDimension("TIME_AW");
MdmPrimaryDimension mdmChanDim = getMdmPrimaryDimension("CHANNEL_AW");
MdmPrimaryDimension mdmCustDim = getMdmPrimaryDimension("CUSTOMER_AW");
// Get the Source for the product dimension.
Source prodStdDim = mdmProdStdDim.getSource();
// Get the marketing manager attribute and the Source for it.
MdmAttribute mdmMktMngrAttr = getContext().getAttributeByName(mdmProdStdDim,
"MARKETING_MANAGER_AW");
Source mktMngrAttr = mdmMktMngrAttr.getSource();
// Get the default hierarchies of the dimensions and the Source objects
// for them.
MdmLevelHierarchy mdmCalendar = (MdmLevelHierarchy)
mdmTimeDim.getDefaultHierarchy();
MdmLevelHierarchy mdmProdHier = (MdmLevelHierarchy)
mdmProdStdDim.getDefaultHierarchy();
MdmLevelHierarchy mdmChanHier = (MdmLevelHierarchy)
mdmChanDim.getDefaultHierarchy();
MdmLevelHierarchy mdmShipHier = (MdmLevelHierarchy)
mdmCustDim.getDefaultHierarchy();
StringSource calendar = (StringSource) mdmCalendar.getSource();
StringSource prodHier = (StringSource) mdmProdHier.getSource();
StringSource chanHier = (StringSource) mdmChanHier.getSource();
StringSource shipHier = (StringSource) mdmShipHier.getSource();
// Get the placeholder Source for the Number data type.
Source ph = dp.getFundamentalMetadataProvider()
.getNumberPlaceholder()
.getSource();
// Get the level to which the dimension members belong.
MdmLevel mdmItemLevel = getContext().getLevelByName(mdmProdHier,
"ITEM_AW");
// Get the Source for the ITEM level.
Source itemLevel = mdmItemLevel.getSource();
// Select the members of the level that are managed by a marketing manager.
Source prodForManager = itemLevel.join(mktMngrAttr, "Jackson");
// Get the short value description attribute for Product and the Source
// for it.
MdmAttribute mdmProdShortDescr =
mdmProdStdDim.getShortValueDescriptionAttribute();
Source prodShortDescr = mdmProdShortDescr.getSource();
// Create the calculation Source, which specifies the aggregation of
// the selected products.
Source calc = ((NumberSource)
(ph.join(prodHier,
new String[] {"PRODUCT_PRIMARY_AW::ITEM_AW::24",
"PRODUCT_PRIMARY_AW::ITEM_AW::25",
"PRODUCT_PRIMARY_AW::ITEM_AW::26",
"PRODUCT_PRIMARY_AW::ITEM_AW::33",
"PRODUCT_PRIMARY_AW::ITEM_AW::34",
"PRODUCT_PRIMARY_AW::ITEM_AW::35",
"PRODUCT_PRIMARY_AW::ITEM_AW::36",
"PRODUCT_PRIMARY_AW::ITEM_AW::37",
"PRODUCT_PRIMARY_AW::ITEM_AW::38",
"PRODUCT_PRIMARY_AW::ITEM_AW::39"}))).total();
// Create the custom dimension member.
MdmStandardMember mdmMktMngrTotal =
mdmProdStdDim.createCustomMember("65", // member local value
mdmItemLevel, // member level
"4", // parent local value
calc, // calculation Source
10); // precedence value
// Set the short value description for the custom member.
mdmMktMngrTotal.setShortDescription("Marketing Manager Total");
// Append the custom member to the product selection.
Source mktMngrWithTotal = prodForManager.appendValue(
prodHier.selectValue(
"PRODUCT_PRIMARY_AW::ITEM_AW::65"));
// Create a query that specifies the units sold of the selected products,
// including a short description of the products, for the specified customer
// through all sales channels in the specified year.
Source result = sales.join(prodShortDescr.join(mktMngrWithTotal))
.join(shipHier, "SHIPMENTS_AW::SHIP_TO_AW::106")
.join(chanHier, "CHANNEL_PRIMARY_AW::TOTAL_CHANNEL_AW::1")
.join(calendar, "CALENDAR_YEAR_AW::YEAR_AW::3");
// Prepare and commit the current Transaction.