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; }
private static String getLevelValue(Member member, String levelName) { logger.debug("IN: Member is " + member.getUniqueName() + ", levelName is " + levelName); String toReturn = null; Level level = member.getLevel(); logger.debug("Member level is " + level.getUniqueName()); if (level.getUniqueName().equals(levelName)) { logger.debug("Member level matches input level name " + levelName + "!!"); String uniqueName = member.getUniqueName(); toReturn = uniqueName.substring(uniqueName.lastIndexOf("].[") + 3, uniqueName.lastIndexOf("]")); } else { logger.debug("Member level does NOT match input level name " + levelName + "!!"); // look for parent member at parent level Member parent = member.getParentMember(); if (parent == null) { return null; } else { return getLevelValue(parent, levelName); } } logger.debug("OUT: returning " + toReturn); return toReturn; }
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 static String buildClickableUrl(Member member, List<TargetClickable> targetsClickable) { logger.debug("IN"); Level level = member.getLevel(); String url = new String(); for (TargetClickable tc : targetsClickable) { if (tc.getUniqueName().equalsIgnoreCase(level.getUniqueName())) { String targetDocumentParameters = ""; for (Map.Entry<String, String> entry : tc.getParametersList().entrySet()) { String key = entry.getKey(); String value = entry.getValue(); targetDocumentParameters += key + "=" + value + "&"; } url = "javascript:parent.execCrossNavigation(window.name, ''" + tc.getTargetDocument() + "'', ''" + targetDocumentParameters + "''"; if (tc.getTitle() != null && tc.getTarget() != null && tc.getTarget().equalsIgnoreCase("tab")) { url += ",null,''" + tc.getTitle() + "'',''tab''"; } else if (tc.getTitle() != null) { url += ",null,''" + tc.getTitle() + "''"; } url += ");"; // int lastIndex=member.getUniqueName().lastIndexOf("].["); // String newName=member.getUniqueName().substring(lastIndex+3, // member.getUniqueName().length()-1); String newName = getLevelValue(member, tc.getUniqueName()); Object[] args = new Object[] {newName}; url = MessageFormat.format(url, args); return url; } else { url = null; } } return url; }
/** * Formats a two-dimensional page. * * @param cellSet Cell set * @param pageCoords Coordinates of page [page, chapter, section, ...] * @param columnsAxis Columns axis * @param columnsAxisInfo Description of columns axis * @param rowsAxis Rows axis * @param rowsAxisInfo Description of rows axis */ private Matrix formatPage( final CellSet cellSet, final int[] pageCoords, final CellSetAxis columnsAxis, final AxisInfo columnsAxisInfo, final CellSetAxis rowsAxis, final AxisInfo rowsAxisInfo) { // Figure out the dimensions of the blank rectangle in the top left // corner. final int yOffset = columnsAxisInfo.getWidth(); final int xOffsset = rowsAxisInfo.getWidth(); // Populate a string matrix final Matrix matrix = new Matrix( xOffsset + (columnsAxis == null ? 1 : columnsAxis.getPositions().size()), yOffset + (rowsAxis == null ? 1 : rowsAxis.getPositions().size())); // Populate corner List<Level> levels = new ArrayList<>(); if (rowsAxis != null && rowsAxis.getPositions().size() > 0) { Position p = rowsAxis.getPositions().get(0); for (int m = 0; m < p.getMembers().size(); m++) { AxisOrdinalInfo a = rowsAxisInfo.ordinalInfos.get(m); for (Integer depth : a.getDepths()) { levels.add(a.getLevel(depth)); } } for (int x = 0; x < xOffsset; x++) { Level xLevel = levels.get(x); String s = xLevel.getCaption(); for (int y = 0; y < yOffset; y++) { final MemberCell memberInfo = new MemberCell(false, x > 0); if (y == yOffset - 1) { memberInfo.setRawValue(s); memberInfo.setFormattedValue(s); memberInfo.setProperty("__headertype", "row_header_header"); memberInfo.setProperty("levelindex", "" + levels.indexOf(xLevel)); memberInfo.setHierarchy(xLevel.getHierarchy().getUniqueName()); memberInfo.setParentDimension(xLevel.getDimension().getName()); memberInfo.setLevel(xLevel.getUniqueName()); } matrix.set(x, y, memberInfo); } } } // Populate matrix with cells representing axes // noinspection SuspiciousNameCombination populateAxis(matrix, columnsAxis, columnsAxisInfo, true, xOffsset); populateAxis(matrix, rowsAxis, rowsAxisInfo, false, yOffset); // Populate cell values for (final Cell cell : cellIter(pageCoords, cellSet)) { final List<Integer> coordList = cell.getCoordinateList(); int x = xOffsset; if (coordList.size() > 0) x += coordList.get(0); int y = yOffset; if (coordList.size() > 1) y += coordList.get(1); final DataCell cellInfo = new DataCell(true, false, coordList); cellInfo.setCoordinates(cell.getCoordinateList()); if (cell.getValue() != null) { try { cellInfo.setRawNumber(cell.getDoubleValue()); } catch (Exception e1) { } } String cellValue = cell.getFormattedValue(); // First try to get a // formatted value if (cellValue == null || cellValue.equals("null")) { // $NON-NLS-1$ cellValue = ""; // $NON-NLS-1$ } if (cellValue.length() < 1) { final Object value = cell.getValue(); if (value == null || value.equals("null")) // $NON-NLS-1$ cellValue = ""; // $NON-NLS-1$ else { try { // TODO this needs to become query / execution specific DecimalFormat myFormatter = new DecimalFormat(SaikuProperties.formatDefautNumberFormat); // $NON-NLS-1$ DecimalFormatSymbols dfs = new DecimalFormatSymbols(SaikuProperties.locale); myFormatter.setDecimalFormatSymbols(dfs); cellValue = myFormatter.format(cell.getValue()); } catch (Exception e) { // TODO: handle exception } } // the raw value } // Format string is relevant for Excel export // xmla cells can throw an error on this try { String formatString = (String) cell.getPropertyValue(Property.StandardCellProperty.FORMAT_STRING); if (formatString != null && !formatString.startsWith("|")) { cellInfo.setFormatString(formatString); } else { formatString = formatString.substring(1, formatString.length()); cellInfo.setFormatString(formatString.substring(0, formatString.indexOf("|"))); } } catch (Exception e) { // we tried } Map<String, String> cellProperties = new HashMap<>(); String val = Olap4jUtil.parseFormattedCellValue(cellValue, cellProperties); if (!cellProperties.isEmpty()) { cellInfo.setProperties(cellProperties); } cellInfo.setFormattedValue(val); matrix.set(x, y, cellInfo); } return matrix; }
/** * Populates cells in the matrix corresponding to a particular axis. * * @param matrix Matrix to populate * @param axis Axis * @param axisInfo Description of axis * @param isColumns True if columns, false if rows * @param offset Ordinal of first cell to populate in matrix */ private void populateAxis( final Matrix matrix, final CellSetAxis axis, final AxisInfo axisInfo, final boolean isColumns, final int offset) { if (axis == null) return; final Member[] prevMembers = new Member[axisInfo.getWidth()]; final MemberCell[] prevMemberInfo = new MemberCell[axisInfo.getWidth()]; final Member[] members = new Member[axisInfo.getWidth()]; for (int i = 0; i < axis.getPositions().size(); i++) { final int x = offset + i; final Position position = axis.getPositions().get(i); int yOffset = 0; final List<Member> memberList = position.getMembers(); final Map<Dimension, List<Integer>> lvls = new HashMap<Dimension, List<Integer>>(); for (int j = 0; j < memberList.size(); j++) { Member member = memberList.get(j); final AxisOrdinalInfo ordinalInfo = axisInfo.ordinalInfos.get(j); List<Integer> depths = ordinalInfo.depths; Collections.sort(depths); lvls.put(member.getDimension(), depths); if (ordinalInfo.getDepths().size() > 0 && member.getDepth() < ordinalInfo.getDepths().get(0)) break; final int y = yOffset + ordinalInfo.depths.indexOf(member.getDepth()); members[y] = member; yOffset += ordinalInfo.getWidth(); } boolean expanded = false; boolean same = true; for (int y = 0; y < members.length; y++) { final MemberCell memberInfo = new MemberCell(); final Member member = members[y]; expanded = false; int index = memberList.indexOf(member); if (index >= 0) { final AxisOrdinalInfo ordinalInfo = axisInfo.ordinalInfos.get(index); int depth_i = ordinalInfo.getDepths().indexOf(member.getDepth()); if (depth_i > 0) { expanded = true; } } memberInfo.setExpanded(expanded); same = same && i > 0 && Olap4jUtil.equal(prevMembers[y], member); if (member != null) { if (lvls != null && lvls.get(member.getDimension()) != null) { memberInfo.setProperty( "levelindex", "" + lvls.get(member.getDimension()).indexOf(member.getLevel().getDepth())); } if (x - 1 == offset) memberInfo.setLastRow(true); matrix.setOffset(offset); memberInfo.setRawValue(member.getCaption()); memberInfo.setFormattedValue(member.getCaption()); // First try to get a formatted value memberInfo.setParentDimension(member.getDimension().getName()); memberInfo.setHierarchy(member.getHierarchy().getName()); memberInfo.setLevel(member.getLevel().getUniqueName()); memberInfo.setUniquename(member.getUniqueName()); // try { // memberInfo.setChildMemberCount(member.getChildMemberCount()); // } catch (OlapException e) { // e.printStackTrace(); // throw new RuntimeException(e); // } // NamedList<Property> values = member.getLevel().getProperties(); // for(int j=0; j<values.size();j++){ // String val; // try { // val = member.getPropertyFormattedValue(values.get(j)); // } catch (OlapException e) { // e.printStackTrace(); // throw new RuntimeException(e); // } // memberInfo.setProperty(values.get(j).getCaption(), val); // } if (y > 0) { for (int previ = y - 1; previ >= 0; previ--) { if (prevMembers[previ] != null) { memberInfo.setRightOf(prevMemberInfo[previ]); memberInfo.setRightOfDimension(prevMembers[previ].getDimension().getName()); previ = -1; } } } if (member.getParentMember() != null) memberInfo.setParentMember(member.getParentMember().getUniqueName()); } else { memberInfo.setRawValue(null); memberInfo.setFormattedValue(null); memberInfo.setParentDimension(null); } if (isColumns) { memberInfo.setRight(false); memberInfo.setSameAsPrev(same); if (member != null) memberInfo.setParentDimension(member.getDimension().getName()); matrix.set(x, y, memberInfo); } else { memberInfo.setRight(false); memberInfo.setSameAsPrev(false); matrix.set(y, x, memberInfo); } int x_parent = isColumns ? x : y - 1; int y_parent = isColumns ? y - 1 : x; if (index >= 0) { final AxisOrdinalInfo ordinalInfo = axisInfo.ordinalInfos.get(index); int depth_i = ordinalInfo.getDepths().indexOf(member.getDepth()); while (depth_i > 0) { depth_i--; Level l = ordinalInfo.getLevel(ordinalInfo.getDepths().get(depth_i)); Member parent = member.getParentMember(); while (l != null && parent != null && !parent.getLevel().getUniqueName().equals(l.getUniqueName())) { parent = parent.getParentMember(); } final MemberCell pInfo = new MemberCell(); pInfo.setRawValue(parent.getCaption()); pInfo.setFormattedValue(parent.getCaption()); // First try to get a formatted value pInfo.setParentDimension(parent.getDimension().getName()); pInfo.setHierarchy(parent.getHierarchy().getName()); pInfo.setLevel(parent.getLevel().getUniqueName()); pInfo.setUniquename(parent.getUniqueName()); matrix.set(x_parent, y_parent, pInfo); if (isColumns) { y_parent--; } else { x_parent--; } } } prevMembers[y] = member; prevMemberInfo[y] = memberInfo; members[y] = null; } } }