import static com.narirelays.ems.resources.EMSi18n.*;
public class OlapService {
public static List getTimeDimensionTree() throws Exception{
MyOlapContext context = MyOlapContext.getMyOlapContext();
MdmPrimaryDimension mdmTimeDim = context.getMdmPrimaryDimension("MYTIME");
MdmLevelHierarchy mdmTimeHier = (MdmLevelHierarchy)mdmTimeDim.getDefaultHierarchy();
// StringSource prodHier = (StringSource) mdmProdHier.getSource();
MdmLevel mdmLevel = context.getLevelByName(mdmTimeHier, "YEAR");
Source levelSrc = mdmLevel.getSource();
StringSource timeHier = (StringSource) mdmTimeHier.getSource();
// Get the Source for the short label attribute of the dimension.
Source prodShortLabel = mdmTimeDim.getShortValueDescriptionAttribute()
.getSource();
Source levelSrcWithShortDescr = prodShortLabel.join(levelSrc);
MdmAttribute mdmTimeHierParentAttr = mdmTimeHier.getParentAttribute();
Source prodHierParentAttr = mdmTimeHierParentAttr.getSource();
Source timeHierChildren = timeHier.join(prodHierParentAttr,
timeHier.value());
Cursor queryCursor = getCursor(context,levelSrcWithShortDescr);
List<LazyDynaBean> result = convertDimensionShortDescCursor2List(queryCursor);
for(int yeari=0;result!=null&&yeari<result.size();yeari++){
LazyDynaBean yearbean = result.get(yeari);
Object objectID = yearbean.get("id");
if(objectID!=null){
String id = objectID.toString();
Source levelElement = timeHier.selectValue(id);
Source levelElementChildren = timeHierChildren.join(timeHier, levelElement);
Source levelElementChildrenWithShortDescr =
prodShortLabel.join(levelElementChildren);
queryCursor = getCursor(context,levelElementChildrenWithShortDescr);
List<LazyDynaBean> quarterList = convertDimensionShortDescCursor2List(queryCursor);
yearbean.set("children", quarterList);
for(int quarteri=0;quarterList!=null&&quarteri<quarterList.size();quarteri++){
LazyDynaBean quarterbean = quarterList.get(quarteri);
objectID = quarterbean.get("id");
if(objectID!=null){
id = objectID.toString();
levelElement = timeHier.selectValue(id);
levelElementChildren = timeHierChildren.join(timeHier, levelElement);
levelElementChildrenWithShortDescr =
prodShortLabel.join(levelElementChildren);
queryCursor = getCursor(context,levelElementChildrenWithShortDescr);
List<LazyDynaBean> monthList = convertDimensionShortDescCursor2List(queryCursor);
quarterbean.set("children", monthList);
for(int monthi=0;monthList!=null&&monthi<monthList.size();monthi++){
LazyDynaBean monthbean = monthList.get(monthi);
objectID = monthbean.get("id");
if(objectID!=null){
id = objectID.toString();
levelElement = timeHier.selectValue(id);
levelElementChildren = timeHierChildren.join(timeHier, levelElement);
levelElementChildrenWithShortDescr =
prodShortLabel.join(levelElementChildren);
queryCursor = getCursor(context,levelElementChildrenWithShortDescr);
List<LazyDynaBean> dayList = convertDimensionShortDescCursor2List(queryCursor);
monthbean.set("children", dayList);
}
}
}
}
}
}
//
// System.out.println(JSONArray.fromObject(result).toString());
context.closeContext();
return result;
}