if (StringUtils.isNotBlank(dimName)) {
QueryDimension dim = qm.getDimension(dimName);
if (dim == null) {
throw new OlapException("Dimension not found:" + dimName);
}
String sortOrder = dimension.getAttributeValue("sortOrder");
if (StringUtils.isNotBlank(sortOrder)) {
dim.sort(SortOrder.valueOf(sortOrder));
}
String hierarchizeMode = dimension.getAttributeValue("hierarchizeMode");
if (StringUtils.isNotBlank(hierarchizeMode)) {
dim.setHierarchizeMode(HierarchizeMode.valueOf(hierarchizeMode));
}
String hierarchyConsistent = dimension.getAttributeValue("hierarchyConsistent");
if (StringUtils.isNotBlank(hierarchyConsistent)) {
dim.setHierarchyConsistent(Boolean.parseBoolean(hierarchyConsistent));
}
qm.getAxes().get(Axis.Standard.valueOf(location)).getDimensions().add(dim);
Element inclusions = dimension.getChild("Inclusions");
if (inclusions != null) {
for (int z = 0; z < inclusions.getChildren(SELECTION).size(); z++) {
Element selectionElement = (Element) inclusions.getChildren(SELECTION).get(z);
String name = selectionElement.getAttributeValue("node");
String operator = selectionElement.getAttributeValue("operator");
String type = selectionElement.getAttributeValue("type");
Selection sel = null;
if ("level".equals(type)) {
for (Hierarchy hierarchy : dim.getDimension().getHierarchies()) {
for (Level level : hierarchy.getLevels()) {
if (level.getUniqueName().equals(name)) {
sel = dim.include(level);
}
}
}
} else if ("member".equals(type)) {
sel = dim.include(Selection.Operator.valueOf(operator),
IdentifierNode.parseIdentifier(name).getSegmentList());
}
Element contextElement = selectionElement.getChild("Context");
if (sel != null && contextElement != null) {
for (int h = 0; h < contextElement.getChildren(SELECTION).size(); h++) {
Element context = (Element) contextElement.getChildren(SELECTION).get(h);
String contextname = context.getAttributeValue("node");
String contextoperator = context.getAttributeValue("operator");
String contextDimension = context.getAttributeValue("dimension");
QueryDimension contextDim = qm.getDimension(contextDimension);
if (contextDim != null) {
Selection contextSelection = contextDim.createSelection(Selection.Operator.valueOf(contextoperator),
IdentifierNode.parseIdentifier(contextname)
.getSegmentList());
if (contextSelection != null) {
sel.addContext(contextSelection);
} else {
throw new OlapException(
"Cannot create selection for node: " + contextname + " operator:" + contextoperator
+ " on dimension: " + dim.getName()
);
}
} else {
throw new OlapException("Context dimension is null");
}
}
}
}
}
Element exclusions = dimension.getChild("Exclusions");
if (inclusions != null) {
for (int z = 0; z < exclusions.getChildren(SELECTION).size(); z++) {
Element selectionElement = (Element) exclusions.getChildren(SELECTION).get(z);
String name = selectionElement.getAttributeValue("node");
String operator = selectionElement.getAttributeValue("operator");
dim
.exclude(Selection.Operator.valueOf(operator), IdentifierNode.parseIdentifier(name).getSegmentList());
// ADD CONTEXT ?
}
}
} else {
throw new OlapException("No Dimension name defined");
}
}