public boolean removeLevel( String queryName, String dimensionName, String uniqueHierarchyName, String uniqueLevelName) { IQuery query = getIQuery(queryName); removeAllChildren(queryName, dimensionName); QueryDimension dimension = query.getDimension(dimensionName); try { for (Hierarchy hierarchy : dimension.getDimension().getHierarchies()) { if (hierarchy.getUniqueName().equals(uniqueHierarchyName)) { for (Level level : hierarchy.getLevels()) { if (level.getUniqueName().equals(uniqueLevelName)) { Selection inclusion = dimension.createSelection(level); dimension.getInclusions().remove(inclusion); ArrayList<Selection> removals = new ArrayList<Selection>(); for (Selection sel : dimension.getInclusions()) { if ((sel.getRootElement() instanceof Member)) { if (((Member) sel.getRootElement()).getLevel().equals(level)) { if (dimension.getInclusions().contains(sel)) { removals.add(sel); } } } } dimension.getInclusions().removeAll(removals); } } } } } catch (Exception e) { throw new SaikuServiceException( "Cannot remove level" + uniqueLevelName + "from dimension " + dimensionName, e); } return true; }
private static String getParameterValue( TargetParameter parameter, WhatIfEngineInstance ei, SpagoBICellWrapper cell) { if (parameter.isAbsolute()) { return parameter.getValue(); } String value = null; String dimensionName = parameter.getDimension(); String hierarchyName = parameter.getHierarchy(); String levelName = parameter.getLevel(); String propertyName = parameter.getProperty(); logger.debug( "Looking for dimension " + dimensionName + ", hierarchy " + hierarchyName + ", level " + levelName + ", property " + propertyName + " ..."); Hierarchy hierarchy = getHierarchy(ei.getSpagoBIPivotModel().getCube(), ei.getModelConfig(), dimensionName); Member member = cell.getContextMember(hierarchy); logger.debug("Considering context member " + member.getUniqueName()); logger.debug("Member hierarchy is " + hierarchy.getUniqueName()); if (hierarchy.getUniqueName().equals(hierarchyName)) { if (propertyName == null || propertyName.trim().equals("")) { value = getLevelValue(member, levelName); } else { value = getMemberPropertyValue(member, propertyName); } } return value; }
/** @return the filterNode */ public TreeNode getFilterNode() { if (model != null && model.isInitialized()) { Hierarchy hierarchy = getHierarchy(); if (filterNode == null && hierarchy != null) { this.filterNode = new DefaultTreeNode(); filterNode.setExpanded(true); List<Member> members; boolean isMeasure; try { members = hierarchy.getRootMembers(); isMeasure = hierarchy.getDimension().getDimensionType() == Type.MEASURE; } catch (OlapException e) { throw new FacesException(e); } for (Member member : members) { if (isMeasure && !member.isVisible()) { continue; } MemberNode node = new MemberNode(member); node.setNodeFilter(this); node.setExpanded(true); node.setSelectable(true); node.setSelected(isSelected(member)); filterNode.getChildren().add(node); } List<TreeNode> initialSelection = ((DefaultTreeNode) filterNode) .collectNodes( new NodeCollector() { @Override public boolean collectNode(TreeNode node) { return node.isSelected(); } @Override public boolean searchNode(TreeNode node) { return node.isExpanded(); } }); this.selection = initialSelection.toArray(new TreeNode[initialSelection.size()]); } } else { this.filterNode = null; } return filterNode; }
/** * @param hierarchy * @return */ protected UIComponent createFilterItem(Hierarchy hierarchy) { String id = "filter-item-" + hierarchy.getUniqueName().hashCode(); HtmlPanelGroup panel = new HtmlPanelGroup(); panel.setId(id); panel.setLayout("block"); panel.setStyleClass("ui-widget-header filter-item"); CommandLink link = new CommandLink(); link.setId(id + "-link"); link.setValue(hierarchy.getCaption()); link.setTitle(hierarchy.getUniqueName()); FacesContext context = FacesContext.getCurrentInstance(); ExpressionFactory factory = context.getApplication().getExpressionFactory(); link.setActionExpression( factory.createMethodExpression( context.getELContext(), "#{filterHandler.show}", Void.class, new Class<?>[0])); link.setUpdate(":filter-form"); link.setOncomplete("PF('filterDialog').show();"); UIParameter parameter = new UIParameter(); parameter.setName("hierarchy"); parameter.setValue(hierarchy.getName()); link.getChildren().add(parameter); panel.getChildren().add(link); CommandButton closeButton = new CommandButton(); closeButton.setId(id + "-button"); closeButton.setIcon("ui-icon-close"); closeButton.setActionExpression( factory.createMethodExpression( context.getELContext(), "#{filterHandler.removeHierarchy}", Void.class, new Class<?>[0])); closeButton.setUpdate( ":filter-items-form,:source-tree-form,:grid-form,:editor-form:mdx-editor,:editor-form:editor-toolbar"); closeButton.setOncomplete("onViewChanged()"); UIParameter parameter2 = new UIParameter(); parameter2.setName("hierarchy"); parameter2.setValue(hierarchy.getName()); closeButton.getChildren().add(parameter2); panel.getChildren().add(closeButton); return panel; }
public List<SaikuMember> getResultMetadataMembers( String queryName, boolean preferResult, String dimensionName, String hierarchyName, String levelName) { IQuery query = getIQuery(queryName); CellSet cs = query.getCellset(); List<SaikuMember> members = new ArrayList<SaikuMember>(); Set<Level> levels = new HashSet<Level>(); if (cs != null && preferResult) { for (CellSetAxis axis : cs.getAxes()) { int posIndex = 0; for (Hierarchy h : axis.getAxisMetaData().getHierarchies()) { if (h.getUniqueName().equals(hierarchyName)) { log.debug("Found hierarchy in the result: " + hierarchyName); if (h.getLevels().size() == 1) { break; } Set<Member> mset = new HashSet<Member>(); for (Position pos : axis.getPositions()) { Member m = pos.getMembers().get(posIndex); if (!m.getLevel().getLevelType().equals(Type.ALL)) { levels.add(m.getLevel()); } if (m.getLevel().getUniqueName().equals(levelName)) { mset.add(m); } } members = ObjectUtil.convertMembers(mset); Collections.sort(members, new SaikuUniqueNameComparator()); break; } posIndex++; } } log.debug("Found members in the result: " + members.size()); } if (cs == null || !preferResult || members.size() == 0 || levels.size() == 1) { members = olapDiscoverService.getLevelMembers( query.getSaikuCube(), dimensionName, hierarchyName, levelName); } return members; }
public SaikuFilter getFilter( String queryName, String filtername, String dimensionName, String hierarchyName, String levelName) { IQuery query = getIQuery(queryName); CellSet cs = query.getCellset(); List<SimpleCubeElement> members = new ArrayList<SimpleCubeElement>(); SimpleCubeElement dimension = null; SimpleCubeElement hierarchy = null; Set<MetadataElement> mset = new HashSet<MetadataElement>(); if (cs != null) { List<CellSetAxis> axes = new ArrayList<CellSetAxis>(); axes.addAll(cs.getAxes()); axes.add(cs.getFilterAxis()); for (CellSetAxis axis : axes) { int posIndex = 0; for (Hierarchy h : axis.getAxisMetaData().getHierarchies()) { if (h.getName().equals(hierarchyName)) { if (hierarchy == null) { hierarchy = new SimpleCubeElement(h.getName(), h.getUniqueName(), h.getCaption()); Dimension d = h.getDimension(); dimension = new SimpleCubeElement(d.getName(), d.getUniqueName(), d.getCaption()); } if (h.getLevels().size() == 1) { break; } for (Position pos : axis.getPositions()) { Member m = pos.getMembers().get(posIndex); if (m.getLevel().getName().equals(levelName)) { mset.add(m); } } break; } posIndex++; } } if (mset.size() == 0) { QueryDimension qd = query.getDimension(dimensionName); if (qd != null && qd.getAxis().getLocation() != null) { for (Selection sel : qd.getInclusions()) { if ((sel.getRootElement() instanceof Member)) { Member m = ((Member) sel.getRootElement()); if (m.getLevel().getName().equals(levelName)) { mset.add(m); } } } } } members = ObjectUtil.convert2Simple(mset); Collections.sort(members, new SaikuUniqueNameComparator()); log.debug("Create Filters: Found members in the result or query: " + members.size()); } return new SaikuFilter(filtername, null, dimension, hierarchy, members); }
/** @param e */ public void onDrop(DragDropEvent e) { List<Integer> sourcePath = getNodePath(e.getDragId()); Hierarchy hierarchy = null; if (isSourceNode(e.getDragId())) { TreeNode sourceNode = findNodeFromPath(navigator.getCubeNode(), sourcePath); if (sourceNode instanceof HierarchyNode) { HierarchyNode node = (HierarchyNode) sourceNode; hierarchy = node.getObject(); } else if (sourceNode instanceof LevelNode) { LevelNode node = (LevelNode) sourceNode; Level level = node.getObject(); hierarchy = level.getHierarchy(); } if (hierarchy == null) { return; } if (navigator.isSelected(hierarchy)) { FacesContext context = FacesContext.getCurrentInstance(); ResourceBundle bundle = context.getApplication().getResourceBundle(context, "msg"); String title = bundle.getString("error.filter.title"); String message = bundle.getString("error.filter.message"); context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, title, message)); return; } UIComponent panel = createFilterItem(hierarchy); filterPanel.getChildren().add(panel); show(hierarchy.getName()); RequestContext.getCurrentInstance().execute("PF('filterDialog').show();"); } }
public List<SaikuMember> getAllMeasures(SaikuCube cube) throws SaikuOlapException { List<SaikuMember> measures = new ArrayList<SaikuMember>(); try { Cube nativeCube = getNativeCube(cube); for (Measure measure : nativeCube.getMeasures()) { if (measure.isVisible()) { measures.add(ObjectUtil.convertMeasure(measure)); } } if (measures.size() == 0) { Hierarchy hierarchy = nativeCube.getDimensions().get("Measures").getDefaultHierarchy(); measures = (ObjectUtil.convertMembers(hierarchy.getRootMembers())); } } catch (OlapException e) { throw new SaikuOlapException("Cannot get measures for cube:" + cube.getName(), e); } Collections.sort(measures, new SaikuMemberCaptionComparator()); return measures; }
public boolean includeLevel( String queryName, String dimensionName, String uniqueHierarchyName, String uniqueLevelName) { IQuery query = getIQuery(queryName); removeAllChildren(queryName, dimensionName); QueryDimension dimension = query.getDimension(dimensionName); for (Hierarchy hierarchy : dimension.getDimension().getHierarchies()) { if (hierarchy.getUniqueName().equals(uniqueHierarchyName)) { for (Level level : hierarchy.getLevels()) { if (level.getUniqueName().equals(uniqueLevelName)) { Selection sel = dimension.createSelection(level); if (!dimension.getInclusions().contains(sel)) { dimension.include(level); } return true; } } } } return false; }
public List<SaikuLevel> getAllLevels(SaikuCube cube, String dimension, String hierarchy) throws SaikuOlapException { Cube nativeCube = getNativeCube(cube); Dimension dim = nativeCube.getDimensions().get(dimension); if (dim != null) { Hierarchy h = dim.getHierarchies().get(hierarchy); if (h == null) { for (Hierarchy hlist : dim.getHierarchies()) { if (hlist.getUniqueName().equals(hierarchy) || hlist.getName().equals(hierarchy)) { h = hlist; } } } if (h != null) { List<SaikuLevel> levels = (ObjectUtil.convertLevels(h.getLevels())); return levels; } } return new ArrayList<SaikuLevel>(); }
public List<SaikuMember> getAllMembers( SaikuCube cube, String dimension, String hierarchy, String level) throws SaikuOlapException { try { Cube nativeCube = getNativeCube(cube); Dimension dim = nativeCube.getDimensions().get(dimension); if (dim != null) { Hierarchy h = dim.getHierarchies().get(hierarchy); if (h == null) { for (Hierarchy hlist : dim.getHierarchies()) { if (hlist.getUniqueName().equals(hierarchy) || hlist.getName().equals(hierarchy)) { h = hlist; } } } if (h != null) { Level l = h.getLevels().get(level); if (l == null) { for (Level lvl : h.getLevels()) { if (lvl.getUniqueName().equals(level) || lvl.getName().equals(level)) { return (ObjectUtil.convertMembers(lvl.getMembers())); } } } else { return (ObjectUtil.convertMembers(l.getMembers())); } } } } catch (OlapException e) { throw new SaikuOlapException("Cannot get all members", e); } return new ArrayList<SaikuMember>(); }
public List<SaikuMember> getHierarchyRootMembers(SaikuCube cube, String hierarchyName) throws SaikuOlapException { Cube nativeCube = getNativeCube(cube); List<SaikuMember> members = new ArrayList<SaikuMember>(); Hierarchy h = nativeCube.getHierarchies().get(hierarchyName); if (h == null) { for (Hierarchy hlist : nativeCube.getHierarchies()) { if (hlist.getUniqueName().equals(hierarchyName) || hlist.getName().equals(hierarchyName)) { h = hlist; } } } if (h != null) { try { members = (ObjectUtil.convertMembers(h.getRootMembers())); } catch (OlapException e) { throw new SaikuOlapException( "Cannot retrieve root members of hierarchy: " + hierarchyName, e); } } return members; }
public List<Hierarchy> getHierarchies() { if (queryAxis.getAxisOrdinal().isFilter()) { // Slicer contains all dimensions not mentioned on other axes. // The list contains the default hierarchy of // each dimension not already in the slicer or in another axes. Set<Dimension> dimensionSet = new HashSet<Dimension>(); for (CellSetAxisMetaData cellSetAxisMetaData : cellSetMetaData.getAxesMetaData()) { for (Hierarchy hierarchy : cellSetAxisMetaData.getHierarchies()) { dimensionSet.add(hierarchy.getDimension()); } } List<Hierarchy> hierarchyList = new ArrayList<Hierarchy>(); for (Dimension dimension : cellSetMetaData.getCube().getDimensions()) { if (dimensionSet.add(dimension)) { hierarchyList.add(dimension.getDefaultHierarchy()); } } // In case a dimension has multiple hierarchies, return the // declared type of the slicer expression. For example, if the // WHERE clause contains [Time].[Weekly].[1997].[Week 6], the // slicer should contain [Time].[Weekly] not the default hierarchy // [Time]. for (Hierarchy hierarchy : getHierarchiesNonFilter()) { if (hierarchy.getDimension().getHierarchies().size() == 1) { continue; } for (int i = 0; i < hierarchyList.size(); i++) { Hierarchy hierarchy1 = hierarchyList.get(i); if (hierarchy1.getDimension().equals(hierarchy.getDimension()) && hierarchy1 != hierarchy) { hierarchyList.set(i, hierarchy); } } } return hierarchyList; } else { return getHierarchiesNonFilter(); } }