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 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; }
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); }
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 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>(); }