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 static Hierarchy getHierarchy(Cube cube, ModelConfig modelConfig, String dimensionName) { List<Dimension> dimensions = cube.getDimensions(); Dimension result = null; for (java.util.Iterator<Dimension> iterator = dimensions.iterator(); iterator.hasNext(); ) { Dimension dimension = iterator.next(); if (dimension.getUniqueName().equals("[" + dimensionName + "]")) { result = dimension; } } if (result == null) { logger.error("Could not find dimension"); throw new SpagoBIEngineRuntimeException("Could not find dimension"); } logger.debug("Found dimension " + result.getUniqueName()); // get Hierarchy Used by dimension NamedList<Hierarchy> hierarchies = result.getHierarchies(); Hierarchy hierarchy = null; if (hierarchies == null || hierarchies.size() == 0) { logger.error("Could not find hierarchies for dimension"); throw new SpagoBIEngineRuntimeException("Could not find hierarchies for dimension"); } else if (hierarchies.size() == 1) { hierarchy = hierarchies.get(0); } else { String hierarchyUsed = modelConfig.getDimensionHierarchyMap().get(dimensionName); hierarchy = hierarchies.get(hierarchyUsed); } return hierarchy; }
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); }
private void metadataTest(String dsUri, int numberOfDimensions, int numberOfMeasures) { try { // We have to use MDX encoded name String name = URLEncoder.encode(dsUri, "UTF-8"); name = name.replace("%", "XXX"); name = name.replace(".", "YYY"); name = name.replace("-", "ZZZ"); // xmla4js is attaching square brackets automatically // xmla-server is using a set of values for a restriction. Cube cube = olapConnection .getOlapDatabases() .get(0) .getCatalogs() .get(0) .getSchemas() .get(0) .getCubes() .get("[" + name + "]"); // Currently, we have to first query for dimensions. List<Dimension> dimensions = cube.getDimensions(); // Number of dimensions assertEquals(numberOfDimensions, dimensions.size()); for (Dimension dimension : dimensions) { List<Member> members = dimension.getHierarchies().get(0).getLevels().get(0).getMembers(); // Each dimension should have some members assertEquals(true, members.size() >= 1); } List<Measure> measures = cube.getMeasures(); // Number of measures assertEquals(numberOfMeasures, measures.size()); } catch (OlapException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
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<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(); } }